
LineGallery =  Class.create(new function(){}, {
	/*
	 * опции
	 */
		
	options:{
		width_element:200,
		images:0,
		border_img : 9.5,
		pause:false,
		count_actions:0
	},
	/*
	 * 
	 */
	
	action_move:null,
	/*
	 * запуск галереи
	 */
	show:function(){

		
	if(navigator.userAgent.indexOf("MSIE")!='-1'){
		this.options.border_img =0
		
	}
		//this.options.width_element = parseInt($$('.gallery_item')[0].getStyle('width'));
		//alert(parseInt($$('.gallery_item')[0].getStyle('padding')));
		$('gallery_win').setStyle({width:this.options.width_element*this.options.images+'px'});
		$('gallery_win').onmouseover= function (){Lgallery.pouse('stop')};
		$('gallery_win').onmouseout= function (){Lgallery.pouse('move')};
		$('gallery_win').setStyle({left:0});
		setTimeout('Lgallery.move()',4000);
		
	},
	
	/*
	 * 
	 */
	
	__getMaxLeft: function(){
		if (parseInt($('gallery_win').getStyle('width'))<2*parseInt($($('gallery_win').parentNode).getStyle('width')))
		
			var left = parseInt($('gallery_win').getStyle('width')) - 2*parseInt($($('gallery_win').parentNode).getStyle('width'));

		else 
			var left = parseInt($($('gallery_win').parentNode).getStyle('width'));

		left = 0;
		for(i=0;i<3;i++)
			left += parseInt($$('.gallery_item')[i].getStyle('width'))+this.options.border_img;
		left+=parseInt($('gallery_win').getStyle('left'))+5;
		return left;
	},
	/*
	 * двигалка
	 */

	
	move:function(){
		//alert(($($('gallery_win').parentNode)));
		
		var sub = 0;
		var tmp_width=0;
		var i=0;
		
		if(-parseInt($('gallery_win').getStyle('left')) >= this.__getMaxLeft())
			
		{
			
			//$('gallery_win').setStyle({left:-5});
				
				//this.options.tmp_width = parseInt($$('.gallery_item')[0].getStyle('width'));
				//alert(this.__getMaxLeft())
				//alert(parseInt($$('.gallery_item')[i+1].getStyle('left')));
				do {
					var tmp = $$('.gallery_item')[0];
						//var sub += $$('.gallery_item')[0].getStyle('width');
					//alert(parseInt($('gallery_win').getStyle('left')));
					
					var _tmp_new_left = parseInt($('gallery_win').getStyle('left')) + parseInt(tmp.getStyle('width'))+this.options.border_img;
					//alert(_tmp_new_left);
					$$('.gallery_item')[0].remove();
					$('gallery_win').appendChild(tmp);
					$('gallery_win').setStyle({left:_tmp_new_left+'px'});
				}
				while(parseInt($('gallery_win').getStyle('left')) + parseInt(tmp.getStyle('width'))<0)
				
					//alert(1);
		}
		
		//$('gallery_win').setStyle({left:parseInt($('gallery_win').getStyle('left'))+tmp});
		
		this.__lineGalleryMove(-(this.__getMaxLeft()));
	
	},
	
	/*
	 *  
	 */
	__lineGalleryMove: function(to){
		
		if (!this.options.pouse && (!this.action_move  ||this.action_move && this.action_move.state=='finished')){
			
			this.action_move =  new Effect.Move("gallery_win", { x: to+1, y: 0, mode: 'relative', duration:1.5, 
				
			afterFinish: function() {setTimeout('Lgallery.move()',4000)} });
		}else{
			setTimeout('Lgallery.move()',2000);
		}
	},
	
	/*
	 * пауза при наведении и клике
	 */
	pouse:function(action){
		if (action == 'stop'){
			this.options.pouse = true;
			//if(this.action_move.state=='running')
			{
				//this.options.count_actions--;
				///this.action_move.state = 'finished';
				//this.action_move.cancel();
				//this.action_move.finish();
				this.action_move.state = 'finished';
				//this.action_move = null;
			}
		}
		if (action == 'move'){
			this.options.pouse = false;
			
			//if(this.action_move && this.action_move.state!='finished')
				//this.action_move.cancel();
			//sLgallery.action_move.state = "running";',1000);
			//alert(move_to);
			//this.__lineGalleryMove(-parseInt($$('.gallery_item')[0].getStyle('width')));
		}
	},
	/*
	 * добавление изображение
	 */
	
	addImage: function(small,big){
			var img =  new Element('img',{src: small});
			var gallery_item =$('gallery_win').appendChild(new Element('a',{href: big,'class': 'gallery_item',rel:'lightbox[manager]',target:'_blank'}).update(new Element('img',{src: small}) ));
			//var gallery_item =$('gallery_win').appendChild(new Element('a',{href: big,'class': 'gallery_item',rel:'lightbox[manager]',target:'_blank'}));
			
			this.options.images++;	
			
			
	},
	
	
	/*
	 * быстрое листание влево
	 */
	listLeft:function(){
		for (i=0;i<5;i++){
			var tmp = $$('.gallery_item')[this.options.images-1];
			//var sub += $$('.gallery_item')[0].getStyle('width');
	
			$$('.gallery_item')[this.options.images-1].remove();
			$('gallery_win').insertBefore(tmp,$$('.gallery_item')[0]);
		}
	},
	/*
	 * быстрое листание вправо
	 */
	listRight:function(){
		for (i=0;i<5;i++){
			var tmp = $$('.gallery_item')[0];
			////var sub += $$('.gallery_item')[0].getStyle('width');
	
			$$('.gallery_item')[0].remove();
			$('gallery_win').appendChild(tmp);
		}
		
		
	}
	
	
	
});

