//Elenco a Discesa

$(document).ready(function(){
	$('ul#menu').superfish({ 
		delay: 100,//Ritardo
		animation: {opacity:0.95,height:'show'},
		autoArrows: false,// disabilito le frecce
		dropShadows: false,// disabilito l'ombreggiatura
		speed: "fast"
	});
	
	try{
		//Adattamento Menù superiore
		var mH = $("#menu").width();
		var tW = 0;
		var n = 0;
		$("#menu").children("li").each(function(index){
			tW = tW+$(this).width();
			n = n+1;
		});
		if(tW<(mH-n)){
			var StW = Math.floor((mH-tW)/n);
			$("#menu").children("li").each(function(index){
				var NewW = $(this).width()+StW;
				$(this).width(NewW);
			});
		}
		
		//Adattamento Caratteristiche Scheda
		var fH = $("#features").width();
		var fW = 0;
		$("#features div p").each(function(index){
			if($("#features").height()>36){//se c'è qualcosa che va su due righe
				$(this).css("max-width","128px");
			}
		});
		$("#features").children("div.feature").each(function(index){
			fW = fW+$(this).width();
		});
		if(fW<(fH-4)){
			var SfW = Math.ceil((fH-fW)/4)-6;
			$("#features").children("div.feature").each(function(index){
				var NewF = $(this).width()+SfW;
				$(this).width(NewF);
			});
		}
		//Troncamento testo degli elementi-small
		$(".elemento-text").each(function(){
			var troncato = $(this).html().substring(0,100);
			$(this).html(troncato+"...");
		});
	}catch(e){}
	
	try{//TABS scheda
		$("#tabs").tabs();
		$("#tabs > #tabs-1").find("p").each(function(index){
		if($(this).html()==""){
			$(this).remove();
		}
	});
	}catch(e){}
	
	try{
		//Recupero valori per il motore dalla querystring
		$("#price").attr('value', getQueryVariable("price"));
		$("#type").attr('value', getQueryVariable("type"));
		$("#beds").attr('value', getQueryVariable("beds"));
	}catch(e){}
});
function toggleLayer(){
	whichLayer = "descrizionehide";
	if(document.getElementById){
		var style2 = document.getElementById(whichLayer).style;
		style2.display = (style2.display=="block") ? "none" : "block";
	}
	else if (document.all){
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers){
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}
	
function InfoRequest(){
	$("#tabs").tabs("select",4);
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
}
