
	
	
// The Ajax to PHP function
function doAjax(actionID, queryString, returnID, doFunctie) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	//var host	= 'http://production.jungleminds.nl/';
	var host	= 'http://www.jungleminds.nl/';
	
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if (ajaxRequest.readyState == 4){
			//if (actionID == 'rate') {
			//	rateResponse(4);
			//}		
			if (ajaxRequest.responseText && returnID){
				if (doFunctie)
					setTimeout(doFunctie, 0);
				
				document.getElementById(returnID).innerHTML = ajaxRequest.responseText;
			}
			
		}
	}
	
	ajaxRequest.open('GET', host + 'ajax.php?actionID=' + actionID + '&' + queryString, true);
	ajaxRequest.send(null);
	
	return false;
}

	
function openWindow(naarPagina, width, height, location)
{
	if (!width)
		width		= 650;
	
	if (!height)
		height		= 580;
	
	if (!location)
		location	= 1;
	
	w = window.open(naarPagina, '', 'top=0,left=0,width=' + width + ',height=' + height + ',location=' + location + ',status=0,menubar=1,directories=0,toolbar=0,resizable=0,scrollbars=1');
	w.focus();
	
	return false;
}
	
		
	// STARSOVER
	function starsOver(starID, totalScore, over)
	{
		var i;
		var starImg		= new Object();
		var imgRoot		= 'img/stars/';
		var starFile	= '';
		var checkScore	= 0;
		var fileExtend	= '';
		var beoordelingen		= new Array('Niks', 'Redelijk', 'OK', 'Goed', 'Top');
		
		if (over){
			fileExtend	= '_over';
		}else{
			var fileExtend	= '';		
		}
		
		for (i = 1; i <= starID; ++i){
			starImg 	= document.getElementById('star_' + i);
			
			if (starImg.src.indexOf('filled') > 0)
				starImg.src = imgRoot + 'star_filled' + fileExtend + '.gif';
			else
				starImg.src = imgRoot + 'star_empty' + fileExtend + '.gif';
		}
	
		document.getElementById('showRate').innerHTML = beoordelingen[starID-1];
	}
	
	// ANYTHING SLIDER ADVERT
	function rateResponse(ajResponse)
	{		
		var ajaxDisplay1		= document.getElementById('actionTitle');
		ajaxDisplay1.innerHTML	= 'Bedankt voor uw beoordeling';
	
	
		var i = 0;
		var starImg		= new Object();
		var imgRoot		= 'img/stars/';
		var starFile	= '';
		var beoordelingen		= new Array('Niks', 'Redelijk', 'OK', 'Goed', 'Top');
	
		
		for (i = 1; i <= ajResponse; i++){
			starImg 				= document.getElementById('star_' + i);
			starImg.src 			= imgRoot + 'star_filled.gif';
			starImg.onclick			= '';
			starImg.onmouseover		= '';
			starImg.onmouseout		= '';
			starImg.style.cursor	= 'auto';
			alert(starImg.src);
		}
		
		for (i; i < 6; i++){
			starImg 				= document.getElementById('star_' + i);
			starImg.src 			= imgRoot + 'star_empty.gif';
			starImg.onclick			= '';
			starImg.onmouseover		= '';
			starImg.onmouseout		= '';
			starImg.style.cursor	= 'auto';
			alert(starImg.src);
		}
	
		
		document.getElementById('showRate').innerHTML		= beoordelingen[ajResponse];
		document.getElementById('rateCount').innerHTML		= Number(document.getElementById('rateCount').innerHTML) + 1;
		document.getElementById('myrateCount').innerHTML	= '[Mijn beoordeling: ' + beoordelingen[ajResponse] +']';
	}


function toggleLayer( whichLayer ) {
	  var elem, vis;
	  if( document.getElementById ) // this is the way the standards work
	    elem = document.getElementById( whichLayer );
	  else if( document.all ) // this is the way old msie versions work
	      elem = document.all[whichLayer];
	  else if( document.layers ) // this is the way nn4 works
	    elem = document.layers[whichLayer];
	  vis = elem.style;
	  // if the style.display value is blank we try to figure it out here
	  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}



function reactieComment(id, title) 
{
	var targetInput = document.getElementById('type');
	var targetHeader = document.getElementById('reactionHeader');
	targetInput.value = id;
	targetHeader.innerHTML = 'Reactie op ' + title;
	targetHeader.style.display = 'block';
}

