function active_panel(){

	if (document.getElementById("linguetta")){

		var mio_blocco = document.getElementById("linguetta");

		if (mio_blocco.style.left == ""){

			mio_blocco.style.left = "51px";

			mio_blocco.style.background = "url(images/linguetta_booking.png) no-repeat right 70px";

		} else if (mio_blocco.style.left == "51px"){

			mio_blocco.style.background = "url(images/sfondo_pannello.png) no-repeat right center";

			aprichiudi("linguetta", 51, 315, "open");

		} else if (mio_blocco.style.left == "315px"){

			aprichiudi("linguetta", 315, 51, "close");

		}

	}

}



function aprichiudi(id, pos_now, pos_end, azione){

	differenza = -(pos_now - pos_end);

	action = azione;

	mio_blocco = id;

	fine_corsa = pos_end;

	new_position = pos_now + (Math.round(differenza/5)*1);

	if (action=="open"){

		if ((pos_end - new_position) > 3){

			document.getElementById(id).style.left = new_position+"px"

			setTimeout("aprichiudi(mio_blocco, new_position, fine_corsa, 'open')",6);

		} else {

			document.getElementById(id).style.left = fine_corsa+"px"

			return false;

		}

	} else if (action=="close"){

		if ((pos_end - new_position) < -3){

			document.getElementById(id).style.left = new_position+"px"

			setTimeout("aprichiudi(mio_blocco, new_position, fine_corsa, 'close')",6);

		} else {

			document.getElementById(id).style.left = fine_corsa+"px"

			document.getElementById(id).style.background = "url(images/linguetta_booking.png) no-repeat right 70px";

			return false;

		}

	}

}



function active_panel2(){

	if (document.getElementById("pannello_richiesta_info")){

		var mio_blocco = document.getElementById("pannello_richiesta_info");

		if (mio_blocco.style.height == ""){

			mio_blocco.style.height = "0px";

			mio_blocco.style.border = "none";

		} else if (mio_blocco.style.height == "0px"){

			aprichiudi2("pannello_richiesta_info", 0, 80, "open");

			mio_blocco.style.border = "2px solid #126CAA";

			mio_blocco.style.borderTop = "none";

		} else if (mio_blocco.style.height == "80px"){

			aprichiudi2("pannello_richiesta_info", 80, 0, "close");

		}

	}

}



function aprichiudi2(id, pos_now, pos_end, azione){

	differenza = -(pos_now - pos_end);

	action = azione;

	mio_blocco = id;

	fine_corsa = pos_end;

	new_position = pos_now + (Math.round(differenza/5)*1);

	if (action=="open"){

		if ((pos_end - new_position) > 3){

			document.getElementById(id).style.height = new_position+"px"

			setTimeout("aprichiudi2(mio_blocco, new_position, fine_corsa, 'open')",6);

		} else {

			document.getElementById(id).style.height = fine_corsa+"px"

			return false;

		}

	} else if (action=="close"){

		if ((pos_end - new_position) < -3){

			document.getElementById(id).style.height = new_position+"px"

			setTimeout("aprichiudi2(mio_blocco, new_position, fine_corsa, 'close')",6);

		} else {

			document.getElementById(id).style.height = fine_corsa+"px"

			document.getElementById(id).style.border = "none";

			return false;

		}

	}

}



function init_fade_block(id){

	if (document.getElementById(id)){

		var mio_blocco = document.getElementById(id);

		var blocchi = mio_blocco.getElementsByTagName("div");

		for (i=0; i < blocchi.length; i++){

			blocco = blocchi[i];

			blocco.style.display = "none";

		}

		fade_block(id, 0);

	}

}

function fade_block(id, id_now){

	if (document.getElementById(id)){

		my_id = id;

		var mio_blocco = document.getElementById(id);

		var blocchi = mio_blocco.getElementsByTagName("div");

		if (id_now < blocchi.length){

			my_id_now = id_now;

		} else {

			my_id_now = 0;

		}

		for (i=0; i < blocchi.length; i++){

			if (my_id_now == i){

				blocchi[i].style.display = "block";

			} else {

				blocchi[i].style.display = "none";

			}

		}

		my_id_now++;

		my_id = id;

		setTimeout("fade_block(my_id, my_id_now)",3000);

	}

}

