var effects={};
Class({
	name:"EffectScroll",
	pack:effects,
	constructor:function(){},
	public:{
		id:-1,
		slider_item:[],
		parent:"",
		appendTo:"",
		widthConst:0,
		timerDelay:0,
		init:function(){
			var i=-1;
			this.timer=new tools.Timer(this.timerDelay);
			this.jqueryArray=[];
			this.jqueryArray[this.id]=$(this.parent).find("div.slaid");
			while(this.slider_item[++i]){
				if(i==this.id){
					this.load++;
					continue;
				}
				this.jqueryArray[i]=$(this.slider_item[i]);
				$("#loading_slider").append(this.jqueryArray[i]);
				this.jqueryArray[i].find("img").load(this.imagesLoading);
				if(!this.jqueryArray[i].find("img")[0]){
					this.load++;
				}
			}
			this.timer.bind("timer",this.goOneNext);
		},
		effectPrev:function(e){
			e.preventDefault();
			if(!this.run){
				this.timer.halt();
				if(this.time==-1){
					this.firstTimePrev();
				}
				else{
					if(this.time-1<0){
						this.timeMinusOne=this.jqueryArray.length+this.time-1;
					}
					else{
						this.timeMinusOne=this.time-1;
					}
					if(this.time-2<0){
						this.timeMinusTwo=this.jqueryArray.length+this.time-2;
					}
					else{
						this.timeMinusTwo=this.time-2;
					}
					var nowDom=this.jqueryArray[this.time];
					var prevDom=this.jqueryArray[this.timeMinusOne];
					var removeDom=this.jqueryArray[this.timeMinusTwo];
					this.runPrev(nowDom,prevDom,removeDom);
					if(--this.time<0){
						this.time=this.jqueryArray.length-1;
					}
				}
			}
		},
		effectNext:function(e){
			e.preventDefault();
			if(!this.run){
				this.timer.halt();
				if(this.time==-1){
					this.firstTimeNext();
				}
				else{
					if(this.time+1>this.jqueryArray.length-1){
						this.timePlusOne=this.time+1-this.jqueryArray.length;
					}
					else{
						this.timePlusOne=this.time+1;
					}
					if(this.time+2>this.jqueryArray.length-1){
						this.timePlusTwo=this.time+2-this.jqueryArray.length;;
					}
					else{
						this.timePlusTwo=this.time+2;
					}
					var nowDom=this.jqueryArray[this.time];
					var nextDom=this.jqueryArray[this.timePlusOne];
					var removeDom=this.jqueryArray[this.timePlusTwo];
					this.runNext(nowDom,nextDom,removeDom);
					if(++this.time>this.jqueryArray.length-1){
						this.time=0;
					}
				}
			}
		}
	},
	private:{
		run:false,
		timer:false,
		jqueryArray:[],
		effectInMSecond:500,
		time:-1,
		timePlusTwo:-1,
		timePlusOne:-1,
		timeMinusTwo:-1,
		timeMinusOne:-1,
		load:0,
		runNext:function(now,next,remove){
			var _$=this;
			if(!this.run && now && next){
				this.run=true;
				//append
				next.css({
					position:"absolute",
					top:0,
					left:this.widthConst
				})
				.appendTo(this.appendTo);
				//anim1
				now.animate({
					left:-this.widthConst
				},
				this.effectInMSecond);
				//anim2
				next.animate({
					left:0
				},
				this.effectInMSecond-60,
				function(){
					return (function(){
						this.run=false;
						if(!this.timer.running){
							this.timer.start();
						}
					}).call(_$);
				});
				if(remove && this.jqueryArray.length>2){
					if(remove.offsetParent()[0].nodeName!="BODY"){
						remove.detach();
					}
				}
			}
		},
		runPrev:function(now,prev,remove){
			var _$=this;
			if(!this.run && now && prev){
				this.run=true;
				//append
				prev.css({
					position:"absolute",
					top:0,
					left:-this.widthConst
				})
				.appendTo(this.appendTo);
				//anim1
				now.animate({
					left:this.widthConst
				},
				this.effectInMSecond);
				//anim2
				prev.animate({
					left:0
				},
				this.effectInMSecond-60,
				function(){
					return (function(){
						this.run=false;
						if(!this.timer.running){
							this.timer.start();
						}
					}).call(_$);
				});
				if(remove){
					if(remove.offsetParent()[0].nodeName!="BODY" && this.jqueryArray.length>2){
						remove.detach();
					}
				}
			}
		},
		goOneNext:function(){
			if(this.time==-1){
				this.firstTimeNext();
			}
			else{
				if(this.time+1>this.jqueryArray.length-1){
					this.timePlusOne=this.time+1-this.jqueryArray.length;
				}
				else{
					this.timePlusOne=this.time+1;
				}
				if(this.time+2>this.jqueryArray.length-1){
					this.timePlusTwo=this.time+2-this.jqueryArray.length;;
				}
				else{
					this.timePlusTwo=this.time+2;
				}
				var nowDom=this.jqueryArray[this.time];
				var nextDom=this.jqueryArray[this.timePlusOne];
				var removeDom=this.jqueryArray[this.timePlusTwo];
				this.runNext(nowDom,nextDom,removeDom);
				if(++this.time>this.jqueryArray.length-1){
					this.time=0;
				}
			}
		},
		imagesLoading:function(){
			if(++this.load==this.slider_item.length && this.slider_item.length>1){
				this.timer.start();
			}
		},
		firstTimeNext:function(){
			if(this.id<this.slider_item.length-1){
				this.time=this.id+1;
			}
			else{
				this.time=0;
			}
			this.runNext(this.jqueryArray[this.id],this.jqueryArray[this.time]);
		},
		firstTimePrev:function(){
			if(this.id>0){
				this.time=this.id-1;
			}
			else{
				this.time=this.jqueryArray.length-1
			}
			this.runPrev(this.jqueryArray[this.id],this.jqueryArray[this.time]);
		}
	}
});
Class({
	name:"EffectOpacity",
	pack:effects,
	constructor:function(){},
	public:{
		id:-1,
		slider_item:[],
		parent:"",
		appendTo:"",
		time:0,
		init:function(){
			var i=-1;
			this.timer=new tools.Timer(this.time);
			this.timer.bind("timer",this.next);
			this.jqueryArray=[];
			this.jqueryArray[this.id]=$(this.parent).find("div.slaid");
			this.jqueryArray[this.id].css({
				opacity:1,
				position:"absolute",
				top:0,
				left:0
			});
			this.now=this.id;
			while(this.slider_item[++i]){
				if(i==this.id){
					this.load++;
					continue;
				}
				this.jqueryArray[i]=$(this.slider_item[i]);
				this.jqueryArray[i].css({
					opacity:0,
					position:"absolute",
					top:0,
					left:0
				});
				$(this.appendTo).append(this.jqueryArray[i]);
				this.jqueryArray[i].find("img").load(this.imagesLoading);
			}
		}
	},
	private:{
		now:0,
		timer:false,
		run:false,
		jqueryArray:[],
		load:0,
		next:function(){
			if(typeof this.jqueryArray[this.now+1]=="object"){
				this.step(
					this.jqueryArray[this.now],
					this.jqueryArray[this.now+1]
				);
				this.now++;
			}
			else{
				this.step(
					this.jqueryArray[this.now],
					this.jqueryArray[0]
				);
				this.now=0;
			}
		},
		step:function(a,b){
			b.css("display", "block");
			a.animate({
				opacity:0
			},2000, function(){
				$(this).css("display" , "none");
			});
			b.animate({
				opacity:1
			},2000);
		},
		imagesLoading:function(e){
			if(++this.load==this.slider_item.length && this.slider_item.length>1){
				this.timer.start();
			}
		}
	}
});
