var ScrollWindow = (function(){
	function constructor(obj,nav,width,count){
		this.obj = obj;
		this.nav = nav;
		this.yTween;
		this.aTween;
		this.cTween;
		this.pTween;
		this.width = width;
		this.count = count;
		this.currentStep = 1;
	}
	
	constructor.prototype.init = function(){

		h=document.documentElement.firstChild;
		h.appendChild(c=document.createElement('link')).setAttribute('href',"/css/"+this.obj.id+".css");
		c.setAttribute('rel','stylesheet');

		var topNavElements = this.nav.getElementsByTagName('a');
		topNavElements[0].style.color = "#233f90";
		for(var q=0;q<topNavElements.length;q++){
			topNavElements[q].controller = this;
			topNavElements[q].num = q+1;
			topNavElements[q].onclick = function(){
				this.controller.scroll(this.num-this.controller.currentStep);
				return false;
			}
		}
		var li = this.obj.getElementsByTagName('li');
		for(var k=0;k<li.length;k++){
			if(li[k].className.toLowerCase().indexOf("control-back") != -1){
				li[k].controller = this;
				li[k].onclick = function(){
					this.controller.scroll(-1);
				}
			} else if(li[k].className.toLowerCase().indexOf("control-next") != -1){
				li[k].controller = this;
				li[k].onclick = function(){
					this.controller.scroll(1);
				}
			}
		}
	}
	constructor.prototype.scroll = function(d){
		var currentPos = Number(this.obj.style.right.match(/\d+/));
		if((currentPos == 0 && d == -1) || (currentPos == this.width*(this.count-1) && d == 1) || (this.yTween && this.yTween.playing) || d == 0){
			return false;
		}
		this.pTween = new Tween(this.nav.getElementsByTagName('a')[this.currentStep-1],"color",0x233f90,0x6197CF,150,"","#","easeSinColor");
		this.currentStep += d;
		var pos = d*this.width+currentPos;
		this.yTween = new Tween(this.obj,"right",currentPos,pos,150,'px','',"easeSin");
		//this.aTween = new Tween(this.nav,"backgroundPosition",currentPos/this.count,pos/this.count,150,'px 1px','',"easeSin");
		this.cTween = new Tween(this.nav.getElementsByTagName('a')[this.currentStep-1],"color",0x6197CF,0x233f90,150,"","#","easeSinColor");
		this.pTween.play();
		this.yTween.play();
	//	this.aTween.play();
		this.cTween.play();
	}
	return constructor;
})();