// iframe bf

function sessGen()
{
	var time = new Date();
	var sec  = time.getSeconds();
	f = Math.floor(Math.random() * 1000000000) + '';
	var sess = '' + sec + f;
	return sess;
}
/* 
   load_iframe(options)
   Apre il sistema di prenotazione fastbooking sul
   Options: 
   DATE_QS (bool, true) Usiamo la data della booking form?
   DATE_FIRST (bool, false) Usiamo la data della booking form?
*/

function load_iframe(options)
	{

		var today= new Date();
		var tomorrow=new Date(today.getTime()+(1000*3600*24));
		var fromday, frommonth, fromyear, to_day, tomonth, toyear, nbnights, city, hotelname, clustername, url, dl, arrival, departure, nbdays, adulteresa, enfantresa, CurrencyLabel, redir, FSTBKNGTrackLink, showPromotions, profil, SESSION, CODE, rt, type, promo, offers_url, iframe_url, FSTBKNGCode, region, AccessCode , FirstRoomName;
		//VALORI DI DEFAULT - SE FALLISCE IL RILEVAMENTO AUTOMATICO - CONFIGURARE PRIMA DELL'INSTALLAZIONE////////
		type="standard"; //oppure offers
		url ="http://www.fastbookings.biz/DIRECTORY/dispoprice.phtml";
		offers_url ="http://www.fastbookings.biz/DIRECTORY/preresa.phtml?";
		clustername='itunafbsite';
		hotelname='All';
		dl='uk';
		fromday=today.getDate();
		frommonth=today.getMonth()+1;
		fromyear=today.getFullYear();
		to_day=tomorrow.getDate();
		tomonth=tomorrow.getMonth()+1;
		toyear=tomorrow.getFullYear();
		nbdays=1;
		adulteresa=1;
		enfantresa=0;
		CurrencyLabel="EUR";
		//redir="BIZ-so5523q0o4";
		redir="UK-so5523q0o4";
		FSTBKNGTrackLink="";
		showPromotions=3;
		profil="";
		FSTBKNGCode='PROMO-BEST-WEB-RATES';
		SESSION="";
		CODE="";
		region="";
		rt=sessGen();
		AccessCode="";
		FirstRoomName="";
		///////////////////////////////////////////////////////////////////
		//INIZIALIZZAZIONE / AUTODETECTION
		//detect clusetername
		if (typeof(document.idForm.Clusternames) != 'undefined') {clustername=document.idForm.Clusternames.value;} 
		//detect hotelnames
		if (typeof(document.idForm.Hotelnames) != 'undefined') {hotelname=document.idForm.Hotelnames.value;} 
		//detect region
		if (typeof(document.idForm.region) != 'undefined') {region=document.idForm.region.value;} 
		//detect language
		if (typeof(document.idForm.langue) != 'undefined') {dl=document.idForm.langue.value;} 
		else { if (typeof(maui_runtime) != 'undefined') { var cl=maui_runtime.current_language; if (cl=="en") dl="uk";  if (cl=="fr") dl="france";  if (cl=="de") dl="germany";  if (cl=="es") dl="spain";  if (cl=="pt") dl="portuguese";  if (cl=="it") dl="italy";  if (cl=="nl") dl="nether";  if (cl=="jp") dl="japan";  if (cl=="ko") dl="coreen";  if (cl=="zh") dl="china";  if (cl=="hk") dl="chinatrad";  if (cl=="ar") dl="arab";  if (cl=="ru") dl="russian";  if (cl=="bu") dl="bulgarian";  if (cl=="tu") dl="turk";  if (cl=="gr") dl="greek";  if (cl=="hu") dl="hungria";  if (cl=="da") dl="dansk";  if (cl=="sv") dl="svensk";  if (cl=="is") dl="islensk";  if (cl=="no") dl="norsk";  if (cl=="fi") dl="finnish";  if (cl=="hr") dl="croate";  if (cl=="cz") dl="czech";  if (cl=="pl") dl="poland";  if (cl=="ro") dl="romanian";  if (cl=="th") dl="thai";  if (cl=="sk") dl="slovak";  if (cl=="si") dl="slovenian";  if (cl=="ca") dl="catalan"; } }
		//detect_date DATE_FIRST � default
		if (typeof(options.DATE_QS) !== 'undefined' && options.DATE_QS)
			{
				//Arrival
				if (typeof(document.idForm.fromday) != 'undefined')	{ fromday=document.idForm.fromday.value; }
				if (typeof(document.idForm.frommonth) != 'undefined')	{ frommonth=document.idForm.frommonth.value; }
				if (typeof(document.idForm.fromyear) != 'undefined')	{ fromyear=document.idForm.fromyear.value; }
				//Departure
				if (typeof(document.idForm.today) != 'undefined')	{ to_day=document.idForm.today.value; }
				if (typeof(document.idForm.tomonth) != 'undefined')	{ tomonth=document.idForm.tomonth.value; }
				if (typeof(document.idForm.toyear) != 'undefined')	{ toyear=document.idForm.toyear.value; }
			}
			else
			{	
				if ( (typeof(options.DATE_FIRST) == 'undefined') || (options.DATE_FIRST==true) ) //XOR
				{
					if (typeof(FB_nb_day_delay) != 'undefined')
						{
							arrival=new Date(today.getTime()+(FB_nb_day_delay*1000*3600*24));
							departure=new Date(arrival.getTime()+(1000*3600*24));
							fromday=arrival.getDate();
							frommonth=arrival.getMonth()+1;
							fromyear=arrival.getFullYear();							
							to_day=departure.getDate();
							tomonth=departure.getMonth()+1;
							toyear=departure.getFullYear();	
						}
				}
			}
		//detect nbdays
		if (typeof(document.idForm.nbdays) != 'undefined') {nbdays=document.idForm.nbdays.value; if (document.idForm.nbdays.value!='') {to_day=tomonth=toyear=false;} } 
		if (typeof(options.nbdays) != 'undefined') {to_day=tomonth=toyear=false;}
		//detect adulteresa
		if (typeof(document.idForm.adulteresa) != 'undefined') {adulteresa=document.idForm.adulteresa.value;}
		//detect enfantresa
		if (typeof(document.idForm.enfantresa) != 'undefined') {enfantresa=document.idForm.enfantresa.value;}		
		//detect CurrencyLabel
		if (typeof(document.idForm.CurrencyLabel) != 'undefined') {CurrencyLabel=document.idForm.CurrencyLabel.value;}
		//detect redir
		if (typeof(document.idForm.redir) != 'undefined') {redir=document.idForm.redir.value;}
		//detect FSTBKNGTrackLink
		if (typeof(document.idForm.FSTBKNGTrackLink) != 'undefined') {FSTBKNGTrackLink=document.idForm.FSTBKNGTrackLink.value;}		
		//detect AccessCode
		if (typeof(document.idForm.AccessCode) != 'undefined') {AccessCode=document.idForm.AccessCode.value;}
		var o = {	
					type:type,
					URL: url,
					DATE_QS: false, //Only for reference
					DATE_FIRST: true, //Only for reference
					offers_URL: offers_url,
					Clusternames: clustername,
					Hotelnames: hotelname,
					region: region,
					langue: dl,
					fromday: fromday,
					frommonth: frommonth,
					fromyear: fromyear,
					today: to_day,
					tomonth: tomonth,
					toyear: toyear,
					nbdays: nbdays,
					adulteresa: adulteresa,
					enfantresa: enfantresa,
					CurrencyLabel: CurrencyLabel,
					redir: redir,
					FSTBKNGTrackLink: FSTBKNGTrackLink,
					showPromotions: showPromotions,
					profil: profil,
					SESSION: SESSION,
					CODE: CODE,
					FSTBKNGCode: FSTBKNGCode,
					rt:rt,
					AccessCode:AccessCode,
					FirstRoomName:FirstRoomName
				};
		o = $.extend(o, options);
		iframe_url=o.URL+"?Clusternames="+o.Clusternames+"&Hotelnames="+o.Hotelnames+"&langue="+o.langue+"&region="+o.region+"&fromday="+o.fromday+"&frommonth="+o.frommonth+"&fromyear="+o.fromyear+"&today="+o.today+"&tomonth="+o.tomonth+"&toyear="+o.toyear+"&nbdays="+o.nbdays+"&adulteresa="+o.adulteresa+"&enfantresa="+o.enfantresa+"&CurrencyLabel="+o.CurrencyLabel+"&redir="+o.redir+"&FSTBKNGTrackLink="+o.FSTBKNGTrackLink+"&showPromotions="+o.showPromotions+"&profil="+o.profil+"&SESSION="+o.SESSION+"&CODE=GoogleAnalytics&rt="+o.rt+"&AccessCode="+o.AccessCode;
		if (o.type == 'offers')
			{
				iframe_url=o.offers_URL+"?langue="+o.langue+"&clustername="+o.Clusternames+"&Hotelnames="+o.Hotelnames+"&FSTBKNGTrackLink="+o.FSTBKNGTrackLink+"&FSTBKNGCode="+o.FSTBKNGCode+"&CurrencyLabel="+o.CurrencyLabel+"&profil="+o.profil+"&rt="+o.rt+"&style=DIRECT";
				//http://81.25.194.32/00000001/032/023112/reservev2.phtml?xcd=P367894.95.164.179&Hotelnames=Italy-Una-Hotel-Cusani&Pricenames=Best-Web-Rates&typeresa=Dist-FBCom;NewSiteFB&CleCode=PROMO-BEST-WEB-RATES&FSTBKNGCode=PROMO-BEST-WEB-RATES&FSTBKNGTrack=Dist-FBCom;NewSiteFB&FSTBKNGTrackLink=NewSiteFB&version=2&langue=italy&ubgj15=9542&style=DIRECT&preresaflg=0
			}
		if (o.type == 'rooms')
		{
			iframe_url=o.offers_URL+"?langue="+o.langue+"&clustername="+o.Clusternames+"&Hotelnames="+o.Hotelnames+"&FSTBKNGTrackLink="+o.FSTBKNGTrackLink+"&FSTBKNGCode="+o.FSTBKNGCode+"&CurrencyLabel="+o.CurrencyLabel+"&profil="+o.profil+"&rt="+o.rt+"&style=DIRECT&FirstRoomName="+o.FirstRoomName;
			//http://213.198.65.231/00000001/032/023112/reservev2.phtml?xcd=P867494.95.164.179&Hotelnames=It-Ca-Sagredo&Pricenames=PASSAGE&CleCode=PROMO-DIRECT-GRAND&FSTBKNGCode=PROMO-DIRECT-GRAND&FSTBKNGTrackLink=roompicture&FirstRoomName=Grand-Canal-Suite-Prestige&profil=URLENCODE%253DOK%2526SESSION%253D23810988492%2526CODE%253DGoogleAnalytics&version=2&langue=italy&ubgj15=9542&style=DIRECT&preresaflg=0
		}
		
		$("iframe").attr('src', iframe_url);
		//if (console) {console.log(iframe_url);}
		//http://81.25.194.32/00000001/032/023112/dispopricev2.phtml?Clusternames=itunahotelsnew&Hotelnames=All&langue=france&fromday=20&frommonth=4&fromyear=2011&today=21&tomonth=4&toyear=2011&nbdays=1&adulteresa=1&enfantresa=0&redir=BIZ-so5523q0o4&FSTBKNGTrackLink=NewSiteFB&showPromotions=3&showPromotions=3&rt=1302699946
	}

