function getElementById(id){
	var elem = $(id);
	if(elem!=null){
		return new Element(elem);
	}else{
		return  null;
	}
}

function isEmail(strEmail) {
	if (strEmail
			.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
	}else{
		return false;
	}
}

var UploadFaceControl = new Class({
	initialize:function(){
		this.TriggerBtn=null;
		this.ChosenFace=null;
		this.ChosenFaceUrl=null;
		this.UploadFaceBox = null;
		this.UploadForm=null;
		this.UploadBtn=null;
		this.CancelBtn=null;
		this.CloseBtn = null;
	},
	build:function(trigger, face, faceUrl){
		this.TriggerBtn=trigger;
		this.ChosenFace=face;
		this.ChosenFaceUrl=faceUrl;
		this.UploadForm=$('FaceUploadForm');
		this.ChooseUpload=$('ChooseUpload');
		this.UploadBtn=$('uploadtoserver');
		this.CancelBtn=$('uploadcancel');
		this.TriggerBtn.addEvent('click', this.open.bind(this));
		this.UploadFaceBox=$('UploadFace');
		this.CloseBtn=this.UploadFaceBox.getElement('dt').getElement('img');
		this.CloseBtn.addEvent('click', this.close.bind(this));
		new UploadFaceHandler(this);
	},
	open:function(){
		this.UploadFaceBox.setStyle('display', 'block');
	},
	close:function(){
		this.UploadFaceBox.setStyle('display', 'none');
	},
	uploadSuccess:function(logoUrl){
		this.ChosenFace.src = APP_PATH+"/"+logoUrl;
		this.ChosenFaceUrl.value = logoUrl;
		AJAX_LOADER.complete($('UploadFaceHolder'));
		this.close();
	}
});

var UploadFaceHandler=new Class({
	initialize:function(control){
		this.UploadFaceControl=control;
		this.UploadFaceControl.UploadBtn.addEvent('click', this.upload.bind(this));
		this.UploadFaceControl.CancelBtn.addEvent('click', this.cancelUpload.bind(this));
	},
	upload:function(){
		if(this.UploadFaceControl.ChooseUpload.value != ''){
			var parentNode = this.UploadFaceControl.ChooseUpload.parentNode;
			this.UploadFaceControl.UploadForm.innerHTML = '';
			this.UploadFaceControl.UploadForm.appendChild(this.UploadFaceControl.ChooseUpload);
			this.UploadFaceControl.UploadForm.submit();
			AJAX_LOADER.loading($('UploadFaceHolder'));
			this.UploadFaceControl.UploadForm.innerHTML = '';
			parentNode.appendChild(this.UploadFaceControl.ChooseUpload);
		}
	},
	cancelUpload:function(){
		this.UploadFaceControl.close();
	}
});

function initSelecter(e){
	this.Set = function(e){
		this.style.left = e.clientX + document.documentElement.scrollLeft +  "px";
		this.style.top = e.clientY + document.documentElement.scrollTop + "px";
	}
	this.Set(e);
    if(!this.close){
        this.close = function(){this.style.display = "none";this.display = false;};
        this.open = function(e){this.Set(e);this.style.display = "block";this.display = true;};
    }
}

function DragTitle(e, target){
    if(!e)e = window.event;
    var oObj = e.target?e.target:e.srcElement;
    var dragTarget = null;
    if(target){
    	dragTarget = target;
    } else {
    	dragTarget = this.parentNode;
    }
    if(this==oObj){
		var intObjX = e.clientX - parseInt(dragTarget.style.left);
		var intObjY = e.clientY - parseInt(dragTarget.style.top);
		if(this.setCapture){
			this.setCapture();
		}else if(window.captureEvents){
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		}
		document.onmousemove = function(e){
		    if(!e)e = window.event;
		    BatchDiffStyle.call(dragTarget,["left",e.clientX - intObjX + "px"]
		            ,["top",e.clientY - intObjY + "px"]);
		}
		document.onmouseup = function(e){
		    if(this.releaseCapture){
		     this.releaseCapture();
		    }else if(window.captureEvents){
		     window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		    }
		    document.onmousemove = null;
		    document.onmouseup = null;
		}
	}
}

