/*
 * generico.js
 * 
 */

/*
function lz(numero, cifre) {
	n = String(numero);
	while (n.length<cifre) { 
		n="0"+n ;
	}
	return n;
}

function dateFormat(data, formato) { 
	var giorni = new Array("Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato");
	var mesi = new Array("Gennaio","Febbraio","marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");

	// preparo la data...  verificare di passarla corretta!
	var adesso = new Date(data); 
	var anno = adesso.getFullYear();
	var mese = adesso.getMonth()+1;
	var giorno = adesso.getDate();
	var settim = adesso.getDay();
	var ore = adesso.getHours();
	var minuti = adesso.getMinutes();
	var secondi = adesso.getSeconds();

	// preparo la stringa di risposta
	var rVal = '';

	if (formato.length==0) { 
		// assenza del secondo parametro
		return String(adesso); 
	} else {

		// inizio loop
		while (formato.length>0) {

			// verifico se c'e' qualche separatore e lo aggiungo
			while (formato.length>0 && String("ymdphnst").indexOf(formato.charAt(0).toLowerCase())<0) {
				rVal += formato.charAt(0);
				formato = formato.substr(1);
			}

			// Separo il gruppo
			if (formato.length>0) {
				ff = formato.charAt(0);
				formato = formato.substr(1);
				while (formato.length>0 && formato.charAt(0).toLowerCase()==ff.charAt(0).toLowerCase()) {
					ff += formato.charAt(0);
					formato = formato.substr(1);
				}

				// espando il formato nella stringa corrispondente
				ff = ff.toLowerCase();	 // operazione preliminare... tutto in minuscolo
				switch (ff) 	{ 
					case "yy" : 
						rVal += String(anno).substr(2); 
						break; 
					case "yyyy" : 
						rVal += String(anno); 
						break; 
					case "m" : 
						rVal += String(mese); 
						break; 
					case "mm" : 
						rVal += lz(mese,2);
						break; 
					case "mmm" : 
						rVal += mesi[mese-1].substr(0,3);
						break; 
					case "mmmm" : 
						rVal += mesi[mese-1];
						break; 
					case "d" : 
						rVal += String(giorno); 
						break; 
					case "dd" : 
						rVal += lz(giorno,2); 
						break; 
					case "ddd" : 
						rVal += giorni[settim].substr(0,3);
						break; 
					case "dddd" : 
						rVal += giorni[settim];
						break; 
					case "p" : 
						var inizio = new Date(anno, 0, 0); 
						rVal += Math.floor((adesso - inizio) / 86400000);
						break; 
					case "ppp" : 
						var inizio = new Date(anno, 0, 0); 
						rVal += lz(Math.floor((adesso - inizio) / 86400000),3);
						break; 
					case "h" : 
						rVal += String(ore); 
						break; 
					case "hh" : 
						rVal += lz(ore,2); 
						break; 
					case "n" : 
						rVal += String(minuti); 
						break; 
					case "nn" : 
						rVal += lz(minuti,2); 
						break; 
					case "s" : 
						rVal += String(secondi); 
						break; 
					case "ss" : 
						rVal += lz(secondi,2); 
						break; 
					case "t" : 
						rVal += lz(ore,2)+":"+lz(minuti,2)+":"+lz(secondi,2); 
						break; 
					default :  // il numero dei caratteri del formato non e' permesso
						rVal += ff.replace(/./gi,"?");
				} 
			}
		} // fine loop principale
		return rVal;
	}
} 
*/

