﻿pAni={
ani: function(obj,from,to){
	if(from!='cur')pAni.cur=from;
	pAni.from=pAni.cur;
	pAni.obj=obj;
	pAni.to=to;
	pAni.applyProp(obj,'left',pAni.cur+'%');
	pAni.stop();
	pAni.timeStart=new Date();
	pAni.loop();
}
,from:0
,cur:0
,obj:null
,to:0
,handler:-1
,timeStart:0
,aniTime:400
,applyProp:function(obj,prop,value)
{
	if(prop=='left'){
		obj.style.left=value;
	}	
}
,loop:function(){
	var timeLeft=new Date()-pAni.timeStart;
	var oldCur=pAni.cur;
	if(timeLeft>=pAni.aniTime){
		pAni.applyProp(pAni.obj,'left',pAni.to+'%');
		pAni.cur=pAni.to;
		pAni.handler=-1;
	}else{
		var centerfar=Math.abs(timeLeft-(pAni.aniTime));
		var eas=(1-(centerfar/(pAni.aniTime)));
		var easValue=0.5+(eas*1);
		var movement=pAni.from+((pAni.to-pAni.from)*(timeLeft/pAni.aniTime));
		var step=movement-pAni.cur;
		step=Math.floor(step*easValue);
		if(step!=0){
			pAni.cur=pAni.cur+step;
			pAni.applyProp(pAni.obj,'left',pAni.cur+'%');
		}
		pAni.handler=setTimeout('pAni.loop()',10);
	}
}
,stop:function(){
	if(pAni.handler!=-1)clearTimeout(pAni.handler);
}
}

var maxslide=6;
var csl=1;
function goSlide(aid){
var mpl=aid;
hC(mpl*-100);
document.getElementById('spc').innerHTML=aid;
document.getElementById('spa').innerHTML=maxslide;
}

function hC(topos){
pAni.ani(document.getElementById('cont'),'cur',topos);
}

pAni.applyProp(document.getElementById('cont'),'left',0);
pAni.cur=0;
goSlide(1);

function goNext()
{
if(csl==maxslide)csl=0;
csl++;
goSlide(csl);
}
function goPrev()
{
if(csl==1)csl=maxslide+1;
csl--;
goSlide(csl);
}

function goFirst(){
csl=1;
goSlide(csl);
}

function goLast(){
csl=maxslide;
goSlide(csl);
}

var slideT=-1;
function startSlide(){
if(slideT==-1)slideT=setInterval('goNext()',6000);
}
function stopSlide(){
if(slideT!=-1)clearInterval(slideT);slideT=-1;
}
startSlide();