$(document).ready(function(){
	start();
});
	
//SETTING UP OUR POPUP   
//0 means disabled; 1 means enabled;   
var popupStatus = 0;  

$(function() {	
// -----------------------------------
// 			START POPUP
// -----------------------------------
	
	//LOADING POPUP
	//Click the button event!
	$(".transfer a").click(function(){
		//alert("qui");	
		centerPopup(); 
		loadPopup();   
	});
	
	//loading popup with jQuery magic!
	function loadPopup(){

	//loads popup only if it is disabled
		if(popupStatus==0){
			$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
		}
	}
	
		//centering popup
	function centerPopup(){
		
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popupContact").height();
		var popupWidth = $("#popupContact").width();
		//centering
		$("#popupContact").css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		$("#backgroundPopup").css({
			"height": windowHeight
		});	
	}	
	
		//disabling popup with jQuery magic!
	function disablePopup(){
		//disables popup only if it is enabled
		if(popupStatus==1){
			$("#backgroundPopup").fadeOut("slow");
			$("#popupContact").fadeOut("slow");
			popupStatus = 0;
		}
	}
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});

// -----------------------------------
//    END POPUP
// -----------------------------------
	
	

	
	
	// TRASPARENT IE6
	$('.arrow-left, .arrow-right, .image, #services_bottom, .btn, #mappa a, .gallery .logo, #offerta_selezionata .thumbnail, #offerta_selezionata .booknow, #list_offers .text .thumbnail, #list_offers .text .info .booknow, #services_bottom_small, .json_image_rotator .caption').ifixpng(); 


	$('#services_bottom').each(function(){
		$(this).children('.services').each(function(){
			$(this).click(function(){
				location.href = $(this).children('a.box_select').attr('href');
		   });
		});										
	});
	
	
	// BOOK NOW LINK
	$("a.cat_13").click(function(){
		hhotelSearchGroup('XXX', '', '', '', '');
		return false;
	});
	
	$('#full_page #list_offers .box_select').each(function() {
		$(this).parent('div').hover(function() {
			$(this).children('a.box_select').addClass('hover');
		}, function() {
			$(this).children('a.box_select').removeClass('hover');
		});
		
	});
	
	<!-- WHERE WE ARE -->
	$('.services_small .box_select').click(function() {
		/* CARICO DINAMICAMENTE CONTENUTO DEL BOX HIDDEN (BOTTOM) es. WHERE WE ARE*/

		var title = $(this).attr('href') + ' #article .title';
		$("#box_hidden .title").load(title, function(){
													 
					
			// CROLL TO su ROOMS
			$.scrollTo($('#ancora_where'), 500);
		});
		//alert(title);
		var body = $(this).attr('href') + ' #article #text .subtitle';
		$("#box_hidden .body").load(body);
		var images = $(this).attr('href') + ' #article .small_image';
		$("#box_hidden .images").load(images);
		$("#box_hidden").show(100);
		$(this).addClass("selected");


		/* AGGIUNGO LA CLASSE PER L'ARTICLE SELEZIONATO*/
		$('.box_select').each(function() {
			$(this).removeClass("selected");	
			$(this).addClass("noselected");
		});
		$(this).addClass("selected");
		//$(this).removeClass("noselected");
		
		return false;
	});
	
	
	
	<!-- HOMEPAGE -->
	$('#services .box_select').click(function() {
		/* CARICO DINAMICAMENTE CONTENUTO DEL BOX HIDDEN (BOTTOM) es. WHERE WE ARE*/

		var title = $(this).attr('href') + ' #article .title';
		$("#box_hidden .title").load(title);
		//alert(title);
		var body = $(this).attr('href') + ' #article #text .subtitle';
		$("#box_hidden .body").load(body);
		var images = $(this).attr('href') + ' #article .small_image';
		$("#box_hidden .images").load(images);
		$("#box_hidden").show(100);
		$(this).addClass("selected");


		/* AGGIUNGO LA CLASSE PER L'ARTICLE SELEZIONATO*/
		$('.box_select').each(function() {
			$(this).removeClass("selected");	
			$(this).addClass("noselected");
		});
		$(this).addClass("selected");
		//$(this).removeClass("noselected");
		
	});
	
	
	
	
	/* CARICO DINAMICAMENTE IL BOX NASCOSTO NELLE ROOMS */
	$('.room a.box_select').click(function() {
		
		var title = $(this).attr('href') + ' #detail_item';
		$("#text_selected").load(title, function(){
			$('.gallery a').lightBox();			
			// CROLL TO su ROOMS
			$.scrollTo($('#ancora_rooms'), 500);
		});
		
		
		$("#text_selected").show(100);
		$('.room .box_select').each(function() {
			$(this).removeClass("selected");
		});
		$(this).addClass("selected");
		$(this).removeClass("noselected");
		return false;
		
	});
	
	
	// VISUALIZZO LA RISPOSTA DELLA FAQ
	$("#faq .story .full_box .moreinfo a").click(function(){
		$("#faq .story .full_box .moreinfo").each(function() {
			$(this).removeClass("faq_select");
		});
		
		$(this).parent('.moreinfo').addClass("faq_select");
		// carico la risposta selezionata nel box #faq_hidden
		var hidden_id = parseInt($(this).parent('.moreinfo').attr('id').replace('h_', ''), 10); 
		var risp = ($(this).attr('href') + ' #risp_' + hidden_id);
		//alert(risp);
		$("#faq_hidden").load(risp);
		//$("#faq_hidden").css("border","1px solid red");	
		return false;
	});
});
