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


var viewportwidth;
var viewportheight;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined')
{
  viewportwidth = window.innerWidth-38;
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth != 'undefined' 
	  && document.documentElement.clientWidth != 0)
{
   viewportwidth = document.documentElement.clientWidth-20;
}

// older versions of IE

else
{
   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
}

$(window).scroll(function () {
	var cart = $("#cartHolder");
	if(document.documentElement.scrollTop >= 110 || window.pageYOffset >= 110){ 
		cart.css('position', 'fixed')
		cart.css('top', '15px')
		cart.css('right', ((viewportwidth - 880)/2) + "px" )
	}
	else {
		cart.css('position', 'absolute');
		cart.css('top', '20px')
		cart.css('right', '-30px')
	}
});


function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

var id = 1;


function slideRight(){
	var panelCount = parseInt(document.getElementById("panelCount").value);
	$('#panel' + id).animate({left: '-880'}, {duration: 300});		
	document.getElementById("panelNav" + id).className = "";
	if(id + 1 <= panelCount){		
		document.getElementById("panel" + (id + 1)).style.left = "880px";		
		document.getElementById("panelNav" + (id + 1)).className = "active";
		$('#panel' + ( id +1 )).animate({left: '0'}, {duration: 300});	
		id++;
	}else{
		document.getElementById("panel" + 1).style.left = "880px";		
		document.getElementById("panelNav" + 1).className = "active";
		$('#panel' + 1).animate({left: '0'}, {duration: 300});	
		id = 1;
	}
}

function slideLeft(){
	var panelCount = parseInt(document.getElementById("panelCount").value);
	$('#panel' + id ).animate({left: '880'}, {duration: 300});	
	document.getElementById("panelNav" + id).className = "";		
	if(id - 1 >= 1){
		document.getElementById("panel" + (id - 1)).style.left = "-880px";
		document.getElementById("panelNav" + (id - 1)).className = "active";
		$('#panel' + ( id - 1)).animate({left: '0'}, {duration: 300});		
		id--;
	}else{
		document.getElementById("panel" + panelCount).style.left = "-880px";		
		document.getElementById("panelNav" + panelCount).className = "active";
		$('#panel' + panelCount).animate({left: '0'}, {duration: 300});		
		id = panelCount;
	}
}
function gotoAndPlay(newId){
	if(id < newId){
		$('#panel' + id).animate({		
		left: '-880'
		}, {duration: 300});
		
		document.getElementById("panel" + newId).style.Left = "880px";
		$('#panel' + newId).animate({		
		left: '0'
		}, {duration: 300});
	}
	if(id > newId){
		$('#panel' + id).animate({		
		left: '880'
		}, {duration: 300});		
		
		document.getElementById("panel" + newId).style.Left = "-880px";
		$('#panel' + newId).animate({		
		left: '0'
		}, {duration: 300});
	}			
	document.getElementById("panelNav" + id).className = "";
	document.getElementById("panelNav" + newId).className = "active";
	id = newId;
}

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

function showPhoto(id){	
	document.getElementById("photo" + prevPhotoId).style.display = "none";
	document.getElementById("photo" + id).style.display = "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;
}

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

function readURL(){
	if(location.hash != ""){hash = location.hash;}else{ hash = "#1";}
 	showPhoto(hash.substr(1,10));
}