var Draggable = new Class({
	initialize:function(dragController, dragTarget, container){
		this.dragController = dragController;
		this.dragTarget = dragTarget;
		this.container = container;
		this.makeDraggable();
	},
	makeDraggable:function(){
		var dragTarget=this.dragTarget;
		this.dragController.onmousedown = function(e){
			DragTitle.call(this, e, dragTarget);
		};
	}
});

var CurtainEffect = new Class({
	initialize:function(switchBtn, screenControl, options){
		this.switchBtn=switchBtn;
		this.screenControl=screenControl;
		if(options){
			this.screenControl.maxHeight=options.maxHeight;
			this.screenControl.speedRate=options.speedRate;
			this.screenControl.delay=options.delay;
			this.cookieName=options.cookieName;
		}
		this.buildCurtain.call(this.screenControl, this);
		if(this.screenControl.style.display == "block"){
	        this.switchBtn.open = true;
	    }else{
	        this.switchBtn.open = false;
	    }
	    this.switchBtn.onclick = function(){
	    	if(this.switchBtn.open){
	    		this.screenControl.close();
	    	}else{
	    		this.screenControl.open();
	    	}
	    }.bind(this);
	},
	buildCurtain:function(curtain){
		var curtainControl = curtain;
		this.step = this.maxHeight*this.speedRate;
		this.limit = this.maxHeight-this.step;
		this.preOpen = function(){
			this.clearIntervals();
			this.realHeight=0;
			this.style.height="1px";
			this.style.display="block";
			curtainControl.switchBtn.blur();
		};
		this.open = function(){
			this.preOpen();
			this.setOpenInterval = setInterval(function(){
				this.realHeight=this.offsetHeight+this.step;
				if(this.realHeight<=this.limit){
					this.style.height=this.realHeight+"px";
				}else{
					this.postOpen();
				}
			}.bind(this), this.delay);
		};
		this.postOpen = function(){
			clearInterval(this.setOpenInterval);
			this.style.height=this.maxHeight+"px";
			curtainControl.switchBtn.open=true;
			curtainControl.switchBtn.blur();
			/*
			 * var obj = this; var loadingBox = new LoadingBox();
			 * loadingBox.bindCloseFunc(function(){ obj.close(); this.close();
			 * }); loadingBox.loading();
			 */
			this.saveState();
		};
		this.preClose = function(){
			this.clearIntervals();
			this.realHeight=this.maxHeight;
			this.style.height=this.maxHeight+"px";
			this.style.display="block";
			curtainControl.switchBtn.blur();
		};
		this.close = function(){
			this.preClose();
			this.setHiddenInterval=setInterval(function(){
				this.realHeight=this.offsetHeight-this.step;
				if(this.realHeight>0){
					this.style.height=this.realHeight+"px";
				}else{
					this.postClose();
				}
			}.bind(this), this.delay);
		};
		this.postClose = function(){
			clearInterval(this.setHiddenInterval);
			this.style.display="none";
			curtainControl.switchBtn.open=false;
			/* curtainControl.switchBtn.className=""; */
			this.saveState();
			curtainControl.switchBtn.blur();
		};
		this.clearIntervals = function(){
	        if(this.setOpenInterval){
	        	clearInterval(this.setOpenInterval);
	        }
	        if(this.setHiddenInterval){
	        	clearInterval(this.setHiddenInterval);
	        }
	    };
	    this.saveState = function(){
	    	document.cookie = curtainControl.cookieName + "=" + this.style.display + "; expires=" + AddDays(365) + "; path=/";
	    }
	}
});

var ResizeTextArea = new Class({
	initialize:function(textArea){
		this.textArea = textArea;
		this.enableResize();
	},
	enableResize:function(){
		this.textAreaWrapper=new Element("div");
		this.textAreaWrapper.setStyle("float", "left");
		this.textAreaWrapper.setStyle("width", this.textArea.style.width);
		this.resizeBar = new Element("div");
		this.resizeBar.addClass("sizebar");
		this.resizeBar.appendChild(new Element("ins"));
		this.resizeBar.addEvent("mousedown", this.resizing.bind(this));
		this.textArea.parentNode.appendChild(this.textAreaWrapper);
		this.textAreaWrapper.appendChild(this.textArea);
		this.textAreaWrapper.appendChild(this.resizeBar);
	},
	resizing:function(e){
		if(!e)e=window.event;
		var target = this.textArea;
		var initY = e.clientY;
		var targetDefaultHeight=this.textArea.offsetHeight;
		if(this.setCapture){
			this.setCapture();
		}else if(window.captureEvents){
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		}
		document.onmousemove = function(e){
			if(!e)e=window.event;
			var newHeight=targetDefaultHeight+e.clientY-initY;
			if(newHeight<50){
				newHeight=50;
			}
			target.setStyle("height", newHeight+"px");
		}
		document.onmouseup=function(e){
			if(this.releaseCapture){
				this.releaseCapture();
			}else if(window.captureEvents){
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			}
			document.onmousemove=null;
			document.onmouseup=null;
		}
	}
});

