var swgallery=Class.create({
	initialize:function(elements,options){
		this.elements=[];
		this.current=0;
		this.timeline=false;
		this.options={
			style:[
				{opacity:0},
				{opacity:1},
				{opacity:0}
			],
			loop:true,
			transition2next:'quadInOut',
			transition2prev:'quadInOut',
			duration2next:500,
			duration2prev:500
		};

		this.elements=elements;
		Object.extend(this.options, options);

		this.elements[0].setStyle(this.options.style[1]);
		for (var a=1; a < this.elements.length; a++)
			this.elements[a].setStyle(this.options.style[0]);
		this.timeline=new Timeline({autostop:false});
		this.timeline.start();
	},
	next:function(){
		var e=this.get_current_elements(1);
		if (!e) return;
		this.change(e,2,this.options.transition2next,this.options.duration2next);
	},
	prev:function(){
		var e=this.get_current_elements(-1);
		if (!e) return;
		this.change(e,0,this.options.transition2prev,this.options.duration2prev);
	},
	change:function(e,o,t,d){
		this.timeline.addTweenings([
			[e[1],this.options.style[1],{duration:d,transition:t,oldstyles:this.options.style[(o ? 0 : 2)]}],
			[e[0],this.options.style[o],{duration:d,transition:t,oldstyles:this.options.style[1]}]
		]);
		if ( e[1].value == 666 && e[0].value != 666 ) {
			this.timeline.addTweenings([
				[$('hotel_month_empty'),this.options.style[1],{duration:d,transition:t,oldstyles:this.options.style[0]}],
				[$('hotel_month'),this.options.style[0],{duration:d,transition:t,oldstyles:this.options.style[1]}]
			]);
		}
		else if ( e[0].value == 666 && e[1].value != 666 ) {
			this.timeline.addTweenings([
    			[$('hotel_month'),this.options.style[1],{duration:d,transition:t,oldstyles:this.options.style[0]}],
    			[$('hotel_month_empty'),this.options.style[0],{duration:d,transition:t,oldstyles:this.options.style[1]}]
    		]);
		}
	},
	get_current_elements:function(to){
		to+=this.current;
		if (to < 0) { if (this.options.loop) to=this.elements.length-1; else return false; }
		if (to >= this.elements.length) { if (this.options.loop) to=0; else return false; }

		var r=[
			this.elements[this.current],
			this.elements[to]
		];

		this.current=to;

		return r;
	}
});

