/* 
Quick port of Adobe Flash Tween class
Requires easing_equations.js

Author: Sergey Chikuyonok (gonarch@design.ru)
17.09.2006
*/ 

function Tween(elemTarget, sStyleProperty, oEaseType, iStartValue, iEndValue, iDuration){
	this.target=elemTarget;
	this.time=0;
	this.duration=iDuration;
	this.position=iStartValue;
	this.finish=parseFloat(iEndValue);
	
	/* private properties */
	this._style=elemTarget.style;
	this._prop=sStyleProperty;
	this._ease=oEaseType;
	this._start=parseFloat(iStartValue);
	this._change=this.finish - this._start;
	this._animate=false;
	
	this.start();
}

Tween.aStack=[];
Tween._poll=function(){
	for(var i=0; i<this.aStack.length; i++){
		this.aStack[i]._onMotion();
	}
}

Tween._add=function(obj){
	this.aStack[this.aStack.length]=obj;
}

Tween._remove=function(obj){
	for(var i=0; i < this.aStack.length; i++){
		if(this.aStack[i] == obj){
			this.aStack.splice(i,1);
			break;
		}
	}
}

Tween._inStack=function(obj){
	for(var i=0; i<this.aStack.length; i++){
		if(this.aStack[i] == obj)
			return true;
	}
	return false;
}

Tween.prototype._onMotion=function(){
	if(this._animate){
		if(this.time < this.duration){
			this.time++;
			this.position=this._ease(this.time, this._start, this._change, this.duration, 50, 1.06);
			if(this._prop)
				this._style[this._prop]=this.position;
			this.onMotionChanged();
		}
		else{
			this.onMotionFinished();
			this.stop();
		}
	}
}

Tween.prototype.onMotionChanged=function(){
	return;
}

Tween.prototype.onMotionFinished=function(){
	return;
}

Tween.prototype.start=function(){
	if(!this._animate){
		this._animate=true;
		this.time=0;
		if(!this.constructor._inStack(this)){
			this.constructor._add(this);
		}
	}
}

Tween.prototype.stop=function(){
	this._animate=false;
	this.constructor._remove(this);
}

Tween.prototype.resume=function(){
	this._animate=true;
	if(!this.constructor._inStack(this))
		this.constructor._add(this);
}

setInterval('Tween._poll()', 22);

/**
 * @author gonarch
 */

var elemContainer, elemPageConatiner;
var oTween;

function NextPage(){
	GoToPage(iCurrentPage+1);
}

function PrevPage(){
	GoToPage(iCurrentPage-1);
}


function GoToPage(iPage){
	if(iPage > 0 && iPage <= iTotalPages && iCurrentPage != iPage){
		if(oTween) oTween.stop();
		
		oTween=new Tween(elemPageConatiner, 'left', Math.easeInOutCubic, elemPageConatiner.offsetLeft, -elemContainer.offsetWidth*(iPage-1), 30);
		oTween.prc=-100*(iPage-1);
		oTween.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage=iPage;
	if(iCurrentPage<=iTotalPages){
		for(var i=1; i<=iTotalPages; i++){
			var pNav = document.getElementById('p'+i);
			pNav.className = (i!=iCurrentPage) ? 'link' : 'select';
		}
	}

	}
}



/**
 * @author Leshich
 */

var elemContainer1, elemPageConatiner1;
var oTween1;

function NextPage1(){
	GoToPage1(iCurrentPage+1);
}

function PrevPage1(){
	GoToPage1(iCurrentPage-1);
}


function GoToPage1(iPage){
	if(iPage > 0 && iPage <= iTotalPages1 && iCurrentPage1 != iPage){
		if(oTween1) oTween1.stop();
		
		oTween1=new Tween(elemPageConatiner1, 'left', Math.easeOutElastic, elemPageConatiner1.offsetLeft, -elemContainer1.offsetWidth*(iPage-1), 30);
		oTween1.prc=-100*(iPage-1);
		oTween1.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage1=iPage;
	if(iCurrentPage1<=iTotalPages1){
		for(var i=1; i<=iTotalPages1; i++){
			var pNav = document.getElementById('b'+i);
			pNav.className = (i!=iCurrentPage1) ? 'link' : 'select';
		}
	}
  }
}




var elemContainer2, elemPageConatiner2;
var oTween2;

function NextPage2(){
	GoToPage2(iCurrentPage+1);
}

function PrevPage2(){
	GoToPage2(iCurrentPage-1);
}


function GoToPage2(iPage){
	if(iPage > 0 && iPage <= iTotalPages2 && iCurrentPage2 != iPage){
		if(oTween2) oTween2.stop();
		
		oTween2=new Tween(elemPageConatiner2, 'left', Math.easeOutElastic, elemPageConatiner2.offsetLeft, -elemContainer2.offsetWidth*(iPage-1), 30);
		oTween2.prc=-100*(iPage-1);
		oTween2.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage2=iPage;
	if(iCurrentPage2<=iTotalPages2){
		for(var i=1; i<=iTotalPages2; i++){
			var pNav = document.getElementById('c'+i);
			pNav.className = (i!=iCurrentPage2) ? 'link' : 'select';
		}
	}
  }
}