var AlphaEffect = new Class({
	initialize:function(elem, imgs, options){
		this.elem = elem;
		this.defaultImg=elem.src;
		this.imgs = imgs;
		this.index = -1;
		if(options){
			this.alpha=options.alpha;
			this.speed=options.speed;
			this.delay=options.delay;
			this.status=options.status;
		}
	},
	clearIntervals:function(){
		if(this.showInterval){
			clearInterval(this.showInterval);
		}
		if(this.hideInterval){
			clearInterval(this.hideInterval);
		}
	},
	show:function(){
		this.showInterval=setInterval(function(){
			this.alpha+=this.speed;
			if(this.alpha>=10){
				this.alpha=10;
				SetAlpha(this.elem,this.alpha);
				this.clearIntervals();
				this.status=false;
				if(this.showFunc){
					this.showFunc();
				}
				this.hide();
			}else{
				SetAlpha(this.elem,this.alpha);
			}
		}.bind(this), this.delay);
	},
	hide:function(){
		this.status=true;
		this.hideInterval=setInterval(function(){
			this.alpha-=this.speed;
			if(this.alpha<=0){
				this.alpha=0;
				SetAlpha(this.elem,this.alpha);
				this.clearIntervals();
				if(this.hideFunc){
					this.hideFunc();
				}
				this.showNext();
			}else{
				SetAlpha(this.elem,this.alpha);
			}
		}.bind(this), this.delay);
	},
	showNext:function(){
		this.index++;
		if(this.index < this.imgs.length){
			this.elem.src=this.imgs[this.index];
		}else{
			this.index=-1;
			this.elem.src=this.defaultImg;
		}
		this.show();
	}
	
});

var AutoScroll = new Class({
	initialize:function(options){
		if(options){
			this.speedRate=0.1;
			this.delay=10;
		}
	},
	scroll:function(topLimit){
		this.topLimit = topLimit;
		this.clearIntervals();
		if(this.topLimit == this.scrollTop){
			return false;
		}
		this.speed=(this.topLimit-this.scrollTop)*this.speedRate;
		this.scrollInterval=setInterval(function(){
			this.scrollTop+=this.speed;
			if((this.speed>0 && this.scrollTop>=this.topLimit)||(this.speed<0&&this.scrollTop<=this.topLimit)){
				this.stop();
			}
		}.bind(this), this.delay);
	},
	stop:function(){
		this.clearIntervals();
		this.scrollTop=this.topLimit;
	},
	clearIntervals:function(){
		if(this.scrollInterval){
			clearInterval(this.scrollInterval);
		}
	}
});