(function($) {

	$.placeholderLabel = {
	    placeholder_class: null,
	    add_placeholder: function(){
	      if($(this).val() == $(this).attr('placeholder')){
	        $(this).val('').removeClass($.placeholderLabel.placeholder_class);
	      }
	    },
	    remove_placeholder: function(){
	      if($(this).val() == ''){
	        $(this).val($(this).attr('placeholder')).addClass($.placeholderLabel.placeholder_class);
	      }
	    },
	    disable_placeholder_fields: function(){
	      $(this).find("input[placeholder]").each(function(){
	        if($(this).val() == $(this).attr('placeholder')){
	          $(this).val('');
	        }
	      });
	      return true;
	    }
	};

	$.fn.placeholderLabel = function(options) {
	    // detect modern browsers
	    var dummy = document.createElement('input');
	    if(dummy.placeholder != undefined){
	      return this;
	    }

	    var config = {placeholder_class : 'placeholder'};

	    if(options) $.extend(config, options);
	    
	    $.placeholderLabel.placeholder_class = config.placeholder_class;

	    this.each(function() {
	      var input = $(this);

	      input.focus($.placeholderLabel.add_placeholder);
	      input.blur($.placeholderLabel.remove_placeholder);

	      input.triggerHandler('focus');
	      input.triggerHandler('blur');
	      
	      $(this.form).submit($.placeholderLabel.disable_placeholder_fields);
	    });
	    
	    return this;
	  }

	$.fn.lowerResolution = function() {
		if ($(window).width() < 1155) {
			$('.page').addClass('lowerResolution');
		} else {
			$('.page').removeClass('lowerResolution');
		}
	};

	$.fn.placeHolder = function() {
		$(this).focus(function(){ 
			if ($(this).val() == $(this).attr('defaultValue')) {
				$(this).val('');
			}
		}).blur(function(){
			if ($(this).val() == '') {
				$(this).val($(this).attr('defaultValue'));
			} 
		});
	};

    $.fn.extend({
          center: function (options) {
               var options =  $.extend({ // Default values
                    inside       : window, // element, center into window
                    transition   : 0, // millisecond, transition time
                    minX         : 0, // pixel, minimum left element value
                    minY         : 0, // pixel, minimum top element value
                    withScrolling: true, // booleen, take care of the scrollbar (scrollTop)
                    vertical     : true, // booleen, center vertical
                    horizontal   : true, // booleen, center horizontal
					offsetX      : 0,
					offsetY      : 0
               }, options);
               return this.each(function() {
                    var props = {position:'absolute'};
                    if (options.vertical) {
                         var top = ($(options.inside).height() - $(this).outerHeight()) / 2;
                         if (options.withScrolling) top += $(options.inside).scrollTop() || 0;
                         top = (top > options.minY ? top : options.minY);
                         $.extend(props, {top: (top-options.offsetY)+'px'});
                    }
                    if (options.horizontal) {
                          var left = ($(options.inside).width() - $(this).outerWidth()) / 2;
                          if (options.withScrolling) left += $(options.inside).scrollLeft() || 0;
                          left = (left > options.minX ? left : options.minX);
                          $.extend(props, {left: (left-options.offsetX)+'px'});
                    }
                    if (options.transition > 0) $(this).animate(props, options.transition);
                    else $(this).css(props);
                    return $(this);
               });
          }
    });

	$.fn.myFadeIn = function() {
		if (jQuery.support.opacity) {
			$(this).fadeIn();
		} else {
			$(this).show();
		}
	};

	$.fn.myFadeOut = function(options) {
		var options =  $.extend({
				speed: "fast"
			  , func: function() {}
			}, options);
		if (jQuery.support.opacity) {
			$(this).fadeOut(options.speed, function() {
												options.func.call(this)
											});
		} else {
			$(this).hide();
			options.func.call(this);
		}
	};

	$.fn.maskMe = function(options) {
		var options =  $.extend({
				src: '/skin/website/widgets/mask-detail.png'
			}, options);
		$(this).each(function() {
			var width    = $(this).css('width')
			  , height   = $(this).css('height')
			  , position = $(this).css('position')
			  , classNew = $(this).attr('class')
			  , srcImg   = $(this).attr('src')
			  , srcImg   = srcImg + ''
			  , cssStyle = 'background: url(' + srcImg + ') no-repeat left top'
			  ;
		$(this).before('<div class="' + classNew + '" style="' + cssStyle + '"><img src="' + options.src + '" width="' + width + '" height="' + height + '" alt="" /></div>');
			$(this).hide();
		});
	};

	$.fn.myValidation = function(options) {
		var options =  $.extend({
				msgPos     : 'modal' // modal|infield|outfield
			  , emailReg   : /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/
			  , errorStyle : {'border':'solid 1px red', 'color':'#ff0000', 'background-color':'#ffff33'}
			}, options)
		  , error = false
		  ;
		$(this).submit(function() {
			var myForm = $(this)
			  , errors = new Array()
			  ;
			$('.required', this).each(function() {
				var el      = $(this).get(0)
				  , tagName = el.tagName
				  , input   = (tagName == 'INPUT' && $(this).attr('type') == 'text' ? $(this).attr('value') : false)
				  , check   = (tagName == 'INPUT' && $(this + ':checked') ? $(this).length : false)
				  ;

				if (options.msgPos == 'modal') {
					var label = $('label[for='+$(this).attr('name')+']').text();
					if (!input || (!check && input == "Y")) {
						errors.push(label);
					} else if ($(this).hasClass('valEmail')) {
						if (!options.emailReg.test(input)) {
							errors.push(label);
						}
					}
				}
			});

			if (errors.length) {
				$.each(errors, function(index, value) {
					var theLabel = $('label:contains(' + value + ')')
					  , theInput = theLabel.siblings('input')
						;
					theInput.css(options.errorStyle);
					if (index == 0) { theInput.focus(); }
					alert('Error: ' + value);
				});

				return false;
			} else {
				return true;
			}
		});
	};

	$.fn.myDatepicker = function(options) {
		var options = $.extend({dateFormat : 'dd/mm/yy'
							  , lang       : 'it'
							  , firstDay   : 1
							  , altField   : '#dateIn'
							  , altFormat  : 'mm/dd/yy'
								}, options);

		
		$.datepicker.setDefaults(
			$.datepicker.regional[options.lang]
		);
		
		/*
		var now = dateFormat(Date(), 'dd/mm/yyyy'); 
		var nowEn = dateFormat(Date(), 'mm/dd/yyyy'); 
		$(this).val(now);
		$('#dateIn').val(nowEn);
		*/
		
		var d = new Date();
		var curr_date  = d.getDate();
		var curr_month = d.getMonth();
		var curr_year  = d.getFullYear();
		$(this).val(curr_date + '/' + (curr_month+1) + '/' + curr_year);
		$('#dateIn').val((curr_month+1) + '/' + curr_date + '/' + curr_year);
		$(this).datepicker({
			dateFormat : options.dateFormat
		  , firstDay   : options.firstDay
		  , altField   : options.altField
		  , altFormat  : options.altFormat
		});
	};

	/* Italian initialisation for the jQuery UI date picker plugin. */
	$.datepicker.regional['it'] = {
		closeText: 'Chiudi',
		prevText: '&#x3c;Prec',
		nextText: 'Succ&#x3e;',
		currentText: 'Oggi',
		monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
		monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic'],
		dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
		dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
		dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
		weekHeader: 'Sm',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''
	};

	/* English/UK initialisation for the jQuery UI date picker plugin. */
	$.datepicker.regional['en'] = {
		closeText: 'Done',
		prevText: 'Prev',
		nextText: 'Next',
		currentText: 'Today',
		monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
		monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
		dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
		dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
		dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
		weekHeader: 'Wk',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''
	};

	/* German initialisation for the jQuery UI date picker plugin. */
	$.datepicker.regional['de'] = {
		closeText: 'schliessen',
		prevText: '&#x3c;zuruck',
		nextText: 'Vor&#x3e;',
		currentText: 'heute',
		monthNames: ['Januar','Februar','Marz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
		monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
		dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		weekHeader: 'Wo',
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''
	};

	$.fn.preloadImage = function() {};
	$.fn.centerPage = function() {};
})(jQuery);


/*
 *
 */
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();
    });
};


/*
 * Regolazione volume main flash?
 */
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}
function sendToActionScript(value) {
    thisMovie("mainFlash").sendToActionScript(value);
}
function updateSoundState(value) {
	thisMovie("mainFlash").updateSoundState(value);
}
function updateSoundVolume(value) {
	thisMovie("mainFlash").updateSoundVolume(value);
}


/*
 *
 */
function tabSfPosition(tab) {
/*	var tabLeft  = $('.tabs .tab.open').position()
	  , tabSf    = $('.bigBox .tabSf')
	  , path     = '/skin/website/widgets/sf-emozioni.png'
	  , rapporto = 1.41
	  , oldLeft  = Math.ceil(tabLeft.left)
	  , newLeft  = Math.ceil((oldLeft*rapporto)/10)*10
	  ;
  
//	if (jQuery.support.opacity) {
//		tabSf.fadeOut();
//		tabSf.css({'background-position':'-' + newLeft + 'px 0'
//				 , 'left': tabLeft.left + 90});
//		tabSf.fadeIn();
//		//tabSf.stop().fadeIn();
//	} else {
//		tabSf.hide();
//		tabSf.css({'background-position':'-' + newLeft + 'px 0'
//				 , 'left': tabLeft.left + 90});
//		tabSf.show();
//	}
	tabSf.myFadeOut();
	tabSf.css({'background-position':'-' + newLeft + 'px 0'
			 , 'left': tabLeft.left + 100});
	tabSf.myFadeIn();*/
}


/*
 * Return current site lang
 */
