// horizontal image scroller
// items visible when scroller does not move
var itemsshown=1;
// width of each item within the scroller
var myitem=640;
var smyitem=330;
// amount of items to be scrolled when moved
var scrollby=1;
// choose to switch carousel on (true) of off (false)
var carousel=false;
var scarousel=true;
// choose speed of carousel
var carspeed=3000;
var scarspeed=3000;
// choose step speed of carousel
var step=20;
var sstep=10;

var oid=0;
function showContent(id) {
	window.open(myLinks[id]);
	oid=id;
}
var soid=0;
function sshowContent(id) {
	document.location=smyLinks[id];
	soid=id;
}
var myDivs=new Array();var myThumbs=new Array();var myItems=new Array();var contentnr=0;
function getContentBig() {
	if (document.getElementById('homeinnerbig')) {
	    myDivs = document.getElementById('homeinnerbig').getElementsByTagName("div");
		contentnr=myDivs.length;
		for(var i=0; i<contentnr; i++) {		
			if (myDivs[i].className=="thumb") { 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('homeinnerbig').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();
		if (myThumbs.length>0) { document.getElementById('nxtbig').style.display='block';document.getElementById('prvbig').style.display='block'; }
	}
}
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('homeinnerbig')) {
		document.getElementById('homeinnerbig').style.left='0px';
		var i=myThumbs;
		mybox=-(((i.length-1)*myitem)-(itemsshown*myitem));
		//document.getElementById('homeinnerbig').style.left=-(myitem*itemsshown)+'px';
		myleft=document.getElementById('homeinnerbig').style.left;
		theleft=parseInt(myleft);
		// deals with automatic scrolling
		if (myThumbs.length > 1) {
			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('homeinnerbig').onmouseover=function() { carousel=false;clearTimeout(waiting); }
				document.getElementById('homeinnerbig').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); } 			
			}
		}	
	}
}
function moveOn() {	
	document.getElementById('blurme').focus();
	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('homeinnerbig').style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft<trgt){ document.getElementById('homeinnerbig').style.left=(trgt+'px');theleft=trgt; }
		busy=false;
		if (carousel==true) { waiting=setTimeout("moveOn()",carspeed); }
	}	
}
// previous button/movement
function moveBack() {		
	document.getElementById('blurme').focus();
	var startpoint=mybox;	
	if (theleft==0) { theleft=(startpoint-myitem);document.getElementById('homeinnerbig').left=(startpoint-myitem+'px'); }
	trgt=theleft+scrollnr;
	if (trgt<0 && busy==false) { timer=setInterval("moveRight("+trgt+");",4);busy=true; }
	else if (busy==false) { 
		var lastitems=theleft/myitem;
		if (lastitems<0) { scrollnr=-(lastitems*myitem);trgt=theleft+scrollnr;timer=setInterval("moveRight("+trgt+");",4);	busy=true; } 
		else { moveinplace();moveBack(); }		 
	}
}
function moveRight(trgt) {
	if (theleft<trgt) {	theleft=theleft+step;document.getElementById('homeinnerbig').style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft>trgt){ document.getElementById('homeinnerbig').style.left=(trgt+'px');theleft=trgt; }
		scrollnr=(scrollby*myitem);	busy=false;
	}	
}