var ListControl = new Class({
	initialize:function(listContainer){
		this.listContainer = listContainer;
		this.switchBtns=$$(".itemBtn");
		this.screenControls=$$(".screen");
		this.listControlBtns=$$(".listControlBtn");
		this.cookieName="ListMode";
		this.isEffect = true;
	},
	initListControl:function(){
		for(var i=0; i<this.listControlBtns.length; i++){
			this.listControlBtns[i].onclick=this.listControlHandle;
			this.listControlBtns[i].changeListControlMode=this.changeListControlMode;
			this.listControlBtns[i].control=this;
			if(this.listControlBtns[i].className=="choose"){
				this.currentModeBtn=this.listControlBtns[i];
				this.currentMode=Number(this.currentModeBtn.rel);
			}
		}
		this.switchBtns.control=this;
		this.switchBtns.handle=this.itemBtnHandle;
		for(var i=0; i<this.switchBtns.length; i++){
			this.switchBtns[i].control=this;
			this.switchBtns[i].mode=this.currentMode;
			new CurtainEffect(this.switchBtns[i], this.screenControls[i], {
				maxHeight:29,
				speedRate:0.08,
				delay:10,
				maxHeight:150
			});
			this.switchBtns[i].handle=this.normalHandle;
		}
	},
	listControlHandle:function(){
		this.blur();
		if(this.rel!=this.control.currentMode){
			this.changeListControlMode();
			this.control.switchBtns.hand();
		}
	},
	changeListControlMode:function(){
		this.control.currentModeBtn.className="";
		this.className="choose";
		this.control.currentModeBtn=this;
		this.control.currentMode=Number(this.rel);
		this.control.saveState();
	},
	itemBtnHandle:function(){
		for(var i=0;i<this.length;i++){
			if(this[i].mode!=this.control.currentMode){
				if(this.control.isEffect){
					this[i].onclick();
				}else{
					this[i].handle();
				}
			}
		}
	},
	normalHandle:function(){
	},
	saveState : function(){
    }
});

var EffectWindow = new Class({
	initialize:function(switchBtn, screenControl){
		this.switchBtn=switchBtn;
		this.switchBtn.control=this;
		this.screenControl=screenControl;
		this.screenControl.control=this;
		this.maxHeight=100;
		this.maxWidth=209;
		this.speed=0.15;
		this.fix=20;
		this.delay=10;
		this.status=false;
		bindEvents();
	},
	bindEvents:function(){
		this.switchBtn.onmouseover=this.switchOverHandler.bind(this);
		this.switchBtn.onmouseout=this.switchOutHandler.bind(this);
		this.switchBtn.onclick=this.switchClickHandler.bind(this);
		this.screenControl.onmouseover=this.screenOverHandler;
	},
	switchOverHandler:function(){
		if(this.hideTimeout){
			clearTimeout(this.hideTimeout);
		}
		if(!this.status){
			var obj=this;
			this.openTimeout=setTimeout(function(){
				obj.open();
			}, 200);
		}
	},
	switchOutHandler:function(){
		if(this.openTimeout){
			clearTimeout(this.openTimeout);
		}
		if(this.status){
			var obj=this;
			this.hideTimeout=setTimeout(function(){
				obj.close();
			}, 500);
		}
	},
	switchClickHandler:function(){
		this.clearSetTimes();
		this.setStatus();
	},
	screenOverHandler:function(){
		var obj=this;
		document.onmouseover=function(e){
			if(!e){
				e=window.event;
			}
			var eventObj=e.target?e.target:e.srcElement;
			if(obj.getParent(eventObj, obj.screenControl)){
				if(obj.hideTimeout){
					clearTimeout(obj.hideTimeout);
				}
			}else{
				obj.switchOutHandler();
				document.onmouseover=null;
			}
		}
	},
	open:function(){
		this.clearSetTimes();
		this.screenControl.style.background="none";
		this.screenControl.style.display="block";
		this.openInterval=setInterval(function(){
			this.setStyle(this.screenControl.offsetHeight + (this.maxHeight * this.speed-this.fix),
		        this.screenControl.offsetWidth + (this.maxWidth * this.speed-this.fix),
		        (this.maxWidth - this.screenControl.offsetWidth)/2);
		    if(this.screenControl.offsetWidth >= this.maxWidth || this.screenControl.offsetHeight >= this.maxHeight){
                this.setStyle(this.maxHeight,this.maxWidth,0);
			    this.screenControl.style.backgroundColor = "#FFF";
                this.status = true;
                clearInterval(this.openInterval);
            }
		}.bind(this), this.delay);
	},
	close:function(){
		this.clearSetTimes();
		this.screenControl.style.background="none";
		this.closeInterval=setInterval(function(){
			this.setStyle(this.screenControl.offsetHeight - (this.maxHeight * this.speed+this.fix),
                this.screenControl.offsetWidth - (this.maxWidth * this.speed+this.fix),
                (this.maxWidth - this.screenControl.offsetWidth)/2
            );
            if(this.screenControl.offsetWidth <= 42 || this.screenControl.offsetHeight <= 30){
                this.setStyle(0,0,this.maxWidth / 2);
                this.screenControl.style.display = "none";
                this.status = false;
                clearInterval(this.closeInterval);
            }
		}.bind(this), this.delay);
	},
	setStatus:function(){
        if(this.status){
        	this.close();
        }else{
        	this.open();
        }
    },
    setStyle:function(height,width,marginLeft){
        this.screenControl.style.height = height + "px";
	    this.screenControl.style.width = width + "px";
	    this.screenControl.style.marginLeft = marginLeft + "px";
    },
    getParent:function(Contain){
	    var oParent = this;
	    while(oParent.tagName != "HTML"){
		    if(oParent == Contain){
			    return true;
		    }
		    oParent = oParent.parentNode;
	    }
	    return false;
    },
	clearSetTimes:function(){
        if(this.openInterval)clearInterval(this.openInterval);
        if(this.closeInterval)clearInterval(this.closeInterval);
	    if(this.hideTimeout)clearTimeout(this.hideTimeout);
	    if(this.openTimeout)clearTimeout(this.openTimeout);
    }
});