function getLang() {
	if ($('ul.langSound').length > 0
	 && $('ul.langSound ul li.current').length > 0) {
		var theCurrentLi   = $('ul.langSound ul li.current').attr('lang')
		  , theCurrentLang = theCurrentLi.toLowerCase()
		  , defaultLang    = 'it'
		  , lang           = (theCurrentLang != '' ? theCurrentLang : defaultLang)
			;
		return lang;
	}
};


/*
 *
 */
function sameHeight() {}


/*
 * Return current site lang
 */
function getSiteLang (lang) {
	if (lang != 'it') {
		lang = '/index-' + lang + '.php';
	} else {
		var lang = '/';
	}
	return lang;   
}


/*
 * Gestione overlay
 */
function closeOverlay() {
	//$('body').css('overflow', 'visible'); // Solo per le fauci (?)
	$('#mainOverlay').hide();
	$('#mainOverlay').remove();
	startMainFlash();

	// ripetizione del filmato dopo n secondi
	/*if (howManyTimes == 1) {
		startMainFlash();
		setTimeout("startMainOverlay()", 10000); 
	}*/
}

function startOverlay(movie, flashvars, params, attributes) {
	swfobject.embedSWF(
	    "/skin/website/swf/overlay/" + movie + ".swf"
	  , "mainOverlay"
	  , "100%", "100%"
	  , "9.0.0"
	  , "/skin/website/swf/expressInstall.swf"
	  , flashvars, params, attributes
	);
}

/* call to action overlay */
function discoverMore() {
	// DO SOMETHING
	var lang = getLang();
	if (lang == 'it') {
		window.location.href = 'http://www.gardaland.it/eraglaciale4d/?utm_source=overlay-HP-Gardaland&utm_medium=overlay&utm_campaign=Era-Glaciale';
	} else {
		window.location.href = 'http://www.gardaland.it/eraglaciale4d-' + lang + '/?utm_source=overlay-HP-Gardaland&utm_medium=overlay&utm_campaign=Era-Glaciale';
	}
}


/*
 * Gestione Main Flash
 */
function startMainFlash() {
	var flashvars = {
			basePath         : $('#baseSiteUrl').attr('title')
		  , swfPath          : "/skin/website/swf/"
		  , audio            : false
		  , soundtrackURL    : "/skin/website/swf/"
		  //, song		     : "sounds/Happy-bells3.mp3"
		  , slideshow        : false
		  , slideshowXMLPath : ""
		  , homeResort       : "/"
		  , homePark         : "http://www.gardaland.it/park" + getSiteLang($('#siteLang').attr('title'))
		  , homeHotel        : "http://www.gardalandhotel.it" + getSiteLang($('#siteLang').attr('title'))
		  , homeSealife      : "http://www.gardaland.it/sealife" + getSiteLang($('#siteLang').attr('title'))
		}
	  , params = {
			wmode           : "transparent"
		  , allowfullscreen : "false"
		  , quality         : "high"
		  , play            : "true"
		  , menu            : "false"
		  , loop            : "false"
		  , scale           : "default"
		}
	  , attributes = {}
	  //, movie = $('#mainFlash').attr('class') != '' ? $('#mainFlash').attr('class') : 'resort_home'
	  ;

	  if ($('#mainFlash').attr('class') !== ''
	   && $('#mainFlash').attr('class') !== undefined) {
		  movie = $('#mainFlash').attr('class');
	  } else {
		  movie = 'resort_home';
	  }

	 swfobject.embedSWF(
	    "/skin/website/swf/" + movie + ".swf"
	  , "mainFlash"
	  , "1246", "346"
	  , "9.0.0"
	  , "/skin/website/swf/expressInstall.swf"
	  , flashvars, params, attributes
	  //, function callbackFn(e) { $('#halloween01').show(); $('#halloween02').show(); } // Just for Halloween
	  , function callbackFn(e) { }
	);
}


/*
 * Gestione main overlay
 */
function startMainOverlay() {
	waitForSomething = true;
	howManyTimes++;

	var overlayText = {
		  it : {
		  	 testo      : "La più grande avventura 4D<br>di tutte le ere..."
		   , testoclose : "Chiudi"
		   , lingua     : "it"
		  }
		, en : {
		  	 testo      : "From the ICE AGE Saga,<br>the incredible 4D adventure!"
		   , testoclose : "Close"
		   , lingua     : "en"
		  }
		, de : {
		  	 testo      : "Von der ICE AGE Saga,<br>das unglaubliche 4D Abenteuer!"
		   , testoclose : "Zu"
		   , lingua     : "de"
		  }
	};
	var flashvars = overlayText[getLang()]
	  , params = {
			wmode           : "transparent"
		  , allowfullscreen : "false"
		  , quality         : "high"
		  , play            : "true"
		  , menu            : "false"
		  , loop            : "false"
		  , scale           : "exactfit"
		  }
	  , attributes = {}
	  , movie = '2012_eraglaciale_' + getLang()
	  ;

	if (!navigator.userAgent.match(/iPad/i)
			 && !navigator.userAgent.match(/iPhone/i)
			 && !navigator.userAgent.match(/iPod/i)
			 && !navigator.userAgent.match(/BlackBerry/i)
				) {
		//$('body').css('overflow', 'hidden'); // Solo per le fauci (?)
		startOverlay(movie, flashvars, params, attributes);
	} else {
		waitForSomething = false;
		$('#mainOverlay').hide();
	}
}