var smyDivs=new Array();var smyThumbs=new Array();var smyItems=new Array();var scontentnr=0;
function getContentSmall() {
	if (document.getElementById('homeinnersmall')) {
		smyDivs=document.getElementById('homeinnersmall').getElementsByTagName("div");		
		scontentnr=smyDivs.length;
		for(var i=0; i<scontentnr; i++) {		
			if (smyDivs[i].className=="thumb") { smyThumbs.push(smyDivs[i]); }
		}	
		var stopit2=smyThumbs.length;
		for(var j=0; j<stopit2; j++) {		
			smyThumbs[j].nr = j;
			smyThumbs[j].onclick=function() { sshowContent(this.nr); }		
		}
		if (smyThumbs.length > itemsshown) {
			for(var k=0; k<itemsshown; k++) { 
				var y=smyThumbs[k].cloneNode(true);
				document.getElementById('homeinnersmall').appendChild(y);
				smyThumbs.push(y);
			}		
			var dubbels=(stopit2+itemsshown);var x=0;	
			for(var h=stopit2; h<dubbels; h++) {					
				smyThumbs[h].nr = x;
				smyThumbs[h].onclick=function() { sshowContent(this.nr); }	
				x=x+1;
			}
		}
		if (smyThumbs.length > 1) {
			smoveinplace();
		}
	}
}
var sscrollnr;var smybox;var smyleft;var stheleft;var stimer;var strgt;var sbusy=false;var swaiting;var sstrt=true;
function smoveinplace() {
	sscrollnr=(scrollby*smyitem);
	if (document.getElementById('homeinnersmall')) {
		document.getElementById('homeinnersmall').style.left='0px';
		var i=smyThumbs;
		smybox=-(((i.length-1)*smyitem)-(itemsshown*smyitem));
		document.getElementById('homeinnersmall').style.left=-(smyitem*itemsshown)+'px';
		smyleft=document.getElementById('homeinnersmall').style.left;
		stheleft=parseInt(smyleft);
		// deals with automatic scrolling		
		if (scarousel==true && sstrt==false) { swaiting=setTimeout("smoveOn()",1); }
		if (scarousel==true && sstrt==true) { sstrt=false;swaiting=setTimeout("smoveOn()",scarspeed); }
		if (scarousel==true) { 
			document.getElementById('homeinnersmall').onmouseover=function() { scarousel=false;clearTimeout(swaiting); }
			document.getElementById('homeinnersmall').onmouseout=function() { scarousel=true;swaiting=setTimeout("smoveOn()",scarspeed); } 			
		}
	}
}
function smoveOn() {	
	strgt=stheleft-sscrollnr;
	if (strgt>=smybox && sbusy==false) { stimer=setInterval("smoveLeft("+strgt+");",5);sbusy=true; }
	else if (sbusy==false) { 
		var slastitems=(smybox+(-stheleft))/smyitem;
		if (slastitems<=0) { 
			sscrollnr=-((slastitems*smyitem)-smyitem);
			strgt=stheleft-sscrollnr;
			stimer=setInterval("smoveLeft("+strgt+");",5);
			sbusy=true; 
		} else { smoveinplace();	if (scarousel==false) { smoveOn(); }	}		 
	}
}
function smoveLeft(strgt) {
	if (stheleft>strgt) {	stheleft=stheleft-sstep; document.getElementById('homeinnersmall').style.left=(stheleft+'px');	} 
	else { 
		clearInterval(stimer); 
		if (stheleft<strgt){ document.getElementById('homeinnersmall').style.left=(strgt+'px');stheleft=strgt; }
		sbusy=false;
		if (carousel==true) { swaiting=setTimeout("smoveOn()",scarspeed); }
	}	
}
// foto viewer
var fotocount;var imgwidth;var endpoint;var fwaiting=false;
function fotoScroller() {
	fotocount = $("#fotoviewer330 .fotoholder img").length;		
	if (fotocount > 1) { 
		$("#fotoviewer330 .fotoholder div:first").clone().appendTo("#fotoviewer330 .fotoholder");
		fotocount=fotocount+1;
		imgwidth = $("#fotoviewer330 .fotoholder img:first").width();
		endpoint = ((imgwidth*-fotocount)+imgwidth)+"px";
		$("#fotoviewer330").mouseover(function() {
			clearTimeout(ftimer);fwaiting=true;
		});
		$("#fotoviewer330").mouseout(function() {
			ftimer=setTimeout('moveFoto()',1);fwaiting=false;
		});
		ftimer=setTimeout('moveFoto()',5000);		
	}
}
function moveFoto() {
	clearTimeout(ftimer);
	if (fwaiting==false) {
		if ($("#fotoviewer330 .fotoholder").css("left") == endpoint) { $("#fotoviewer330 .fotoholder").css("left","0px");	}
		$("#fotoviewer330 .fotoholder").animate({"left": "-="+imgwidth+"px"}, "slow");
		ftimer=setTimeout('moveFoto()',5000);
	}
}
$(document).ready(function() {		
	fotoScroller();
});