var SelectControl = new Class({
	initialize:function(selectDivs){
		this.selectDivs = selectDivs;
		this.openSelectDiv=null;
		this.isOpen = false;
		this.bindEvents();
	},
	bindEvents:function(){
		for(var i=0;i<this.selectDivs.length;i++){
			var currentSelectDiv = this.selectDivs[i];
			currentSelectDiv.addEvent('click', this.selectDivFunc.bindWithEvent([this, currentSelectDiv]));
			var selectLis=currentSelectDiv.getElements('li');
			for(var j=0;j<selectLis.length;j++){
				var selectLi = selectLis[j];
				selectLi.addEvent('click', this.selectLiFunc.bind([selectLi, currentSelectDiv, this]));
			}
		}
	},
	enableCaptureEventFunc:function(){
		var thisControl = this[0];
		var selectDiv = this[1];
		var tempCapture = null;
		if(selectDiv.setCapture){
			selectDiv.setCapture();
			tempCapture = selectDiv;
		}else if(window.captureEvents){
			window.captureEvents(Event.Click);
			tempCapture = window;
		}
		var release = function(){
			var thisControl = this[0];
			var selectDiv = this[1];
			if(selectDiv.releaseCapture){
				selectDiv.releaseCapture();
			}else if(window.releaseEvents){
				window.releaseEvents(Event.Click);
			}
			thisControl.closeSelectDivFunc();
			tempCapture.removeEvents('click');
		}
		tempCapture.addEvent('click', release.bind(this));
	},
	selectDivFunc:function(e){
		if(e){
			e.stop();
		}
		var thisControl = this[0];
		var currentSelect = this[1];
		var divStateOpen = currentSelect.hasClass("open");
		if (thisControl.isOpen) {
			if(thisControl.openSelectDiv!=null){
				thisControl.openSelectDiv.removeClass("open");
			}
			thisControl.isOpen = false;
		}
		if(!divStateOpen){
			currentSelect.addClass("open");
			thisControl.openSelectDiv=currentSelect;
			thisControl.isOpen = true;
			// thisControl.enableCaptureEventFunc.call([thisControl,
			// currentSelect]);
		}
	},
	closeSelectDivFunc:function(e){
		var thisControl = this;
		if (thisControl.isOpen) {
			if(thisControl.openSelectDiv!=null){
				thisControl.openSelectDiv.removeClass("open");
			}
			thisControl.isOpen = false;
		}
	},
	selectLiFunc:function(){
		var selectLi = this[0];
		var selectDiv = this[1];
		var thisControl = this[2];
		var filterDiv = selectDiv.getElements('.filterWrapper')[0];
		var displayTextDiv = filterDiv.getPrevious();
		if(!displayTextDiv.hasClass('selected')){
			displayTextDiv.addClass('selected');
		}
		if(selectDiv.hasClass('open')){
			selectDiv.removeClass('open');
		}
		thisControl.selectDivFunc.call([thisControl, selectDiv]);
	}
});

