var YJns1Slide=new Class({
	initialize:function(container,options){
		this.container=container;
		this.options=options;
		var automated;
		var direction;
		var hideshow_flag;

		this.hideshow_flag=true;
		if(this.options){
			this.direction=this.options.direction
		}else{
			this.direction="forward"
		};

		if(this.direction!="pause"){
			if(this.options.auto=="loop"||this.options.auto=="once"){
				this.automated=this.klizi.periodical(this.options.time,this,$(this.container))
			}else{
				this.klizi($(this.container))
			}
		}
	},
	
	naprijed:function(type){
		if(this.options.auto=="loop"||this.options.auto=="once"){
			this.pauza()
		};
		
		this.options.type=type;
		this.direction="forward";
		this.klizi($(this.container))
	},

	nazad:function(type){
		if(this.options.auto=="loop"||this.options.auto=="once"){
			this.pauza()
		};

		this.options.type=type;
		this.direction="back";
		this.klizi($(this.container))
	},

	pauza:function(){
		this.direction="pause";
		this.klizi($(this.container))
	},

	radi:function(){
		this.direction="forward";
		this.automated=this.klizi.periodical(this.options.time,this,$(this.container))
	},

	klizi:function(container){
		if((this.options.auto=="once"||this.options.auto=="loop")&&this.direction=="pause"){
			$clear(this.automated)
		}else{
			var child;
			var children=container.getChildren().getChildren()[0];

			children.each(function(e){
				if(e.id=="currentChild"){
					child=e
				}
			});
			
			if(!child&&(this.direction=="forward"||this.direction=="pause")){
				child=children[0].getNext();
				child.id="currentChild"
			}else{
				if(this.direction=="forward"){
					var lastElement=container.getChildren()[0].getLast();
					
					if(lastElement==child.getNext()&&this.options.auto=="once"){
						$clear(this.automated);
					}
					
					if(lastElement==child){
						child=children[0];
					}else{
						child=child.getNext();
					}
				};
				
				if(this.direction=="back"){
					var firstElement=container.getChildren()[0].getFirst();
					
					if(firstElement==child.getPrevious()&&this.options.auto=="once"){
						$clear(this.automated)
					}
					
					if(firstElement==child){
						child=container.getChildren()[0].getLast()
					}else{
						child=child.getPrevious();
					}
				}
			};
			
			if(child&&this.direction!="pause"){
				if(this.options.type=="scroll"){
					this.scroll(container,children,child)
				}else{
					if(this.options.type=="fade"){
						this.fade(container,children,child)
					}else{
						if(this.options.type=="scrollfade"){
							this.scrollfade(container,children,child)
						}
					}
				}
			}
		}
	},
		
	init_vertical:function(){
		$(this.container).setStyle('position','relative');
		
		var children=$(this.container).getChildren().getChildren()[0];
		
		var i;
		var s_h;
		var s_w;
		var b_w;
		b_w=$(this.container).getStyle('border-width').toInt();
		s_h=$(this.container).getSize().size.y-2*b_w;
		s_w=$(this.container).getSize().size.x-2*b_w;
		i=0;
		
		children.each(function(e){
			if(i!==0){
				e.id="currentChild";
				$('currentChild').setStyle('position','relative');
				$('currentChild').setStyle('left',0-s_w*i);
				$('currentChild').setStyle('top',0+s_h*i);
				
				e.id="";
			};
			i++
		});
		
		children.each(function(e){
			e.id=""
		})
	},
	
	init_horizontal:function(){
		$(this.container).setStyle('position','relative');
		
		var children=$(this.container).getChildren().getChildren()[0];
		var i;
		var s_h;
		var s_w;
		var b_w;
		
		b_w=$(this.container).getStyle('border-width').toInt();
		s_h=$(this.container).getSize().size.y-2*b_w;
		s_w=$(this.container).getSize().size.x-2*b_w;
		
		i=0;
		
		children.each(function(e){
			if(i!==0){
				e.id="currentChild";
				
				$('currentChild').setStyle('position','relative');
				$('currentChild').setStyle('left',0);
				$('currentChild').setStyle('top',0);
				e.id=""
			}
			i++;
		})
	},
	
	scroll:function(container,children,child){
		var scroll=new Fx.Scroll(container,{
				duration:this.options.duration,
				onComplete:function(){
					children.each(function(e){
						e.id=""
					});
					child.id="currentChild"
				}
			}).toElement(child)
	},
			
	fade:function(container,children,child){
		var fade=new Fx.Style(container,'opacity',{
				duration:this.options.duration,
				onComplete:function(){
					new Fx.Scroll(container,{
							duration:1,
							onComplete:function(){
								children.each(function(e){
									e.id=""
								});
								
								child.id="currentChild";
								new Fx.Style(container,'opacity').start(0.01,1);
								$('pozicija').style.background="transparent";
							}
						}).toElement(child)
					}
				});
		
		fade.start(1,0.01);
		//$('pozicija').style.background="url(modules/mod_yj_ns1/images/loader.gif) no-repeat center center"
		$('pozicija').style.background="#000000";
	},
	
	scrollfade:function(container,children,child){
		var durationInt=this.options.duration.toInt();
		var fade=new Fx.Style(container,'opacity',{
				duration:(durationInt/2)
			});
		
		//$('pozicija').style.background="url(modules/mod_yj_ns1/images/loader.gif) no-repeat center center";
		$('pozicija').style.background="#000000";
		
		fade.start(1,0.01).chain(function(){
			fade.start(0.01,1);
			$('pozicija').style.background="transparent"
		});
		
		new Fx.Scroll(container,{
				duration:durationInt,
				onComplete:function(){
					children.each(function(e){
						e.id=""
					});
					child.id="currentChild"
				}
			}).toElement(child)
	},
	
	hide_and_show_fade:function(){
		var fade=new Fx.Style($(this.container),'opacity',{
				duration:this.options.duration
			});
		
		if(this.hideshow_flag){
			fade.start(1,0.01)
		}else{
			fade.start(0.01,1)
		}
		
		this.hideshow_flag=!this.hideshow_flag
	}
});
