function initGallery(gall){document.getElementById(gall).gallery = new galleryConstruct(gall);}

function galleryConstruct(){
	this.time = 50;
	this.step = 10;
	
	this.id = arguments[0];
	tmp = document.getElementById(this.id).getElementsByTagName('a');
	this.imgWidth = tmp[4].offsetWidth;
//	alert(this.imgWidth);
	this.miniStep = this.imgWidth/this.step;
	this.t = null;
	this.counter = 0;
	this.pos = 0;
	}


galleryConstruct.prototype.move = function(){
	this.way = arguments[0] ? true : false;
	this.pos = document.getElementById(this.id).scrollLeft;
	if(!this.t) this.t = setInterval(function(){this.timer()}.bind(this),10);
}

galleryConstruct.prototype.stopper = function(){
	window.clearInterval(this.t);
	this.t = null;
	this.counter = 0;
}

galleryConstruct.prototype.timer = function(){
	
	if(this.way){
		this.pos += this.miniStep;
		this.counter += this.miniStep;
	}
	if(!this.way){
		this.pos -= this.miniStep;
		this.counter -= this.miniStep;
	}
	document.getElementById(this.id).scrollLeft = Math.round(this.pos);
	
	this.check();
	
	if(Math.abs(Math.round(this.counter))==this.imgWidth) {
		
			
			
			this.stopper();
		}
}
galleryConstruct.prototype.check = function(){
	tmp = document.getElementById(this.id).scrollWidth - document.getElementById(this.id).clientWidth - document.getElementById(this.id).scrollLeft;
	if( tmp < Math.round(this.miniStep) ) document.getElementById(this.id).scrollLeft += tmp;
	if(document.getElementById(this.id).scrollLeft < Math.round(this.miniStep)) document.getElementById(this.id).scrollLeft=0;
}

Function.prototype.bind=function(object){var method=this;return function(){return method.apply(object,arguments)}}