var NavigationControl = new Class({
	initialize:function(navMenu){
		this.navMenu = navMenu;
		this.navItems = navMenu.getElements('li.firstlevel');
		this.TIMEOUT = 200;
		this.bindEvents();
		this.currentStyle = null;
	},
	bindEvents:function(){
		for(var i=0;i<this.navItems.length;i++){
			var thisNavItem = this.navItems[i];
			this.navItems[i].addEvent('mouseenter', this.activateNavItem.bind([thisNavItem, this]));
			this.navItems[i].addEvent('mouseleave', this.deActivateNavItem.bind([thisNavItem, this]));
		}
	},
	toggleCurrent : function(dir) {
        var thisNavItem = this[0];
        var thisControl = this[1];
        if(!thisControl.currentStyle) {
        	thisControl.currentStyle = thisNavItem.getProperty("class");
        }
        if(dir) {
        	thisNavItem.getParent().addClass(thisControl.currentStyle)
        } else {
        	thisNavItem.getParent().removeClass(thisControl.currentStyle)
        }
    },
	activateNavItem:function(){
		var thisNavItem = this[0];
		var thisControl = this[1];
		thisNavItem.timeOutEvent = setTimeout(function() {
			this[1].toggleCurrent.call(this, false);
            this[0].removeClass("hover");
            this[0].addClass("hover");
        }.bind([thisNavItem, thisControl]), thisControl.TIMEOUT);
		if (thisNavItem.getProperty('class')!="firstlevel active"){
			var activeNavItem = thisControl.navMenu.getElements("li.firstlevel.active")[0];
			if(activeNavItem && activeNavItem!=null){
				activeNavItem.addClass("active_but_not");
				activeNavItem.removeClass("active");
			}
		}
	},
	deActivateNavItem:function(){
		var thisNavItem = this[0];
		var thisControl = this[1];
		if(thisNavItem.timeOutEvent){
			clearTimeout(thisNavItem.timeOutEvent);
		}
		thisNavItem.timeOutEvent = setTimeout(function() {
			this[1].toggleCurrent.call(this, true);
            this[0].removeClass("hover");
        }.bind([thisNavItem, thisControl]), thisControl.TIMEOUT);
		var activeNavItem = thisControl.navMenu.getElements("li.firstlevel.active_but_not")[0];
		if(activeNavItem && activeNavItem!=null){
			activeNavItem.addClass("active");
			activeNavItem.removeClass("active_but_not");
		}
	}
});

var SlideShowControl = new Class({
	initialize:function(slideShow, index){
		this.slideShow = slideShow;
		this.slidePics = slideShow.getElements("li");
		this.displayPane = $('productimg');
		this.bigDisplayPane = $('productimghref')
		this.previousIndex = 0;
		this.currentIndex = index;
		this.bindEvents();
		this.slideShowList.scroll();
	},
	bindEvents:function(){
		this.leftBtn = this.slideShow.getElements(".slideshow-left-btn")[0];
		this.rightBtn = this.slideShow.getElements(".slideshow-right-btn")[0];
		this.slideShowClip = this.slideShow.getElements(".slideshow-clip")[0];
		this.slideShowList = this.slideShow.getElements(".slideshow-list")[0];
		this.slideShowList.scroll = this.triggerScroll.bind(this);
		this.slideShowList.clear = this.clearScrollEvent.bind(this);
		this.leftBtn.onclick = function(){
			if(this.currentIndex>-1){
				if(this.currentIndex-4 > -1){
					this.currentIndex -= 4;
				}else{
					this.currentIndex = 0;
				}
				this.scrollTo(this.currentIndex);
			}else if(this.currentIndex == 0){
				this.scrollTo(this.currentIndex);
			}
		}.bind(this);
		this.rightBtn.onclick = function(){
			if(this.currentIndex < this.slidePics.length-1){
				if(this.currentIndex+4 < this.slidePics.length-1){
					this.currentIndex += 4;
				}else{
					this.currentIndex = this.slidePics.length-1;
				}
				this.scrollTo(this.currentIndex);
			}else if(this.currentIndex == this.slidePics.length-1){
				this.scrollTo(this.currentIndex);
			}
		}.bind(this);
	},
	clearScrollEvent:function(){
		var justThis=this.slideShowList;
		if(justThis.scrollEffect){
			clearInterval(justThis.scrollEffect);
		}
	},
	triggerScroll:function(){
		if(this.previousIndex != this.currentIndex){
			this.slidePics[this.previousIndex].removeClass('selected');
			var justThis = this.slideShowList;
			justThis.clear();
			justThis.endPosition = this.currentIndex * 60;
			justThis.toMargin = (this.previousIndex * 60) - justThis.endPosition;
			justThis.stepLength = justThis.toMargin/10;
			justThis.scrollEffect = setInterval(function(){
				var margin = justThis.getStyle('margin-left').toInt();
				if(justThis.toMargin<0){
					justThis.setStyle('margin-left', margin - Math.PI * justThis.stepLength * (justThis.endPosition + margin) / justThis.toMargin);
				}else{
					justThis.setStyle('margin-left', margin - Math.PI * justThis.stepLength * (justThis.endPosition + margin) / justThis.toMargin);
				}
				if((justThis.toMargin < 0 && margin <= -justThis.endPosition + 1)
						|| (justThis.toMargin > 0 && margin >= -justThis.endPosition - 1)){
					justThis.setStyle('margin-left', -justThis.endPosition);
					justThis.clear();
				}
				
			}, 100);
		}
		var slidePic = this.slidePics[this.currentIndex];
		if(slidePic!=null){
			slidePic.addClass('selected');
			this.displayPane.src=slidePic.getElements('img')[0].src;
			this.bigDisplayPane.href=slidePic.getElements('img')[0].src;
		}
	},
	scrollLeft:function(){
		if(this.previousIndex > 0){
			this.currentIndex = this.previousIndex - 1;
			this.slideShowList.scroll();
			this.previousIndex = this.currentIndex;
		}
		
	},
	scrollRight:function(){
		if(this.previousIndex < this.slidePics.length-1){
			this.currentIndex = this.previousIndex + 1;
			this.slideShowList.scroll();
			this.previousIndex = this.currentIndex;
		}
	},
	scrollTo:function(targetIndex){
		if(targetIndex>this.previousIndex || ( targetIndex > -1 && targetIndex < this.previousIndex)){
			this.currentIndex = targetIndex;
			this.slideShowList.scroll();
			this.previousIndex = this.currentIndex;
		}
	}
});