function show_book_home(div_count){
	if (document.getElementById("hotel")){
		var mio_div = document.getElementById("hotel");
		var blocchi = mio_div.getElementsByTagName("div");
		var conta_blocchi = 0;
		for (i=0; i < blocchi.length; i++){
			if (blocchi[i].className == "hotel_info_container"){
				if (conta_blocchi != div_count){
					blocchi[i].style.display = "none";
				} else {
					blocchi[i].style.display = "block";
				}
				conta_blocchi++;
			}
		}
	}
}





function abrir_janela_popup(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}



function show_search(){
	if (document.getElementById("loading")){
		document.getElementById("loading").style.display = "block";
	}
	
        var divCollection = document.getElementsByTagName("div");
        for (var i=0; i<divCollection.length; i++) {
            if(divCollection[i].getAttribute("class") == "risultato_wrapper") {
                divCollection[i].style.display = "none";
            } 
        }

}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


/******************************************************* BOX NEWS HOMEPAGE */


function newsInitHome() {
	
	var list = $('#contOffers .offer');

	if(list.length > 3) {
		setInterval ( "newsScrollHome()", 7000 );
	}
}

function newsScrollHome() {

	var myHeight = $('#contOffers .offer:first').outerHeight();
	
	//console.log(myHeight);
	
	$('#contOffers .offer:first').animate(			
		{opacity:0,
		marginTop: '-'+myHeight+'px'
		},
		700,
		'',
		function(){
			$(this).remove().insertAfter('#contOffers .offer:last');
			$('#contOffers .offer').removeAttr('style');
		});	

}

// Funzione per slideShow immagini nel visual
function slideShow() {

	var active = $('#galJs img:first');
	
	active
		.remove()
		.insertAfter('#galJs img:last')
		.animate({opacity: 1.0}, 1000, function() {
			$(this).siblings().removeAttr('style');
		});
		
}

///////////
$(document).ready(function(){
		
		newsInitHome();
		
		$.ajax({
            type: "GET",
            url: "gal_home.xml", //xml file 
   			dataType: "xml",
            success: function(xml) {
                var count = 0; //counter
                $(xml).find('image').each(function() {
 
                    var url = $(this).attr('path'); //url 
					
					$('#galJs').append('<img src="'+url+'" />');
                    count++;
                });
				
				// Init slideShow 
				$('#load').remove();
				slideShow();
				setInterval( "slideShow()", 5000 );
				
            }
        });
		
		// Datepicker
		
		var lg = $('input#lg').val();
		
		switch(lg) {
			case '1':		lang = 'it';		break;
			case '2':		lang = 'en';		break;
			case '3':		lang = 'de';		break;
			case '4':		lang = 'fr';		break;
			case '5':		lang = 'hu';		break;
			case '6':		lang = 'pl';		break;
			case '7':		lang = 'ro';		break;
			case '8':		lang = 'sk';		break;
			case '9':		lang = 'cs';		break;
			default:
			case '2':		lang = 'en';		break;
		}
		
		$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
		$('.input > input').datepicker($.datepicker.regional[lang]);
	
		$('.input > input').datepicker('option', {
			dateFormat: 'dd/mm/yy',
			minDate: 0,
			changeMonth: true,
			changeYear: true
		});
		
		$('.data_arrivo').val();
		$('.data_partenza').val();
		$('.data_partenza').datepicker('option', {	minDate: '+1d' });
		
		$('.data_arrivo').change(
			function(el) {
				var elId =  el.target.id;
				var form = $('#'+elId).parents('form');
				date1 = $('.data_arrivo', form).datepicker('getDate');
				date2 = new Date(date1);
				date2.setDate(date1.getDate() + 1);
				$('.data_partenza', form).datepicker('option', 'minDate', date2);
			}
		);
});






