// JavaScript Document
function setMouseWheelListener(o){
	o.onmousemove=o.onmouseover=function(event){
		todo._blockScroll=true;
		event=event||window.event;
		if(event.stopPropagation)event.stopPropagation();
		else event.cancelBubble=true;
		if(event.preventDefault)event.preventDefault();
		else event.returnValue=false;
		document.onmouseover=function(){
			todo._blockScroll=false;
			document.onmouseover=null;
		}
	};
	var func=function(o){return function(event){
		var delta;
		event=event||window.event;
		if(event.wheelDelta)delta=event.wheelDelta/120;
		else if(event.detail)delta=-event.detail/3;
		if(todo._blockScroll){
			if(event.stopPropagation)event.stopPropagation();
			else event.cancelBubble=true;
			if(event.preventDefault)event.preventDefault();
			else event.returnValue=false;
			o._onmousewheel(delta);
		};
		return delta; 
	}}(o);
	if(typeof document.attachEvent!='undefined')document.attachEvent('onmousewheel',func);
	else window.addEventListener('DOMMouseScroll',func,false);
};
function galleryScroll(idButtonLeft,idButtonRight,idContainer){
	this.cnt=todo.get(idContainer);
	this.cnt._step=10;
	//this.cnt.style.width='535px';
	this.cnt.style.whiteSpace='nowrap';
	this.cnt.style.overflow='hidden';
	this.bl=todo.get(idButtonLeft);
	this.br=todo.get(idButtonRight);
	this.bl.onmousedown=function(){this._$.cnt._scroll(-1);};
	this.bl.onmouseup=function(){this._$.cnt._stopScroll();};
	this.br.onmousedown=function(){this._$.cnt._scroll(1);};
	this.br.onmouseup=function(){this._$.cnt._stopScroll();};
	this.cnt._stopScroll=function(){
		window.clearInterval(this._timerId);
		this._timerId=0;
	};
	this.cnt._scroll=function(direction){
		var leftDir=this.scrollLeft<this._step,
			rightDir=this.scrollLeft>this.scrollWidth-this.offsetWidth-this._step,
			isEnd=direction<0 ? leftDir : rightDir;
		if(!this._timerId)this._timerId=window.setInterval(function(o,direction){return function(){o._scroll(direction);}}(this,direction),40);
		if(isEnd){
			var chn=this.getElementsByTagName('span'),e;
			if(direction<0)e=this.insertBefore(this.removeChild(chn[chn.length-1]),chn[0]);
			else e=this.appendChild(this.removeChild(chn[0]));
			this.scrollLeft-=e.offsetWidth*direction;
		};
		this.scrollLeft+=this._step*direction;
	};
	this.cnt._init=function(){
		var chn=this.getElementsByTagName('a'),
			d1=todo.create('span'),
			d2=todo.create('span');
		while(this.firstChild){
			var e=this.removeChild(this.firstChild);
			if(e.nodeName.toLowerCase()!='a')continue;
			d1.appendChild(e.cloneNode(true));
			d2.appendChild(e);
		};
		this.appendChild(d1);
		this.appendChild(d2);
	};
	this.cnt._init();
	this.cnt._onmousewheel=function(delta){this._scroll(-delta);this._stopScroll()};
	setMouseWheelListener(this.cnt);
	for(i in this)if(this[i])this[i]._$=this;
};