//Zorgt voor correcte afronding prijs in js. (lijkt op number_format() in php)
function priceFormat(bedrag)
{
	bedrag = Math.round(bedrag * 100) / 100;
	bedrag = String(bedrag);
	
	var bedragDecimals = new Array();
	bedragDecimals = bedrag.split('.');
	
	if (bedragDecimals.length == 2){
		switch (bedragDecimals[1].length){
			case 1:
				bedrag = bedrag + '0';
			break;
		}
	} else {
		bedrag = bedrag + '.00';
	}
	
	return bedrag;
}

//verander direct de prijs bij orderformulier
function changePrice(artID, verzendKosten)
{
	document.getElementById('subtot_' + artID).value = priceFormat(Number(document.getElementById('aantal_' + artID).value) * Number(document.getElementById('prijs_' + artID).innerHTML));
	document.getElementById('spantot_' + artID).innerHTML = document.getElementById('subtot_' + artID).value;
	
	if (document.getElementById('aantal_1')){
		document.getElementById('totaalbedrag').innerHTML = priceFormat(Number(document.getElementById('subtot_0').value) + Number(document.getElementById('subtot_1').value) + Number(verzendKosten));
		
		if (Number(document.getElementById('aantal_0').value) + Number(document.getElementById('aantal_1').value) == 0){
			if (artID == 1)
				artID = 0;
			else
				artID = 1;
			
			document.getElementById('aantal_' + artID).value = 1;
			
			document.getElementById('subtot_' + artID).value = priceFormat(Number(document.getElementById('aantal_' + artID).value) * Number(document.getElementById('prijs_' + artID).innerHTML));
			document.getElementById('spantot_' + artID).innerHTML = document.getElementById('subtot_' + artID).value;
			
			document.getElementById('totaalbedrag').innerHTML = priceFormat(Number(document.getElementById('subtot_0').value) + Number(document.getElementById('subtot_1').value) + Number(verzendKosten));
		}
	} else {
		document.getElementById('totaalbedrag').innerHTML = priceFormat(Number(document.getElementById('subtot_0').value) + Number(verzendKosten));
	}
}