var ScrollGateControl = new Class({
	initialize:function(tabPane, handlers, screens){
		this.tabPane = tabPane;
		this.handlers = handlers;
		this.screens = screens;
		this.bindTabEvents();
	},
	bindTabEvents:function(){
		this.tabs = this.tabPane.getElements("a");
		this.current = 1;
		for(var i=0; i<this.tabs.length; i++){
			this.tabs[i].number = i+1;
			this.tabs[i].control=this;
			this.tabs[i][this.handlers[i]]=this.scroll;
		}
	},
	scroll:function(){
		if(this.control.current!=this.number){
			this.control.tabs[this.control.current-1].className="";
			this.control.screens[this.control.current-1].style.display="none";
			this.control.current=this.number;
			this.control.tabs[this.control.current-1].className="choosed";
			this.control.screens[this.control.current-1].style.display="";
		}
		this.blur();
	}
});

var Scroller = new Class({
	options: {
		velocity: 1
	},
	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element);
		this.lastPage = null;
		this.coord = this.getCoords.bindWithEvent(this);
		this.release = this.release.bindWithEvent(this);					
		this.mouseover = ([window, document].contains(element)) ? $(document.body) : this.element;					
		this.element.addEvent('mousedown', function(e) {
			if(this.element && e.target) {
				if(this.element.tagName == e.target.tagName) {
					this.reset.bind(this)(e);
					document.addListener('mousemove', this.coord);
					document.addListener('mouseup', this.release);
				}
			}			
		}.bind(this));
		this.element.scrollTo(0, 0);
	},	
	getCoords: function(event){
		event = new Event(event);
		this.page = (this.element == window) ? event.client : event.page;
		if(this.lastPage == null){			
			this.lastPage = this.page;
		}
		var scroll = this.element.getScroll();
		var change = {x: 0, y: 0};
		for (var z in this.page){
			change[z] = (this.page[z] - this.lastPage[z]) * this.options.velocity;
		}
		this.element.scrollTo(scroll.x - change.x, scroll.y - change.y)
		this.lastPage = this.page;	
	},
	release: function() {
		document.removeListener('mousemove', this.coord);
		document.removeListener('mouseup', this.release);
	},
	reset: function(event) {
		this.lastPage = (this.element == window) ? event.client : event.page;
	}
});

Scroller.implement(new Events, new Options);