var elemContainer3, elemPageConatiner3;
var oTween3;

function NextPage3(){
	GoToPage3(iCurrentPage+1);
}

function PrevPage3(){
	GoToPage3(iCurrentPage-1);
}


function GoToPage3(iPage){
	if(iPage > 0 && iPage <= iTotalPages3 && iCurrentPage3 != iPage){
		if(oTween3) oTween3.stop();
		
		oTween3=new Tween(elemPageConatiner3, 'left', Math.easeOutElastic, elemPageConatiner3.offsetLeft, -elemContainer3.offsetWidth*(iPage-1), 30);
		oTween3.prc=-100*(iPage-1);
		oTween3.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage3=iPage;
	if(iCurrentPage3<=iTotalPages3){
		for(var i=1; i<=iTotalPages3; i++){
			var pNav = document.getElementById('d'+i);
			pNav.className = (i!=iCurrentPage3) ? 'link' : 'select';
		}
	}
  }
}





var elemContainer4, elemPageConatiner4;
var oTween4;

function NextPage4(){
	GoToPage4(iCurrentPage+1);
}

function PrevPage4(){
	GoToPage4(iCurrentPage-1);
}


function GoToPage4(iPage){
	if(iPage > 0 && iPage <= iTotalPages4 && iCurrentPage4 != iPage){
		if(oTween4) oTween4.stop();
		
		oTween4=new Tween(elemPageConatiner4, 'left', Math.easeOutElastic, elemPageConatiner4.offsetLeft, -elemContainer4.offsetWidth*(iPage-1), 30);
		oTween4.prc=-100*(iPage-1);
		oTween4.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage4=iPage;
	if(iCurrentPage4<=iTotalPages4){
		for(var i=1; i<=iTotalPages4; i++){
			var pNav = document.getElementById('e'+i);
			pNav.className = (i!=iCurrentPage4) ? 'link' : 'select';
		}
	}
  }
}




/**
 * for actions
 */
var elemContainer_act, elemPageConatiner_act;
var oTween_act;

function NextPage_act(){
	GoToPage_act(iCurrentPage_act+1);
}

function PrevPage_act(){
	GoToPage_act(iCurrentPage_act-1);
}


function GoToPage_act(iPage){
	if(iPage > 0 && iPage <= iTotalPages_act && iCurrentPage_act != iPage){
		if(oTween_act) oTween_act.stop();
		
		oTween_act=new Tween(elemPageConatiner_act, 'left', Math.easeInOutQuad, elemPageConatiner_act.offsetLeft, -elemContainer_act.offsetWidth*(iPage-1), 30);
		oTween_act.prc=-100*(iPage-1);
		oTween_act.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage_act=iPage;
	if(iCurrentPage_act==1){
			var pNav = document.getElementById('s1');
			pNav.className = 'select';
			var pNav = document.getElementById('s2');
			pNav.className = 'link';
	}else{	var pNav = document.getElementById('s1');
			pNav.className = 'link';}
	if(iCurrentPage_act==iTotalPages_act){
			var pNav = document.getElementById('s2');
			pNav.className = 'select';
			var pNav = document.getElementById('s1');
			pNav.className = 'link';
	}else{	var pNav = document.getElementById('s2');
			pNav.className = 'link';}			
//	if(iCurrentPage_act<=iTotalPages_act){
//		for(var i=1; i<=iTotalPages_act; i++){
//			var pNav = document.getElementById('s'+i);
//			pNav.className = (i!=iCurrentPage_act) ? 'link' : 'select';
//		}
//	}

	}
}

function NextPage_act_short(){
	GoToPage_act(iCurrentPage_act+1);
}

function PrevPage_act_short(){
	GoToPage_act(iCurrentPage_act-1);
}


function GoToPage_act_short(iPage){
	if(iPage > 0 && iPage <= iTotalPages_act && iCurrentPage_act != iPage){
		if(oTween_act) oTween_act.stop();
		
		oTween_act=new Tween(elemPageConatiner_act, 'left', Math.easeInOutQuad, elemPageConatiner_act.offsetLeft, -elemContainer_act.offsetWidth*(iPage-1), 30);
		oTween_act.prc=-100*(iPage-1);
		oTween_act.onMotionFinished=function(){
			this.target.style.left=this.prc+'%';

		}
		iCurrentPage_act=iPage;
	if(iCurrentPage_act==1){
			var pNav = document.getElementById('s1');
			pNav.className = 'select';
			var pNav = document.getElementById('s2');
			pNav.className = 'link';
	}else{	var pNav = document.getElementById('s1');
			pNav.className = 'link';}
	if(iCurrentPage_act==iTotalPages_act){
			var pNav = document.getElementById('s2');
			pNav.className = 'select';
			var pNav = document.getElementById('s1');
			pNav.className = 'link';
	}else{	var pNav = document.getElementById('s2');
			pNav.className = 'link';}	
//	if(iCurrentPage_ac<=iTotalPages_act){
//		for(var i=1; i<=iTotalPages_act; i++){
//			var pNav = document.getElementById('s'+i);
//			pNav.className = (i!=iCurrentPage_act) ? 'link' : 'select';
//		}
//	}

	}
}