var GaleryScripts = Class.create();
//var GaleryScripts = {};

GaleryScripts.prototype = {
	initialize: function() {
		this.parentBlock = $('parent_galery_block');
		this.scrollBlock = $('parent_galery_block').down();
		if(this.parentBlock == null || this.scrollBlock == null) return;		
		this.scrollWidth = this.scrollBlock.getWidth();
		this.parentWidth = this.parentBlock.getWidth();
		if(this.scrollWidth > this.parentWidth) this.initBlocks();	
		this.bigNode = null;	
	},
	
	initBlocks : function(){		
		this.cloneBlock = this.scrollBlock.cloneNode(true);				
		this.scrollable = Builder.node('div',{'style':'width:'+(this.parentWidth)+'px; height:'+(this.parentBlock.getHeight())+'px'},[			
				
				Builder.node('a',{href:'#',id:'parent_scrollLeft','style':'cursor:pointer;'},[
					Builder.node('div',{'style':'float:left; margin-right:1px;'},
						[Builder.node('img',{'style':'margin-top:5px;',src:'/dp_plugins/global/other/images/arrow_left.gif'})]
					),
				]),				
				Builder.node('div',{'style':'overflow:hidden; postion:relative; float:left; width:'+(this.parentWidth-22)+'px; height:'+this.parentBlock.getHeight()+'px'},
				[this.cloneBlock]					
				),
				Builder.node('a',{href:'#',id:'parent_scrollRight','style':'cursor:pointer;'},[
					Builder.node('div',{'style':'float:left; margin-left:1px;'},
						[Builder.node('img',{'style':'margin-top:5px;',src:'/dp_plugins/global/other/images/arrow_right.gif'})]
					)
				])		
			]	
		);			
		this.parentBlock.removeChild(this.scrollBlock);		
		this.parentBlock.appendChild(this.scrollable);		
		this.cloneBlock.setStyle({'position':'relative','left':0+'px'});												
		this.scrollBlock = this.cloneBlock;		
		this.parentWidth -= 20;
		this.initEvents();				
	},
	
	initEvents:function(){		
		$('parent_scrollLeft').observe('click',(function(event){
			event.stop();
			var left = parseInt(this.scrollBlock.getStyle('left'));
			left = Math.min((left + 100),0);			
			this.scrollBlock.setStyle({'left':left+'px'});						
		}).bind(this));
		
		$('parent_scrollRight').observe('click',(function(event){			
			event.stop();
			var left = parseInt(this.scrollBlock.getStyle('left'));
			left = Math.max((left - 100),(this.parentWidth-this.scrollWidth));									
			this.scrollBlock.setStyle({'left':left+'px'});
		}).bind(this));								
	}	
}
	
/*jQuery(document).ready(function(){
	if ($('parent_galery_block') != null) new GaleryScripts();	
});*/

document.observe('dom:loaded', (function () { 	
	if ($('parent_galery_block') != null) new GaleryScripts();	
}).bind(this));

