var aanbieding_speed = 10;		/* Speed of the aanbiedingen slideshow in seconds */

$(document).ready(function(){
	$(function(){
		 $('.auto-submit-star').rating({
		  callback: function(value, link){
		   // 'this' is the hidden form element holding the current value
		   // 'value' is the value selected
		   // 'element' points to the link element that received the click.
		     
		      var xmlHttp;
			  try
				{       xmlHttp=new XMLHttpRequest();    }
			  catch (e)
				{     try
				  {      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }
				catch (e)
				  {      try
					{        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        }
				  catch (e)
					{        alert("Your browser does not support AJAX!");        return false;        }      }    }
				xmlHttp.onreadystatechange=function()
				  {
				  if(xmlHttp.readyState==4)
					{
						alert(xmlHttp.responseText);
					}
				  }
				  
				var random = Math.round( Math.random() * 100 );
				  
				xmlHttp.open("GET","/includes/handleRating.php?acco="+accomodation_id+"&nr="+value+"&ip="+ip_address+"&random="+random,true);
				xmlHttp.send(null);
		   // To submit the form automatically:
		   //this.form.submit();
		   // To submit the form via ajax:
		   //$(this.form).ajaxSubmit();
		  }
		 });
	 
	 
		$('.handle_review_algemeen').rating({ });
		$('.handle_review_ligging').rating({ });
		$('.handle_review_prijs').rating({ });
		$('.handle_review_kamer').rating({ });
		$('.handle_review_plaats').rating({ });
		$('.handle_review_piste').rating({ });
	 
		$('.review_algemeen').rating({ });
		$('.review_ligging').rating({ });
		$('.review_prijs').rating({ });
		$('.review_kamer').rating({ });
		$('.review_plaats').rating({ });
		$('.review_piste').rating({ });
	});
	
	if ($(".acco_foto").length > 0)
		$(".acco_foto").fancybox();
	
	initAanbiedingen();
	
	handleDescription();
	
	if ($("#detail-prijzen").length > 0)
	{
		$("#detail-prijzen").designTable({
			oddClass : 'odd'
		});
	}
});

var speed = aanbieding_speed * 1000;
var stopped = false;
function initAanbiedingen() {
	$("#aanbiedingen-box .aanbieding").hide();
	$("#aanbiedingen-box .aanbieding:first").show();
	
	$("#aanbiedingen-box .aanbieding").css({
		'position' : 'absolute',
		'left' : '0px',
		'top' : '0px'
	});
	
	window.setTimeout(function(){ nextAanbieding(2) } , speed);
	
}

function nextAanbieding(nr, start) {

	if (start) stopped = false;

	if (!stopped)
	{
		var cur = nr - 1;
		$("#aanbiedingen-box .aanbieding:nth-child("+ cur +")").fadeOut("slow", function(){
			$("#aanbiedingen-box .aanbieding:nth-child("+ nr +")").fadeIn("slow");
		});
		
		var total = $("#aanbiedingen-box .aanbieding").length;
		
		if (total < nr) nr = 1;
		
		var next = nr + 1;		
		
		window.setTimeout(function(){ nextAanbieding(next) } , speed);
	}
}

function handleDescription(){
	var real_height = $("#omschrijving-box").height();
	$("#omschrijving-box").height("125px");
	$("#omschrijving-box").css({
		'overflow' : 'hidden'
	});
	
	$("#omschrijving-read-more").click(function(e){
		e.preventDefault();
		$("#omschrijving-box").animate({
			height: real_height
		},
		500);
	});
	
}