$(document).ready(function() {

	$('.page').lowerResolution();

	$('input:text[placeholder]').placeholderLabel();
	if ($('input[type=text]').length > 0) {
		$('input[type=text]').placeHolder();
	}


	/*
	 * Main Overlay
	 */
	waitForSomething = false;
	howManyTimes     = 0;
	if ($('#mainOverlay').length > 0) {
		startMainOverlay();
	}


	/*
	 * Main flash (homepages)
	 */
	if ($('#mainFlash').length > 0) {
		var template_name = $('#mainFlash').attr('class');
		if (!waitForSomething) {
			//if (swfobject.getFlashPlayerVersion()) {
			if (!navigator.userAgent.match(/iPad/i)
			 && !navigator.userAgent.match(/iPhone/i)
			 && !navigator.userAgent.match(/iPod/i)
			 && !navigator.userAgent.match(/BlackBerry/i)
				) {
				//startFlash.delay(600);
				startMainFlash();
			} else {
				$('#mainFlash').css({'background':'url(/skin/website/img/noflash/' + (template_name != '' ? template_name : 'resort_home') + '.png) no-repeat 0 0'});
			}
		}
	}

	function startStar() {
		//$('#halloween04').show();
		if ($('#winter02').length > 0) {
			var flashvars, attributes
			, params = {
				wmode           : "transparent"
			  , allowfullscreen : "false"
			  , quality         : "high"
			  , play            : "true"
			  , menu            : "false"
			  , loop            : "false"
			  , scale           : "default"
			};
			swfobject.embedSWF(
								"/skin/website/swf/stella.swf"
							  , "winter02"
							  , "150", "255"
							  , "9.0.0"
							  , "/skin/website/swf/expressInstall.swf"
							  , flashvars, params, attributes
							 );
		}

	} 

	/*
	 * Slider flash (internes)
	 */
	if ($('#sliderFlash').length > 0) {
		var module_name = $('#sliderFlash').attr('rel');
		var flashvars = {basePath         : $('#baseSiteUrl').attr('title')
					   , swfPath          : "/skin/website/swf/"
					   , audio            : false
					   , soundtrackURL    : ""
					   , slideshow        : false
					   , slideshowXMLPath : $('#slideshowXMLPath').attr('title')
					   , homeResort       : "/"
					   , homePark         : "http://www.gardaland.it/park/"
					   , homeHotel        : "http://www.gardalandhotel.it/"
					   , homeSealife      : "http://www.gardaland.it/sealife/"
					   }
		  , params = {
						wmode           : "transparent"
					  , allowfullscreen : "false"
					  , quality         : "high"
					  , play            : "true"
					  , menu            : "false"
					  , loop            : "false"
					  , scale           : "default"
					}
		  , attributes = {}
		  , movie = 'slider'
		  , playerVersion = swfobject.getFlashPlayerVersion()
		  ;

		//if (playerVersion.major) {
		if (!navigator.userAgent.match(/iPad/i)
		 && !navigator.userAgent.match(/iPhone/i)
		 && !navigator.userAgent.match(/iPod/i)
		 && !navigator.userAgent.match(/BlackBerry/i)
		 	) {
			swfobject.embedSWF(
								"/skin/website/swf/" + movie + ".swf"
							  , "sliderFlash"
							  , "1246", "266"
							  , "9.0.0"
							  , "/skin/website/swf/expressInstall.swf"
							  , flashvars, params, attributes
							  //, function callbackFn(e) { startStar(); } // Just for Winter
							 );
		} else {
			$('#sliderFlash').css({'background':'url(/skin/website/img/noflash/' + (module_name != '' ? module_name + '_interna' : 'resort_interna') + '.jpg) no-repeat 0 0'});
		}
	}


	/*
	 * Mappa parco flash
	 */
	if ($('#mappaFlashParco').length > 0) {
		var flashvars = {
				basePath         : $('#baseSiteUrl').attr('title')
			  , swfPath          : "/skin/website/swf/"
			  , audio            : false
			  , soundtrackURL    : ""
			  , slideshow        : false
			  , slideshowXMLPath : $('#slideshowXMLPath').attr('title')
			  , homeResort       : "/"
			  , homePark         : "http://www.gardaland.it/park/"
			  , homeHotel        : "http://www.gardalandhotel.it/"
			  , homeSealife      : "http://www.gardaland.it/sealife/"
			}
		  , params = {
				wmode           : "transparent"
			  , allowfullscreen : "false"
			  , quality         : "high"
			  , play            : "true"
			  , menu            : "false"
			  , loop            : "false"
			  , scale           : "default"
			}
		  , attributes = {}
		  , movie = 'mappa'
		  , playerVersion = swfobject.getFlashPlayerVersion()
		  ;

		if (playerVersion.major) {
			swfobject.embedSWF(
				"/skin/website/swf/" + movie + ".swf"
			  , "mappaFlashParco"
			  , "848", "600"
			  , "9.0.0"
			  , "/skin/website/swf/expressInstall.swf"
			  , flashvars, params, attributes
			);
		} else {
			//$('#mainFlash').css({'background':'url(/skin/website/img/noflash/' + movie + '.png) no-repeat 0 0'});
		}		
	}

	

	// Sfondo flash
	/*if ($('#mainBackground').length > 0) {
		var flashvars = {
			img: "/skin/website/img/background/01.png"
		};
		var params = {
			wmode           : "transparent"
		  , allowfullscreen : "true"
		  , quality         : "high"
		  , play            : "true"
		  , menu            : "false"
		  , loop            : "true"
		  , scale           : "default"
		};
		var attributes = {};
		swfobject.embedSWF(
			"/skin/website/swf/background.swf"
		  , "mainBackground"
		  //, "100%", "100%"
		  , $(document).width(), $(document).height()
		  , "9.0.0"
		  , "/skin/website/swf/expressInstall.swf"
		  , flashvars, params, attributes
		 );
	}*/


	/*
	 * posizione content se c'è il bigBanner o meno
	 */ 
	/*
	if ($('img.bigBanner').length > 0) {
		$('img.bigBanner').parents('.content').css('top', '-18px');
	}
	*/


	/*
	 * gestione menu langSound
	 */
	if ($('ul.langSound').length > 0) {
		//$('ul.langSound').children('li').css('width','64px');
		//$('ul.langSound').children('ul li').css('width','21px');
	}


	/*
	 * Gestione MENU principale e sottolivelli (anche TWOcol)
	 */
	var maxNumVoci = 13;
	if ($('.mainMenu ul.lev2').length > 0) {
		$('.mainMenu ul.lev2').each(function() {
			if ($('li', this).length > (maxNumVoci + 2)) {
				$(this).removeClass('oneCol');
				$(this).addClass('twoCol');
				$(this).after('<ul class="lev2 secondCol"></ul>');
				$('li', this).slice(maxNumVoci, $('li', this).length - 2).appendTo($(this).siblings('ul.lev2.secondCol'));
			}
		});
		$('.mainMenu ul.lev2').each(function() {
				$('li:first', this).addClass('moreMargin');
		});
	}
	if ($('.mainMenu ul').length > 0) {
		$('.mainBtOver').hide();
		var cssStyle = {'top':'-12px', 'left':'1px'};
		$('.mainMenu ul').superfish({
			mouseOver: function() { $('.mainBtOut', this).hide(); $('.mainBtOver', this).show().css(cssStyle);}
		  , mouseOut: function()  { $('.mainBtOver', this).hide(); $('.mainBtOut', this).show();}
		  , autoArrows  :  false
		  , delay : 300
		  , dropShadows : false
		});
	}


	/*
	 * gestione barrette liste
	 */
	if ($('#fCerca ul li').length > 0) {
		$('#fCerca ul li:last').css('background', 'none');
	}


	/* Footer
	 *
	 */
	if ($('footer ul li').length > 0) {
		$('footer ul li:last').css('border', 'none');
	}
	/*if ($('footer img.logoMerlin').length > 0) {
		var logoMerlin = $('footer img.logoMerlin');
		logoMerlin.parent('a').css('position', 'relative');
		//logoMerlin.css({'position':'absolute', 'top':'-8px', 'right':'-39px'});
		//logoMerlin.addClass("goMerlin");
	}*/


	/*
	 * gestione testine dentro i box e CAROUSEL (http://sorgalla.com/jcarousel/)
	 */
	if ($('li.box').length > 0) {
		var headTopSx = '<div class="head topSx">&nbsp;</div>'
		  , headTopDx = '<div class="head topDx">&nbsp;</div>'
		  , headBotDx = '<div class="head botDx">&nbsp;</div>'
		  , headBotSx = '<div class="head botSx">&nbsp;</div>'
			;
		$('li.box').each(function() {
			$(this).prepend(headTopSx);
			$(this).prepend(headTopDx);
			$(this).prepend(headBotDx);
			$(this).prepend(headBotSx);

			if ($('ul li', this).length > 1) {
				$('ul', this).jcarousel({visible: 1, scroll: 1, auto: 4, wrap: 'last', initCallback: mycarousel_initCallback});
			}
		});
	}


	/*
	 * Calendario datepicker http://www.eyecon.ro/datepicker/
	 */
	if ($('#fArrivo').length > 0) {
		$('#fArrivo').myDatepicker({'lang':getLang()});
	}


	/*
	 *
	 */
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}


	/*
	 * Gestione tabs homepage
	 */
	if ($('.tabs .tab').length > 0 && $('.panes .pane').length > 0) {
		$('.tabs .tab:first').addClass('open');
		$('.panes .pane').hide();
		$('.panes .pane:first').show();
		if ($('.resort.home').length > 0) {
			$('.bigBox').append('<div class="tabSf">&nbsp;</div>');
			tabSfPosition($('.tabs .tab:first').attr('title'));
		}

		$('.tabs .tab a').mouseover(function() {
			//if ($(this).parent('li').hasClass('open')) {
			//} else {$(this).parent('li').addClass('open');}
		}).mouseout(function() {
			//$(this).parent('li').removeClass('open');
		}).click(function() {
			$('.tabs .tab').removeClass('open');
			$('.panes .pane').hide();
			if ($('.resort.home').length > 0) { $('.bigBox .tabSf').hide();}
			var tab = $(this).attr('href');
			tab = tab.replace('#', '');

			$(this).parent('li').addClass('open');
			if ($('.resort.home').length > 0) {
				tabSfPosition(tab);
				$('.bigBox .tabSf').show();
			}
			$('.panes .pane[id=' + tab + ']').myFadeIn();
			return false;
		});

		if ($('.panes .pane ul.col_0').length > 0) {
			$('.panes .pane ul.col_0').each(function() {
				var maxNumLi = $(this).attr('title')
				  , totLi = $('li', this).length
				  , totUl     = totLi / maxNumLi
				  , myFather  = $(this).parent('.pane')
				  ;
				for (i=1; i<totUl; i++) {
					$(myFather).append('<ul class="col_' + i + '"></ul>');
				}
				for (i=0; i<totUl; i++) {
					if (i > 0) {
						$('li', this).slice(maxNumLi, maxNumLi*2).appendTo($(this).siblings('.col_' + i));
					}
				}
			});	
		}
	}


	/*
	 *
	 */
	if ($('#attrazioni ul').length > 0) {
		$('.resort.home #attrazioni ul').jcarousel({visible: 5, scroll: 5, auto: 4, wrap: 'last', initCallback: mycarousel_initCallback});
		$('.park.home #attrazioni ul').jcarousel(  {visible: 4, scroll: 4, auto: 4, wrap: 'last', initCallback: mycarousel_initCallback});
	}
	if ($('#attzCarousel li').length > 1) {
		$('#attzCarousel').jcarousel({visible: 1, scroll: 1, auto: 4, wrap: 'last', initCallback: mycarousel_initCallback
});
	}
	if ($('.jcarousel-skin-generica li').length > 1) {
		$('.jcarousel-skin-generica').jcarousel(  {visible: 1, scroll: 1, auto: 4, wrap: 'last', initCallback: mycarousel_initCallback});
	}


	/*
	 *
	 */
	if ($('#gMiniGallery').length > 0) {
		$('#gMiniGallery li').each(function(e) {
			var n = ((e + 1) / 4)
			  , isInt = (Math.floor(n) == n ? true : false)
			  ;
			if (isInt) {
				$(this).css('margin-right', '0');
			}
		});
	}


	/*
	 *
	 */
	function thisMediaBt() {
		$('#medias a').each(function() {
			var src = $('img', this).attr('src');
			if (src) {
				var extension = src.substring(src.lastIndexOf('-'), src.length);
				if ($(this).hasClass('thisMedia')) {
					$('img', this).attr('src', src.replace(extension,'-on.png'));
				} else {
					$('img', this).attr('src', src.replace(extension,'-off.png'));
				}
			}
		});
	}
	function thisMedia(media) {
		if ($('.media').length > 0 ) {
			$('.media').hide();
		}
		
		if (media) {
			$(media).show();
		} else {
			$('.media:first').show();
		}
	}
	if ($('#medias a').length > 0) {	
		thisMedia();	
		thisMediaBt();
		$('#medias a').click(function() {
			if ($(this).hasClass('thisMedia')) {
				return false;
			} else {
				$('#medias a').removeClass('thisMedia');
				$(this).addClass('thisMedia');
				thisMediaBt();
			}
			var media = $(this).attr('href');
			thisMedia(media);

			if ($(this).attr('href') == '#ytInclude') {
				loadPlayer();
				$('#videoInfo').show();
			}

			return false;
		});
	}


	/*
	 * Gestione on/off del controllo volume
	 */
	if ($('img.volumeControl').length > 0) {
		var imgControl = $('img.volumeControl')
		  , src        = imgControl.attr('src')
		  , ext        = src.substring(src.lastIndexOf('.'), src.length)
		  , newSrc     = src.replace(ext,'_off' + ext)
		  ;

		imgControl.css('cursor','pointer');
		imgControl.toggle(
			function () { $(this).attr('src', newSrc);}
		  , function () { $(this).attr('src', src);}
		);
	}


	/*
	 * Gestione overlay pacchetti hotel
	 */
	if ($('#pacchettiHomeList li').length > 0) {
		$('.maskMe3First').maskMe({src: '/skin/website/widgets/mask-colspan3.png'});
		$('.maskMe3').maskMe({src: '/skin/website/widgets/mask-colspan1.png'});
		$('.maskMe2').maskMe({src: '/skin/website/widgets/mask-colspan1.png'});
		$('.maskMe1').maskMe({src: '/skin/website/widgets/mask-colspan1.png'});
		$('.maskMeDetail').maskMe({src: '/skin/website/widgets/mask-detail.png'});

		$('.packDetail').each(function(e) {
			if (e == 0) {
				$(this).before('<img src="/skin/website/widgets/bt-plus2.png" width="24" height="24" class="btPlus" alt="" />');
			} else {
				$(this).before('<img src="/skin/website/widgets/bt-plus.png" width="18" height="18" class="btPlus" alt="" />');
			}
		});

		$('.btPlus').click(function(e) {
			var detail = $(this).siblings('.packDetail')
			  , offset = $(this).offset()
				;
			$('<div class="cloneDetail"></div')
					.html(detail.clone())
					.appendTo('body')
					.show()
					.center({offsetX: -(offset.left/10), offsetY: -(offset.top/10)})
					.draggable({ 
						 opacity: 0.8
					   , start: function () {
									$('.cloneDetail').css('z-index', 2000);
									$(this).css('z-index', 2001);
								}
			}).mousedown(function() {
				$('.cloneDetail').css('z-index', 2000);
				$(this).css('z-index', 2001);				
			});
		});

		$('.btChiudi').live('click', function() {
			var cloneDet = $(this).parents('.cloneDetail');
			cloneDet.myFadeOut({speed: "fast", func: function() { cloneDet.empty(); }} );
		});

		var KEYCODE_ESC = 27;
		$(document).keyup(function(e) {
			if (e.keyCode == KEYCODE_ESC) {
				$('.cloneDetail').myFadeOut({speed: "fast"
										   , func: function() {$('.cloneDetail').remove();}
										   });
			} 
		});
	}


	/*
	 *
	 */
	if ($('#fNewsletter').length > 0) {
		$('#fNewsletter').myValidation();
	}


	/*
	 *
	 */
	if ($('.multiBox.half').length > 0) {
		$('.multiBox.half:odd').css('left', '18px');
		$('.multiBox.half:even').css('clear', 'left');
	}


	/*
	 *
	 */
	if ($('.gTesto table').length > 0) {
		var color = '#71ac33'; // DEFAULT;
		if ($('.resort').length > 0) {
			var color = '#e7c660';
		}
		if ($('.park').length > 0) {
			var color = '#71ac33';
		}
		if ($('.hotel').length > 0) {
			var color = '#e06495';
		}
		if ($('.sealife').length > 0) {
			var color = '#0096e0';
		}
		$('.gTesto table tr:even').css('background-color', color);
		$('.gTesto table tr').each(function() {
			$('td:first', this).css('padding-left', '43px');
		});
	}


	/*
	 *
	 */
	if ($('#gForm').length > 0) {
		$('input').focus(function() {
			$(this).addClass('focus');
			$(this).prev('label').addClass('focus');
		}).focusout(function() {
			$(this).removeClass('focus');
			$(this).prev('label').removeClass('focus');
		});
		if ($('p.right').length > 0) {}
	}


	/*
	 *
	 */
	if ($('.colCx .testi ol').length > 0) {
		$('.colCx .testi ol').each(function() {
			$('li', this).each(function(e) {
				var num = e +1;
				$(this).prepend('<span class="customNumber">' + num + '.</span>');
			});
		});
	}


	/*
	 * Gestione checkbox form
	 */
	if ($(".gTesto.formContattaci").length > 0) {
		$("#chk-resort").click(function() {
			checkboxList = $(this).parents("fieldset").find("input[type=checkbox]"
														  + "[id!=" + $(this).attr("id") + "]"
														  + "[id!='chk-insegnanti']");
			if ($(this).is(":checked")) {				
				checkboxList.bind("click", function() {
					$(this).attr("checked", "checked");
					return false;
				}).trigger("click");
			} else {
				checkboxList.unbind("click").trigger("click");
			}
		});
	}

	if ($(".gTesto.formNewsletter").length > 0) {
		$("#chk-resort").click(function() {
			checkboxList = $(this).parents("fieldset").find("input[type=checkbox][id!=" + $(this).attr("id") + "]");
			if ($(this).is(":checked")) {				
				checkboxList.bind("click", function() {
					$(this).attr("checked", "checked");
					return false;
				}).trigger("click");
			} else {
				checkboxList.unbind("click").trigger("click");
			}
		});		
	}


	/*
	 * Gestione pagina faq
	 */
	if ($(".faq-page").length > 0) {
		form = $(this).find("form.searchFaq");
		
		// Gestione ricerca in ajax
		$("input[name=cerca-faq]").keyup(function(e) {			
			if (e.keyCode == 13) {
				return false;
			}
			
			cercaVal = $("input[name=cerca-faq]").val();
			loader = $("img.loader");
			if (cercaVal.length < 3) {
				return false;
			}
			$.ajax({
				  url: form.attr('action')
				, type: 'GET'
				, data: 'cerca-faq=' + cercaVal
				, dataType: 'json'
				, beforeSend: function() {				
					loader.show();
				}
				, success: function(json) {					
					$(".boxFaqs").each(function() {
						// Per ogni categoria scorro le sue faq, e se sono presenti
						// nel json le mostro, altrimenti le nascondo
						visible = 0;
						$(this).find(".single-faq").each(function() {							
							// Recupero testo e pulisco da eventuali span con class 'search'
							textObj = $(this).find('div.text');
							text = textObj.html();
							textReplace = text.replace(new RegExp('<span class="search">', 'g'), '');
							textReplace = textReplace.replace(new RegExp('</span>', 'g'), '');
							text = textReplace;
														
							idFaq = parseInt($(this).attr('id').substring(4));
							if (in_array(idFaq, json)) {
								textReplace = text.replace(new RegExp(cercaVal, 'g'), '<span class="search">' + cercaVal + '</span>');
								textObj.html(textReplace);
								$(this).removeClass('hidden');
								visible++;								
							} else {
								$(this).addClass('hidden');
							}
						});
												
						// Se nessuna faq � visibile per questa categoria, chiudo anche il box
						titleH1 = $(this).parents("div.box-faq-category").find("h1");
						if (! visible) {
							$(this).addClass('hidden');
							titleH1.removeClass('open');
						} else {
							$(this).removeClass('hidden');
							titleH1.addClass('open');
						}
					});
					
					// Visualizzo messaggio e form di richiesta nel caso non ho nessun risultato
					if (! json.length) {						
						$(".messageFaq").removeClass('hidden');
						$(".formRichieste").removeClass('hidden');
					} else {						
						$(".messageFaq").addClass('hidden');
						$(".formRichieste").addClass('hidden');
					}
					loader.hide();
				}
			});
			
		});
		
		// Gestione apertura e chiusura faq
		$(".linkBoxFaqs h1").click(function() {
			divBoxFaqs = $(this).parents("div.box-faq-category").find("div.boxFaqs");
			if (divBoxFaqs.hasClass("hidden")) {
				divBoxFaqs.removeClass("hidden");
				$(this).addClass("open");				
			} else {
				divBoxFaqs.addClass("hidden");
				$(this).removeClass("open");
			}
		});
		
		form.submit(function() {			
			return false;
		});
	}


	/*
	 *
	 */
	if ($('#gForm').length > 0) {
		if ($('#res_nazione').length > 0) {
			$('#res_nazione').change( function(){
				if ($(this).val() != 'IT') {
					$('#res_provincia').hide();	
				} else {
					$('#res_provincia').show();
				}
			});
		}
	
		if ($('#dom_nazione').length > 0) {
			$('#dom_nazione').change( function(){
				if ($(this).val() != 'IT') {
					$('#dom_provincia').hide();	
				} else {
					$('#dom_provincia').show();
				}
			});
		}
	
		if ($('#titolo_studio').length > 0) {
			$('#titolo_studio').change(function(){
				if ($(this).val() != 'elementare' && $(this).val() != 'media' ) {
					$('p#spec_titolo_studio').show();
				} else {
					$('p#spec_titolo_studio').hide();
				}
			});
		}
	
	}
	
	var newsletterInsegnantiCheckedOnLoad = $("#chk-insegnanti").is(':checked');
	if (newsletterInsegnantiCheckedOnLoad) {
		$('#campi-aggiuntivi-insegnanti').show("fast");
	}
	
	$('#chk-insegnanti').click(function(){
		var newsletterInsegnantiChecked = $(this).is(':checked');
		if (newsletterInsegnantiChecked) {
			//$('#campi-aggiuntivi-insegnanti').show("fast");
			$('#campi-aggiuntivi-insegnanti').css("display", "block");
		} else {
			//$('#campi-aggiuntivi-insegnanti').hide("fast");
			$('#campi-aggiuntivi-insegnanti').css("display", "none");
		}
	});


	/*
	 *
	 */
	var soundStatus = true;
	if ($('.volumeControl').length > 0) {
		$('.volumeControl').click(function(){
			if (soundStatus){
				thisMovie("mainFlash").updateSoundState(0);
				soundStatus = false;
			} else {
				thisMovie("mainFlash").updateSoundState(1);
				soundStatus = true;
			}
		});		
	}


	/*
	 *
	 */
	$('.tableToShow').mouseover(function(){
		$(this).css('cursor','pointer');
		$(this).find('.hide').fadeIn('slow').removeClass('hide');	
		
		if ($(this).attr('lang') != 'yes') {
			//aggiungo l'altezza alle colonne e rimuovo la classe
			var colSx = $('.colsContainer .colSx').height();
			var colCx = $('.colsContainer .colCx').height();
			var primarigaHeight = $(this).find('.primariga').height();
			var finalHeight1 = colSx + $(this).height() - primarigaHeight;
			var finalHeight2 = colCx + $(this).height() - primarigaHeight;
			$('.colsContainer .colSx').height(finalHeight1);
			$('.colsContainer .colCx').height(finalHeight2);
		}
		$(this).attr('lang', 'yes');
	});


	/*
	 * Gestione icone attrazioni (foto e negozio)
	 */
	if ($(".ico-attr").length) {		
		$("div.icon img.image").hover(
			function() {
				boubleDiv = $(this).parents("div.icon").find("div.bouble");				
				boubleDiv.removeClass("hidden");
			}
			, function() {
				boubleDiv = $(this).parents("div.icon").find("div.bouble");				
				boubleDiv.addClass("hidden");
			}
		);
	}


	/*
	 * Gestione FILTRI attrazioni
	 */
	if ($('#filtroAttz')) {
		$('.filtri ul').each(function() {
			$('li', this).click(function() {
				var isOn = $(this).hasClass('on');
				if (isOn) {
					$(this).removeClass('on');
				} else {
					$(this).addClass('on');
				}
			});
		});
	}


	/*
	 * Gestione FORM
	 */
	if ($('.colCx legend').length > 0) {
		$('.colCx legend').each(function() {
			$(this).after('<p class="legend">' + $(this).text() + '</p>');
			$(this).remove();
		});
	}


	/*
	 * Vertical menu
	 */
	if ($('#vMenu').length > 0 && $('.park').length > 0) {
		var bullet = '<div class="attzBullet">'
				   + '<img src="/skin/website/widgets/bullet-attz.png" width="6" height="17" />'
				   + '</div>'
				   ;
		$('#vMenu li').each(function() {
			if ($(this).hasClass('color')) {
				var style = $(this).attr('style')
				  , color = $(this).css('border-left-color')
				  ;
				$('>a', this).append(bullet);
				$('a .attzBullet', this).css('background-color', color);
			}
		});
	}


	/*
	 * FILTRO ATTRAZIONI
	 */
	if ($('#filtroAttz').length > 0) {
		var bsu = $('#filtroAttz').attr('title')
		  , buttons = $('#filtroAttz .filtri li')
		  , buttonsOn = $('#filtroAttz .filtri li.on')
		  , loading = '<p id="loading">Loading ...</p>'
		  , noResults = '<p id="noResults">No results</p>'
		  , returnHtml = function(params) {
				$.ajax({url: bsu + "/park/action/filter-results"
				     , async: false
					 , data: params
					 , beforeSend : function(){$('#risultati').empty().append(loading);}
					 , success: function(html){
							if (html != '') {
								$('#risultati').empty().append(html);
							} else {
								$('#risultati').empty().append(noResults);
							}
							sameHeight(false);
						 }
					 }).responseText;
				}
		  ;

		$('#filtroAttz').removeAttr('title');

		function startAjax() {
			var cat = ''
			  , alt = ''
			  , eta = ''
			  , params
			  ;
			$('#filtroAttz .filtri li.on').each(function() {
				var currId = $(this).attr('id')
				  , currId = currId.split('_')
				  ;
				if (currId[0] == "cat") { cat += $(this).attr('id'); }
				if (currId[0] == "alt") { alt += $(this).attr('id').replace('alt', ''); }
				if (currId[0] == "eta") { eta += $(this).attr('id').replace('eta', ''); }
			});
			alt = alt.substr(1, alt.length); 
			eta = eta.substr(1, eta.length);
			params = { cat: cat, alt: alt, eta: eta };

			returnHtml(params);
		}

		if ($('#filtroAttz .filtri li.on').length > 0) {
			//setTimeout();
			startAjax();
		}

		buttons.click(function() {
			startAjax();
		});
	}





	/*if ($('.titoloPagina').length > 0) {
		$('.titoloPagina').
	}*/
	/*var delayInterval = 0;
	$('body').css('overflow', 'hidden');
	$('.icons li').each(function() {
		$(this).css('left', '-5000px');
		//$(this).animate({"left":0},2000, "easeOutElastic");
		
	    if (delayInterval > 0) $(this).delay(delayInterval);
	    $(this).animate({"left":0},1000, "easeOutElastic");
	    delayInterval += 300;
	});*/
	























	/*
	 *
	 */
	if ($('#donna_taglia_giacca').length > 0) {
		$('#donna_taglia_giacca').change(function(){
			if ($(this).val() == 'Altro' ) {
				$('p#donna_specifica_taglia_giacca').show();
			} else {
				$('p#donna_specifica_taglia_giacca').hide();
			}
		});			
	}
	if ($('#uomo_taglia_giacca').length > 0){
		$('#uomo_taglia_giacca').change(function(){
			if ($(this).val() == 'Altro' ) {
				$('p#uomo_specifica_taglia_giacca').show();
			} else {
				$('p#uomo_specifica_taglia_giacca').hide();
			}
		});	
	}
	if ($('#donna_taglia_gonna_pant').length > 0){
		$('#donna_taglia_gonna_pant').change(function(){
			if ($(this).val() == 'Altro' ) {
				$('p#donna_specifica_taglia_gp').show();
			} else {
				$('p#donna_specifica_taglia_gp').hide();
			}
		});		
	}
	if ($('#uomo_taglia_gonna_pant').length > 0) {
		$('#uomo_taglia_gonna_pant').change(function(){
			if ($(this).val() == 'Altro' ) {
				$('p#uomo_specifica_taglia_gp').show();
			} else {
				$('p#uomo_specifica_taglia_gp').hide();
			}
		});	
	}
	$('#donna_taglia_camicia').change(function(){
		if ($(this).val() == 'Altro' ) {
			$('p#donna_specifica_taglia_camicia').show();
		} else {
			$('p#donna_specifica_taglia_camicia').hide();
		}
	});
	$('#uomo_taglia_camicia').change(function(){
		if ($(this).val() == 'Altro' ) {
			$('p#uomo_specifica_taglia_camicia').show();
		} else {
			$('p#uomo_specifica_taglia_camicia').hide();
		}
	});
	if ($('select#sesso').length > 0) {
		$('select#sesso').change(function(){
			if ($(this).val() == 'F') {
				$('fieldset.info_donna').show();
				var heightFieldset = $('fieldset.info_donna').height();
				$('fieldset.info_uomo').hide();
			}
			if ($(this).val() == 'M') {
				$('fieldset.info_donna').hide();
				$('fieldset.info_uomo').show();
			}
			if ($(this).attr('title') != 'true') {
				var colCx = $('.colsContainer .colCx').height();
				$('.colsContainer .colSx').height(colCx + heightFieldset);
				$('.colsContainer .colCx').height(colCx + heightFieldset);	
			}
			$(this).attr('title', 'true');
		});
	}


	/*
	 *
	 */
	var overPopup = false;	


	/*
	 *
	 */
	if ($('.icona').length > 0) {
		$('.icona').hover(
			function(){
				var strings = ($(this).attr('id')).split('_');
				var idIcona = strings[0];
				// riga e colonna utili per il posizionamento del baloon
				// la costante è 23px, dimensione dell'iconcina
				var riga = strings[1];
				var colonna = strings[2];
				var costante = 23;
				var ombra = 5;
				var leftNegativo = 89;
				
				$('.tooltip_restrizione').each(function(index, element){
					if ($(this).attr('id') != ('tooltip_'+idIcona)) {
						$(this).hide();
					} else {
						var larghezza = -(leftNegativo - (colonna*costante));
						var altezza = -($(this).height() - (riga*costante));
						
						$(this).css('top', altezza);
						$(this).css('left', larghezza);
						
						$(this).show();
					}
				});
			},
			function(){
				var strings = ($(this).attr('id')).split('_');
				var idIcona = strings[0];

				$('#tooltip_'+idIcona).delay(3000).fadeOut();
			}			
		);
	}



	/* Gestione analytics link esterni verso booking.ihotelier.com
	 *
	 */
	if ($('.hotel .testi a[href^="https://booking.ihotelier.com/"]').length > 0) {
		$('.hotel .testi a[href^="https://booking.ihotelier.com/"]').each(function(e) {
			var href = $(this).attr('href');
			$(this).removeAttr('onclick');
			$(this).click(function() {
				//_gaq.push(['_link', href]);
				//return false;
				pageTracker._link(href);
				return false;
			});
		});
	}


	/*
	 *
	 */
	$('.ico_question').mouseover(function(){
		$(this).css('cursor', 'pointer');
		$('#testo_' + $(this).attr('id')).show();
	}).mouseout(function(){
		$('#testo_' + $(this).attr('id')).hide();
	});	


	/*
	 *
	 */
	$('#giastato_no').click(function(){
		$('#primavolta').attr("disabled","disabled");
		$('#ultimianni').attr("disabled","disabled");
		$('#tornarci_si').attr("disabled","disabled");
		$('#tornarci_yes').attr("disabled","disabled");
		$('#tornarci_no').attr("disabled","disabled");
	});
	$('#giastato_si').click(function(){
		$('#primavolta').removeAttr('disabled');
		$('#ultimianni').removeAttr('disabled');
		$('#tornarci_si').removeAttr('disabled');
		$('#tornarci_yes').removeAttr('disabled');
		$('#tornarci_no').removeAttr('disabled');
	});	
	$('#giastato_yes').click(function(){
		$('#primavolta').removeAttr('disabled');
		$('#ultimianni').removeAttr('disabled');
		$('#tornarci_si').removeAttr('disabled');
		$('#tornarci_yes').removeAttr('disabled');
		$('#tornarci_no').removeAttr('disabled');
	});	
});



/*
 *
 */
$(window).resize(function() {
	$('.page').lowerResolution();
});



/*
 *
 */
function updateSoundState(value) {
	thisMovie("mainFlash").updateSoundState(value);
}



/*
 * Checks if the given value exists in the array 
 */
function in_array (needle, haystack, argStrict) {
    var key = '',        strict = !! argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {                return true;
            }
        }
    } else {
        for (key in haystack) {            if (haystack[key] == needle) {
                return true;
            }
        }
    } 
    return false;
}
