// catalogy/lib/slider.js v2.0
// CompuCity - compucity.com - compiled 26-Jun-2011
// copyright (c) usc (uk) ltd 2011

// horizontal + vertical carousel scroller
// requires some CSS, see individual projects
// for details

var slTxt=document.title,slTxtPause="(paused)";
var SL=[],SLX=-1,SLTAG='DIV'
function init_slides(Slides,Info,Start,Delay,Incr,T1,T2) {
	var X=++SLX
	SL[X]={div:ById(Slides),inf:ById(Info),start:Start,delay:Delay,inc:Incr,tmr1:T1,tmr2:T2,tmrx:0,tmrs:[],pause:false,ctr:2,last:1,max:0,width:0,dir:0,speed:'normal'}
	if (SL[X].start<0) {
		SL[X].start=-SL[X].start;
		SL[X].dir=1
	}

	if (SL[X].div) {
		var a,s=SL[X].div.getElementsByTagName(SLTAG)
		SL[X].max=s.length;SL[X].width=SL[X].dir==0?s[0].clientWidth:s[0].clientHeight
		for (x=0;x<s.length;x++) {
			a=s[x].getElementsByTagName('A');
			for(y=0;y<a.length;y++) with(a[y]){id='slax-'+X+'-'+x+'-'+y;onmouseover=slideapause;onmouseout=slideastart}
		}
		setTimeout("slide("+X+",2)",SL[X].start);
	}
}
function slideastart() {slidestart(this.id.split('-')[1])}
function slideapause() {slidepause(this.id.split('-')[1])}
function slideinfo(N,v) {v=v.replace(/%CTR%/gi,SL[N].ctr);if (SL[N].inf) SL[N].inf.innerHTML=v;document.title=v}
function slidestart(N) {if (SL[N].pause) {SL[N].pause=false;slideinfo(N,slTxt);slidegoto(N,1)}}
function slidepause(N) {if (!SL[N].pause) {SL[N].pause=true;slideinfo(N,slTxtPause);slideclear(N)}}
function slideclick(N) {if (SL[N].pause) slidestart(N); else slidepause(N)}
function slidepos(N,x) {if (SL[N].dir==1) SL[N].div.style.marginTop=x+'px'; else SL[N].div.style.marginLeft=x+'px'}
function slidegoto(N,x) {SL[N].speed='fast';slide(N,SL[N].ctr+x);SL[N].speed='normal'}
function slideclr(t) {if (t) clearTimeout(t);return null}
function slideclear(N) {for (var x=0;x<=SL[N].tmrx;x++) SL[N].tmrs[x]=slideclr(SL[N].tmrs[x])}
function slideset(N,x,y,speed) {SL[N].tmrs[y]=setTimeout('slidepos('+N+','+x+')',100+(y*speed));SL[N].tmrx=y}
function slide(N,V) {
	if (!SL[N].pause) {
	    var p1,p2,x,y=0,speed,W=-SL[N].width,L=SL[N].ctr;
	    slideclear(N);V=V>SL[N].max?1:V;V=V<1?SL[N].max:V
		p1=(L-1)*W;p2=(V-1)*W;SL[N].last=L;SL[N].ctr=V;speed=SL[N].speed=='normal'&&(L-V==1||L-V==-1)?SL[N].tmr1:SL[N].tmr2
	    if (p1>p2) for(x=p1;x>p2;x-=SL[N].inc) slideset(N,x,++y,speed)
		else for(x=p1;x<p2;x+=SL[N].inc) slideset(N,x,++y,speed)
		slideset(N,p2,++y,speed)
		SL[N].tmrs[0]=setTimeout("slide("+N+","+(V+1)+")",100+(++y*speed)+SL[N].delay)
	}
}