function show_booking(options) {
		$("#bottom_box_home_group").css("display", 'none');
		$("#offers_link").css("display", 'none');
		$("#booking_iframe_container").slideDown("fast");
		load_iframe(options);
}

function close_booking(e)
	{
		e.preventDefault();	
		$("#booking_iframe_container").slideUp("fast");
		$("#bottom_box_home_group").css("display", 'block');
		$("#offers_link").css("display", 'block');
		$("#booking_iframe").attr('src', '/loading.html');
	}

function close_booking_opened()
{
	$("#booking_iframe_container").slideUp("fast");
	$("#bottom_box_home_group").css("display", 'block');
	$("#offers_link").css("display", 'block');
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(function(){
	
	$("#booking_iframe_controls a").click(function(e) {
		close_booking(e);
	});
	$('#offers_link a#button_offers_home').click(function () {	show_booking({DATE_QS:true});});
	
	/*
	Calcolo l'altezza complessiva della finestra : height_window
	Calcolo l'altezza del box bottom : height_bottom
	Calcolo l'altezza di top + 50 + bottom: height_tot
	Se quest'ultima � > di altezza finestra allora calcolo l'altezza di bottom : max_height
	*/	
	
	/*altezza della finestra browser*/
	/*var height_window = ($(window).height());*/
	//alert("Altezza finestra: " + (height_window -140));
	
	/*altezza box bottom*/
	/*var height_bottom = $('#bottom_box').height();*/
	/*alert("Altezza box bottom: " + height_bottom);*/
	
	/*altezza ombra in basso*/
	/*var height_top = $('#top_box').height();*/
	/*alert("Altezza ombra top: " + height_top);*/
	
	/*altezza tot: ombra in alto + spazio che voglio lasciare + ombra in basso*/
	/*var height_tot = (height_window-160);*/	
	/*alert("Somma dei div: " + height_tot);*/
	
	/*altezza massima che pu� avere ombra in basso*/
	/*var max_height = ((height_window - height_top) - 200);*/	
	/*alert("Altezza da dare al div in basso:" + max_height);*/
	
	/*if((height_bottom) > height_tot){
		$('#bottom_box').css('height',(max_height + 'px'));	
		$('#bottom_box').css('overflow','auto');
	}*/	
	
	/*Scrollbar personalizzata*/
	/*$(function(){
		$('.scroll-pane').jScrollPane({showArrows:true});
	});*/
	
	/*Mentre carica la pagina nascondo tutto, quando ha caricato tutto mostro*/
	$('#offers').removeClass('hidden');	
	
	/*
	//image preloader
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
	
	/*Logo png trasparente*/
	$('#top_box,#logo').pngFix();
	
	// FANCYBOX	
	jQuery(".gallery a").fancybox();
	
	/*Fancybox*/
	//$(".group").fancybox({ titlePosition: 'over' });
	

	// SUPERSIZE	
	$.fn.supersized.options = {  
				startwidth: 1024,  
				startheight: 768,
				vertical_center: 1,
				slideshow: 1,
				navigation: 0,
				transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 1,
				slide_interval: 4000  
			};

	$('#supersize_category').cycle();
	
	// SLIDE ITEM HOMEPAGE
	$('#items_list_home').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 3000, 
		next:   '#next_item', 
		prev:   '#prev_item' 
	});

	
	/*Scroll offers*/
	/*$('#shuffle_offers').cycle({ 
    	fx:     'scrollHorz',
    	speed:   2000, 
    	timeout: 2000    
	});*/
	
	/*Personalizzazione select booking form*/
	$('.my-dropdown').sSelect();
	$('#hotel_list .my-dropdown').sSelect();
	
	
	/*Effetto Carousel photogallery*/	
	jQuery('#mycarousel_photo').jcarousel({
        auto: 5,
        wrap: 'last',
        scroll: 1,
        initCallback: mycarousel_initCallback
    });

	/* MORE_INFO */
	/*all_hidden: per aprire items senza aver schiacciato view all*/
	$('div.more a.more_info').click (function() {		
		//var hidden_id = parseInt($(this).attr('id').replace('h_', ''), 10); 									 	
		var hidden_id = $(this).attr('id').replace('more_', ''); 									 	
		//alert(hidden_id);
		
		//$(this).closest(".all_hidden #list .item").addClass('height_ie6'); 
		//alert(parent_item);
		$('#body_item_' + hidden_id).show(100);
		$(this).hide(10);
		return false;
	});
	
	/*richiudere il div*/
	$('div.close a').click (function() {		
		//var hidden_id = parseInt($(this).attr('id').replace('h_', ''), 10); 									 	
		var hidden_id = $(this).attr('id').replace('close_', ''); 									 	
		//alert(hidden_id);
		
		//$(this).closest(".all_hidden #list .item").addClass('height_ie6'); 
		//alert(parent_item);
		$('#body_item_' + hidden_id).hide(100);
		$('#more_' + hidden_id).show(100);
		return false;
	});
	
	// Link_exchange pager
	$('#link_exchange_links .pager').find('a').live('click', function () {
		var that = $(this);
		$('#link_exchange_links_container').height($('#link_exchange_links_container').height()).addClass('loading');
		$('#link_exchange_links').fadeOut(200, function () {
			$(this).load(that.attr('href') + ' #link_exchange_links > *', function  () {
				$(this).fadeIn(200);
				$('#link_exchange_links_container').height('auto').removeClass('loading');
			});
		});
		return false;
	});

	// Guest comments pager
	$('#guestcomments .pager').find('a').live('click', function () {
		var that = $(this);
		$('#guestcomments-container').height($('#guestcomments-container').height()).addClass('loading');
		$('#guestcomments').fadeOut(200, function () {
			$(this).load(that.attr('href') + ' #guestcomments > *', function  () {
				$(this).fadeIn(200);
				$('#guestcomments-container').height('auto').removeClass('loading');
			});
		});
		return false;
	});
	

	
	// BOOK NOW LINK FOOTER
	/*$("[class*='cat_28']").attr('href', 'javascript:;');
	$("[class*='cat_28']").click(function(){
		hhotelSearch('ITHTLVOlmiresort', '', '', '', '', '', '');
		return false;
	});*/
	
	$("[class*='cat_49']").attr('href', 'http://www.lerobinie.com');
	
	$("[class*='cat_31']").attr('href', 'http://www.fastbooking.net');
	$("[class*='cat_31']").attr('target', 'blank');


	/* BOOKING FORM */
	start();
	
	if(typeof idForm!='undefined' && typeof init_form != 'undefined'){
		init_form();
	}
	
//Bottoni mostra/nascondi
  //***************************************  HOMEPAGE  ********************************************//
  var orig_title="";
  $('#home_article a.show_hide_button').click(
    function()
    {
      var id_to_hide="#"+$(this).attr('rel');
      var that=$(this);
      if (that.hasClass('show'))
        {
          
          //SHOW    
          that.parent().parent().animate({width:'100%', height:'100%'}, 500, function() {
            $(id_to_hide+" .text").fadeIn('fast', function() {that.removeClass('show'); that.attr("title", orig_title);} );
          });

        }
        else
        {
          //HIDE
          orig_title=that.attr('title');
          $(id_to_hide+" .text").fadeOut('fast',
           function()
            {
              that.parent().parent().animate({width:'26px', height:'26px'}, 500, function() {that.addClass('show'); that.attr("title", that.find("span").html());});
            }
          );          
        }
    }
  );
//***************************************  MORE HOMEPAGE ************************************//
  $("#content_home_group a.more_body").click(function() {
    $("#first-text").fadeOut('fast', function()
      {
        $("#first-text").removeClass('text');
        $('#offers_list').css("display","none");
        $('#trecentosessanta').css("display","none");
        $("#content_home_group").animate(
                      {
                        width: "960px",
                        height:"400px"
                      },
                      1000,
                      function()
                        {
                          $("#second-text").addClass('text');
                          $("#second-text").fadeIn('fast');
                        }
                      );
      });
  });    
  $("#content_home_group a.close_body").click(function() {
    $("#second-text").fadeOut('fast', function()
      {
        $("#second-text").removeClass('text');
        $('#offers_list').css("display","block");
        $('#trecentosessanta').css("display","block");
        $("#content_home_group").animate(
                      {
                        width: "500px",
                        height: "250px"
                      },
                      1000,
                      function()
                        {
                          $("#first-text").addClass('text');
                          $("#first-text").fadeIn('fast'); 
                        }
                      );
      });
  });
  //***************************************  FINE  ********************************************//

	
});