$(document).ready(function(){ 

	$querystring = $(".query").attr("rel"); 
	// LOAD JM TWEETS
	$(".query").tweet({	  
	  join_text: "auto",
	  query: $querystring,	    
	  avatar_size: 28,
	  count: 5,         
	  loading_text: "bezig met laden..."
	});
	
	
// TABNAVIGATION FUNCTION FOR BOOKS
	$('#tabNavigation li').click(function() {		
		$('#tabNavigation li.active').removeClass().addClass('idle');
		if($(this).attr("id") == 'inhoudButton') {
			$('#resensieContent').hide();
			$('#videoContent').hide();
			$('#inhoudContent').show('fast');
			$(this).removeClass();
			$(this).addClass('active');		
		}else if($(this).attr("id") == 'resensieButton') {
			$('#videoContent').hide();
			$('#inhoudContent').hide();
			$('#resensieContent').show('fast');
			$(this).removeClass();
			$(this).addClass('active');
		}else if($(this).attr("id") == 'videoButton') {
			$('#inhoudContent').hide();
			$('#resensieContent').hide();
			$('#videoContent').show('fast');
			$(this).removeClass();
			$(this).addClass('active');
		}	
	});	
	
	
	
	

// CUSTOMER PAGE *Needs to be made dynamic!!!!*
	$('#customerCaseNav li:first').addClass('activeCustomer');		
	$('#customerCaseNav li').hover(function () {$(this).addClass("hover");},function () {$(this).removeClass("hover");});	
	$('#customerCaseNav li').click(function() {		
		$('.visibleCase').removeClass().addClass('hiddenCase');
		$('#customerCaseNav li').removeClass();		
		if($(this).attr("id") == 'caseButton1') {
			$('#klantCase1').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton2') {
			$('#klantCase2').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton3') {
			$('#klantCase3').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton4') {
			$('#klantCase4').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton5') {
			$('#klantCase5').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton6') {
			$('#klantCase6').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton7') {
			$('#klantCase7').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton8') {
			$('#klantCase8').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton9') {
			$('#klantCase9').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer');
		}else if($(this).attr("id") == 'caseButton10') {
			$('#klantCase10').removeClass().addClass('visibleCase');
			$(this).addClass('activeCustomer'); }	
	});	
	
	$('.customerCaseImgButton').click(function() {	
		$('html, body').animate({scrollTop:350}, 'fast'); 
		$('.visibleCase').removeClass().addClass('hiddenCase');
		$('#customerCaseNav li').removeClass();			
		if($(this).attr("id") == '#imgButton1') {
			$('#klantCase1').removeClass().addClass('visibleCase');
			$('#caseButton1').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton2') {
			$('#klantCase2').removeClass().addClass('visibleCase');
			$('#caseButton2').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton3') {
			$('#klantCase3').removeClass().addClass('visibleCase');
			$('#caseButton3').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton4') {
			$('#klantCase4').removeClass().addClass('visibleCase');
			$('#caseButton4').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton5') {
			$('#klantCase5').removeClass().addClass('visibleCase');
			$('#caseButton5').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton6') {
			$('#klantCase6').removeClass().addClass('visibleCase');
			$('#caseButton6').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton7') {
			$('#klantCase7').removeClass().addClass('visibleCase');
			$('#caseButton7').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton8') {
			$('#klantCase8').removeClass().addClass('visibleCase');
			$('#caseButton8').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton9') {
			$('#klantCase9').removeClass().addClass('visibleCase');
			$('#caseButton9').addClass('activeCustomer');
		}else if($(this).attr("id") == '#imgButton10') {
			$('#klantCase10').removeClass().addClass('visibleCase');
			$('#caseButton10').addClass('activeCustomer'); }
		
	});	
	
	$('#previousCase').hover(function () {$(this).css("background-position","0px 0px");},function () {$(this).css("background-position","0px -21px");});	
	$('#previousCase').click(function() {
		if ($('.visibleCase').attr("id") != 'klantCase1') {
			$('.visibleCase').removeClass().addClass('hiddenCase').prev().removeClass().addClass('visibleCase');
			$('.activeCustomer').removeClass().prev().addClass('activeCustomer');
		}
	});
	
	$('#nextCase').hover(function () {$(this).css("background-position","-108px 0px");},function () {$(this).css("background-position","-108px -21px");});	
	$('#nextCase').click(function() {
		if ($('.visibleCase').attr("id") != 'klantCase10') {
			$('.visibleCase').removeClass().addClass('hiddenCase').next().removeClass().addClass('visibleCase');
			$('.activeCustomer').removeClass().next().addClass('activeCustomer');		
		}
	});	
	
	
	
 // CUSTOMER SIDEBAR
	$('#customerWrapper div:not(:first, :last)').hide(); 
	$('#customerNav li:first').addClass('active');		
	$('#customerNav li').hover(function () {$(this).addClass("hover");},function () {$(this).removeClass("hover");});	
	$('#customerNav li').click(function() {		
		$('#customerWrapper div:not(:last)').hide();
		$('#customerNav li').removeClass();
		if($(this).attr("id") == 'customer1') {
			$('#case1').show('fast');
			$(this).addClass('active');
		}else if($(this).attr("id") == 'customer2') {
			$('#case2').show('fast');
			$(this).addClass('active');
		}else if($(this).attr("id") == 'customer3') {
			$('#case3').show('fast');
			$(this).addClass('active');
		}else if($(this).attr("id") == 'customer4') {
			$('#case4').show('fast');
			$(this).addClass('active');
		}else if($(this).attr("id") == 'customer5') {
			$('#case5').show('fast');
			$(this).addClass('active');
		}	
	});	
	
	
 // NAVIGATION DROPDOWN	
	$(function(){
		$("ul.navList li.dd").hover(function(){    
			$('a:first',this).addClass('mouseover');
			$('div:first',this).css('display', 'block');
		
		}, function(){
			$('a:first',this).removeClass('mouseover');
			$('div:first',this).css('display', 'none');	
		});	   
	});


 // YEAR SELECTOR DROPDOWN
	$(function(){
		$("div.yearFilterHolder").hover(function(){    
			$('ul:first',this).css('display', 'block');
			$('div:first',this).addClass('filterHover');
		
		}, function(){
			$('ul:first',this).css('display', 'none');
			$('div:first',this).removeClass('filterHover');
		});	   
	});
	

// AUTHOR SELECTOR DROPDOWN
	$(function(){
		$("div.authorFilterHolder").hover(function(){    
			$('ul:first',this).css('display', 'block');
			$('div:first',this).addClass('filterHover');
		
		}, function(){
			$('ul:first',this).css('display', 'none');
		 $('div:first',this).removeClass('filterHover');
		});	   
	});
	

	
// ANYTHING SLIDER ADVERT
	function formatText(index, panel) {return index + "";}	
	$(function () { 
		$('.advertSlider').anythingSlider({
			easing: "swing",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 6000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 800,            // How long the slide transition takes
			hashTags: false,                // Should links change the hashtag in the URL?
			buildNavigation: false,         // If true, builds and list of anchor links to link to each slide
			buildArrows: true,         // If true, builds and list of anchor links to link to each slide
			buildCurrent: false,    
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             	// Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});
	});


});
