/*************************************************************/
/*                                                           */
/*         JAVASCRIPT BY CHILLI DESIGN & MULTIMEDIA          */
/*                                                           */
/*           info@chilli.be  -  http://chilli.be             */
/*                                                           */
/*************************************************************/

/* dynamically split up the url and insert the country code */
function switchLanguage(lang) {
	u = location.href.split('/');
    u[3] = lang;
    location.href = u.join('/');
}

/* get phoyo ID and show the photo */
var prevPhotoId = 1;

/* get ID from #hash and pass to showPhoto() */
var step = 0;
var query = "all";

function showPhoto(id){	
	document.getElementById("photo" + prevPhotoId).style.display = "none";
	
	
	if(document.getElementById("photo" + id).firstChild.width != undefined){
		document.getElementById("photo" + id).style.display = "block";
		document.getElementById("photo" + id).style.width = parseInt(document.getElementById("photo" + id).firstChild.width) + 8;
	}else{
		document.getElementById("photo" + id).style.display = "inline-block";
	}
	
	document.getElementById("thumb" + prevPhotoId).className = "";
	document.getElementById("thumb" + id).className = "active";
	prevPhotoId = id;
	
	changeURL(id);
}

/* add a #hash to the url with the id */
function changeURL(id){
 	location.hash = id + "?" + query;
}


function readURL(){
	if(location.hash != ""){hash = location.hash;}else{ hash = "#1";}	
	isQuery = hash.indexOf("?");
	
	if(isQuery != 0){
		oldHash = hash;
		hash = hash.substr(0, isQuery);
		query = oldHash.substr(isQuery+1, 10);		
		if(query != "all" && query != ""){
			document.getElementById("backLink").href += query;
		}
	}
	//if(location.search != ""){query = location.search; alert(query);}	
 	showPhoto(hash.substr(1,10));
	var count = document.getElementById("count").innerHTML;		
	step = Math.floor((hash.substr(1,10)-1)/5);
	var myFx = new Fx.Tween("thumbs", {duration: 200});	
	myFx.start('left', '0', -(step*590));
	
}

var previ = 1;
var prevThumbId = 1;

function showThumb(i, id){
	if(document.getElementById("thumb_" + i + "_" + prevThumbId)){document.getElementById("thumb_" + i + "_" + prevThumbId).style.display = "none";}
	document.getElementById("thumb_" + i + "_" + id).style.display = "block";
	
	prevThumbId = id;
}

function showLogin(id){
	document.getElementById("iGolf").style.display = "block";
	document.getElementById("iGolf").style.visibility = "visible";
	$('#iGolf').animate({opacity: 1}, {duration: 300});
}
function closeLogin(id){	
	//document.getElementById("iGolf").style.visibility = "none";
	//document.getElementById("iGolf").style.opacity = 0;
	$('#iGolf').animate({opacity: 0}, {duration: 300, complete: function(){$(this).hide();}});
}

function goRight(){
	var count = document.getElementById("count").innerHTML;	
	if(step < (count/5)-1){
		step ++;
		var myFx = new Fx.Tween("thumbs", {duration: 200});	
		myFx.start('left', -((step-1)*590), -(step*590));
		
	}
}
function goLeft(){
	if(step > 0){
		step --;
		var myFx = new Fx.Tween("thumbs", {duration: 200});	
		myFx.start('left', -((step+1)*590), -(step*590));
	}
}

var brandboxid = 0;
function BrandBoxGoRight()
{
	
	var panelCount = parseInt(document.getElementById("panelCount").value);
	//alert ("brandboxid " + brandboxid + " panelCount " + Number(panelCount-1));
	
	if (Number(brandboxid) < Number(panelCount-1))
	{
		//var myFx = new Fx.Tween("panelHolder", {duration: 200});	
		brandboxid = brandboxid+1
		$('#panelHolder').animate({left: -650*brandboxid}, {duration: 300});
		
	//	myFx.start('left',0, -655*brandboxid);
		
	
	//	alert("niet gelijk");
		
	}
	else if (Number(brandboxid) == Number(panelCount-1))
	{
		//	alert("spring terug");
			var myElement = document.getElementById("panelHolder");
		//	var myFx = new Fx.Tween("panelHolder", {duration: 200});
			
			brandboxid = 0;
			$('#panelHolder').animate({left: 0}, {duration: 300});
		
			
			
		
	}
	
}

function initTimer()
{
	var t=setTimeout("slide()",5000);
	
}
			
	var fadeState="out";
	
	function slide()
	{
		
				var panelCount = parseInt(document.getElementById("panelCount").value);
				//alert ("brandboxid " + brandboxid + " panelCount " + Number(panelCount-1));
				//alert("slid");
				if (Number(brandboxid) < Number(panelCount-1))
				{	
					brandboxid = brandboxid+1
					$('#panelHolder').animate({left: -650*brandboxid}, {duration: 300});
				
				//	alert("niet gelijk");
					
				}
				else if (Number(brandboxid) == Number(panelCount-1))
				{
					//	alert("spring terug");
						brandboxid = 0;
						$('#panelHolder').animate({left: 0}, {duration: 300});
					
						
					
				}
		initTimer();
	}
			
			

function BrandBoxGoLeft()
{
	if (brandboxid != 0)
	{
		//var myFx = new Fx.Tween("panelHolder", {duration: 300});	
		//myFx.start('left',-655, 0);
		brandboxid = brandboxid-1
		$('#panelHolder').animate({left: -650*brandboxid}, {duration: 300});
		
	}
}

function gotoAndPlay(nummer)
{
	nummer = nummer-1;
	$('#panelHolder').animate({left: -655*nummer}, {duration: 300});
	brandboxid = nummer
}


function hideValue(){
	var check = document.getElementById("check").value;
	
	if(document.getElementById("email").value == check){
		document.getElementById("email").value = "";	
	}	
}
function showValue(){
	var check = document.getElementById("check").value;
	
	if(document.getElementById("email").value == ""){
		document.getElementById("email").value = check;	
	}	
}

  
