// JavaScript Document
$('document').ready(function() {

	$('.photo-city li a').click(function() {
		
		var hidden_id = parseInt($(this).parents('li').attr('id').replace('photo_', ''), 10); 
		
		$('.photo-city li').each(function() {
			$(this).removeClass('on');
			$(this).addClass('off');
		});
		$('#photo_' + hidden_id).addClass('on');
		
		$('#gallery').load($(this).attr('href') + ' .gallery > a', function() { 
			$('#gallery a').lightBox();													
		});
		return false;
	});

	// FACCIO UN PO' PIU' LARGO IL BOX (rosa) DEL title-page
	var width_title_page = $('.title-page').width();
	if (width_title_page<=500) {
		$('.title-page').css('padding-right','200px');
	}


	$('#gallery a').lightBox();
	

	$('.first a').click(function() {
		$(this).addClass('selected');
		$('.second a').removeClass('selected');	
		$('#form-2').css("display","none");
		$('#form-1').css("display","block");
	});
	
	$('.second a').click(function() {
		$(this).addClass('selected');
		$('.first a').removeClass('selected');	
		$('#form-1').css("display","none");
		$('#form-2').css("display","block");
	});
	

	/* */	
	$('#menu_hotels a').each(function() {
		$(this).click(function() {
			// TITLE
			$('.title_page').load($(this).attr('href') + ' #titolo', function() { });
			
			// CONTENT
			$('#cont_page').load($(this).attr('href') + ' #contenuto', function() {
				$('#gallery a').lightBox();

				/* MORE DETAILS OFFERTE ED EVENTI (in dettaglio hotel) */
				$('.more_offers a').click(function() {
					var hidden_id = parseInt($(this).parents('.more_offers').attr('id').replace('h_', ''), 10); 
					//console.log(hidden_id);
					$('#hidden_' + hidden_id).show(1000);
					return false;
				});
			});
		});	
	});
		
			
	/* */	
	$('#menu_hotels li').each(function() {				
		var pop_visible = $('#cont_page').css('left') == 0 ? true : false;
		//alert(pop_visible);
		
		$(this).click(function() {	
			$('#menu_hotels li').each(function() {
				$(this).removeClass("on");
				$(this).addClass("off");
			});
			$(this).addClass("on");
			return false;
		});
	});
		
		
	//------------ OFFERS
	$('#offers-container .box a').livequery('click', function(event) {
		$(this).parent('div').siblings().children('a').removeClass('on_offers');
        var link = $(this).attr('href');
		var box_id = parseInt($(this).parents('.box').attr('id').replace('div-offer-', ''), 10);
		for (i=box_id + 1; i<=5 ; i++) {
			$('#div-offer-4').css("display","block");
			$('#div-offer-' + i).load(link + ' #list-' + i + '> *');
		}
		return false;
    });
	
	
	//------------ EVETS
	$('#events-container .box a').livequery('click', function(event) {
		$(this).parent('div').siblings().children('a').removeClass('on_offers');
        var link = $(this).attr('href');
		var box_id = parseInt($(this).parents('.box').attr('id').replace('div-offer-', ''), 10);
//		console.log('#div-offer-6');
		for (i=box_id + 1; i<=5 ; i++) {
			$('#div-offer-4').css("display","block");
			$('#div-offer-5').css("display","block");
			$('#div-offer-' + i).load(link + ' #list-' + i + '> *');
		}
		return false;
    }); 
	
	
	$('.box li a').click(function() {
		//console.log($(this).parents('li').attr('id'));
		$('.box li').each(function() {
			$(this).removeClass("on");
		});
		var box_li = parseInt($(this).parents('li').attr('id').replace('li_', ''), 10); 
		$('#li_' + box_li).addClass("on");
	});
	
	
	/* MORE DETAILS OFFERTE ED EVENTI (in dettaglio hotel) */
	$('.more_offers a').click(function() {
		var hidden_id = parseInt($(this).parents('.more_offers').attr('id').replace('h_', ''), 10); 
		//console.log(hidden_id);
		$('#hidden_' + hidden_id).show(1000);
		return false;
	});
	
	/* VIEW ALLOFERS in APARTMENTS */
	$('#view_all_offers a').click(function() {
		//console.log(hidden_id);
		$('#view_all_offers').hide();
		$('#all_offers').fadeIn(500);
		return false;
	});
	
	
}); // end document ready



// HOTELS_LIST
$('.hotels_list a').livequery('click', function(event) {
	// TITLE
//	console.log($(this).attr('href'));
//	$(this).css("border","1px solid red");
	$('.hotels_list a').each(function() {
		$(this).removeClass("selected");
	});
	$(this).addClass('selected');
	var link = $(this).attr('href');
	$('#div-offer-5').load(link + ' #list-' + 5 + '> *');
	return false;
});	

	

// APERTURA BOX OFFERTA
$('.offerta a')
	.livequery('click', function(event) {
		var hidden_id = parseInt($(this).parents('.offerta').attr('id').replace('offer_', ''), 10); 
		//alert('hidden_body_' + hidden_id);
//		$(".hidden_body_" + hidden_id).css("display","block");
		$(".hidden_body_" + hidden_id).show(100);
		//		$("#h_" + hidden_id).css("display","none");
		$("#booknow_" + hidden_id).removeClass("hidden");
		
	// TITLE
	/*
	var link = $(this).attr('href');
	$("#box_offerta").css("display","block");
	$("#box_offerta").animate({"top": "0px"}, "slow");
	$('#box_offerta').load($(this).attr('href') + ' .contenuto_offera', function() {
		$('#close_animate a').click(function() {
			$("#box_offerta").animate({"top": "-280px"}, "slow");
			return false;
			//$("#box_offerta").hide();
		});
	});*/
	
	return false;
});



// APERTURA BOX EVENTO
$('.evento a')
	.livequery('click', function(event) {
	// TITLE
	var link = $(this).attr('href');
//	console.log("qui");
	$("#box_evento").css("display","block");
	$("#box_evento").animate({"top": "0px"}, "slow");
	$('#box_evento').load($(this).attr('href') + ' .contenuto_evento', function() {
		$('#close_animate a').click(function() {
			$("#box_evento").animate({"top": "-280px"}, "slow");
			return false;
			//$("#box_offerta").hide();
		});
	});
	return false;
});
