// horizontal image scroller
// items visible when scroller does not move
var itemsshown=4;
// width of each item within the scroller
var myitem=137;
// amount of items to be scrolled when moved
var scrollby=4;
// choose to switch carousel on (true) of off (false)
var carousel=true;
// choose speed of carousel
var carspeed=5000;
// choose step speed of carousel
var step=5;

var oid=0;
function showContent(id) {
	window.open(myLinks[id])
	oid=id;
}
var myDivs=new Array();var myThumbs=new Array();var myItems=new Array();var contentnr=0;
function getContent() {
	if (document.getElementById('ainner')) {
		myDivs=document.getElementById('ainner').getElementsByTagName("div");		
		contentnr=myDivs.length;
		for(var i=0; i<contentnr; i++) {		
			if (myDivs[i].className=="athumb") { myThumbs.push(myDivs[i]); }
		}	
		var stopit2=myThumbs.length;
		for(var j=0; j<stopit2; j++) {		
			myThumbs[j].nr = j;
			myThumbs[j].onclick=function() { showContent(this.nr); }		
		}
		if (myThumbs.length > itemsshown) {
			for(var k=0; k<itemsshown; k++) { 
				var y=myThumbs[k].cloneNode(true);
				document.getElementById('ainner').appendChild(y);
				myThumbs.push(y);
			}		
			var dubbels=(stopit2+itemsshown);var x=0;	
			for(var h=stopit2; h<dubbels; h++) {					
				myThumbs[h].nr = x;
				myThumbs[h].onclick=function() { showContent(this.nr); }	
				x=x+1;
			}
		}
		moveinplace();
	}
}
var scrollnr;var mybox;var myleft;var theleft;var timer;var trgt;var busy=false;var waiting;var strt=true;
function moveinplace() {
	scrollnr=(scrollby*myitem);
	if (document.getElementById('ainner')) {
		document.getElementById('ainner').style.left='0px';
		var i=myThumbs;
		mybox=-(((i.length-1)*myitem)-(itemsshown*myitem));
		var actlft=0;
		for (x=0;x<i.length;x++) {
			if (i[x].className=='active') { actlft=-(x*myitem);	}
		}
		if (actlft>-(myitem*itemsshown)) {
			document.getElementById('ainner').style.left=actlft+'px'; 
		} else { document.getElementById('ainner').style.left=-(myitem*itemsshown)+'px'; }
		myleft=document.getElementById('ainner').style.left;
		theleft=parseInt(myleft);
		showButtons(theleft);		
		// deals with automatic scrolling
		if (carousel==true && strt==false) { waiting=setTimeout("moveOn()",1); }
		if (carousel==true && strt==true) { strt=false;waiting=setTimeout("moveOn()",carspeed); }
		if (carousel==true) { 
			document.getElementById('ainner').onmouseover=function() { carousel=false;clearTimeout(waiting); }
			document.getElementById('ainner').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); } 
			document.getElementById('anxt').onmouseover=function() { carousel=false;clearTimeout(waiting); }
			document.getElementById('anxt').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
			document.getElementById('aprv').onmouseover=function() { carousel=false;clearTimeout(waiting); }
			document.getElementById('aprv').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
		}		
	}
}
function moveOn() {	
	trgt=theleft-scrollnr;
	if (trgt>=mybox && busy==false) { timer=setInterval("moveLeft("+trgt+");",5);busy=true; }
	else if (busy==false) { 
		var lastitems=(mybox+(-theleft))/myitem;
		if (lastitems<=0) { 
			scrollnr=-((lastitems*myitem)-myitem);
			trgt=theleft-scrollnr;
			timer=setInterval("moveLeft("+trgt+");",5);
			busy=true; 
		} else { moveinplace();	if (carousel==false) { moveOn(); }	}		 
	}
}
function moveLeft(trgt) {
	if (theleft>trgt) {	theleft=theleft-step; document.getElementById('ainner').style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft<trgt){ document.getElementById('ainner').style.left=(trgt+'px');theleft=trgt; }
		showButtons(theleft);
		busy=false;
		if (carousel==true) { waiting=setTimeout("moveOn()",carspeed); }
	}	
}
function moveBack() {		
	var startpoint=mybox;	
	if (theleft==0) { theleft=(startpoint-myitem);document.getElementById('ainner').style.left=(startpoint+'px'); }
	trgt=theleft+scrollnr;
	if (trgt<0 && busy==false) { timer=setInterval("moveRight("+trgt+");",5);busy=true; }
	else if (busy==false) { 
		var lastitems=theleft/myitem;
		if (lastitems<0) { 
			scrollnr=-(lastitems*myitem);
			trgt=theleft+scrollnr;
			timer=setInterval("moveRight("+trgt+");",5);
			busy=true; 
		} else { moveinplace();moveBack(); }		 
	}
}
function moveRight(trgt) {
	if (theleft<trgt) {	theleft=theleft+step; document.getElementById('ainner').style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft>trgt){ document.getElementById('ainner').style.left=(trgt+'px');theleft=trgt; }
		showButtons(theleft);
		scrollnr=(scrollby*myitem);
		busy=false; 
	}	
}
function showButtons(theleft) {
	if (mybox<0) { 
		if (document.getElementById('anxt')) { 
			document.getElementById('anxt').style.backgroundImage='url(/images/scroll_next.gif)';
			document.getElementById('anxt').style.cursor='pointer'; 
		}
		if (document.getElementById('aprv')) { 
			document.getElementById('aprv').style.backgroundImage='url(/images/scroll_prev.gif)';
			document.getElementById('aprv').style.cursor='pointer'; 
		}
	}
}

function initScroller() {
	initAll();
	getContent();
}

//onload=initScroller;
