function Modal(){
    var e = $("#modal");
    var w = $("#modal").width();
    var screenW = $(document).width();
    e.css({
        top: "200px",
        left: (screenW-w)/2+"px"
    });
    $("#fade").fadeTo('', '0.33').css({
        height: $("body").height()
    });
    e.fadeIn();
}
function hideModal() {
    $("#modal").fadeOut();
    $("#fade").fadeTo('', '0').css({
        display: 'none'
    });
}
// validate an email address
function isEmail(strEmail, lblAlert){
	validRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (strEmail.search(validRegExp) == -1) {
	  alert(lblAlert);
	  return false;
	}
	return true;
}
// verify a privacy checkbox
function ctrlPrivacy(alertChkPrivacy){
	var bConsenso;
	bConsenso = document.form1.chkPrivacy.checked;
	if (bConsenso){
		document.form1.Submit.disabled = false;
                jQuery('.button').css({'opacity':'1','cursor':'pointer'});
	} else {
		document.form1.Submit.disabled = true;
                jQuery('.button').css({'opacity':'0.3','cursor':'default'});
		alert(alertChkPrivacy);
	}
}	  
// add extra form parameters to an element href
function addParams(id, parameters) {	
	var uri = jQuery("a#"+id).attr('href');
	jQuery("a#"+id).click(function() {
		var uriparms = "?";
		var tmp = "";
		jQuery.each(parameters, function(index, value) {										 
			if(jQuery("input[name='"+value+"']").is(":checkbox") || jQuery("input[name='"+value+"']").is(":radio")) {
				jQuery("input[name='"+value+"']:checked").each(function() { tmp = tmp+jQuery(this).val()+",";});																				   
				var inputval = tmp.slice(0, -1);
				//alert(inputval);
			} else {				
					var inputval = jQuery("input[name='"+value+"']").val();				
			}			
			if(inputval) uriparms = uriparms+value+"="+inputval+"&";
		});
		uriparms = escape(uriparms.slice(0, -1));
		jQuery(this).attr('href', uri+uriparms);
		//alert(jQuery(this).attr('href'));
	});	  
}
$(document).ready(function(){
    $("select").select_skin();
    $('#scrollbar, #scrollbar2').tinyscrollbar({sizethumb:50});
    $("a.m1").prettyPhoto({custom_markup: '<iframe src="/styles/tirano.html" width="100%" height="600" frameborder="0" scrolling="no" />'});
    $("a.m2").prettyPhoto({custom_markup: '<iframe src="/styles/aprica.html" width="100%" height="600" frameborder="0" scrolling="no" />'});
    $("a.m3").prettyPhoto({custom_markup: '<iframe src="/styles/costarei.html" width="100%" height="600" frameborder="0" scrolling="no" />'});
    $("a.m4").prettyPhoto({custom_markup: '<iframe src="/styles/mezzana.html" width="100%" height="600" frameborder="0" scrolling="no" />'});
    $("a.m5").prettyPhoto({custom_markup: '<iframe src="/styles/pontedilegno.html" width="100%" height="600" frameborder="0" scrolling="no" />'});
    /* Newsletter */
    $('#subscribe').hide();
    $('#click').click(function(){
        $('#subscribe').slideToggle(500, function() {
        if ($('#subscribe').is(':visible')){
            $('#click b').removeClass('open');
            $('#click b').addClass('close');
        } else {
            $('#click b').removeClass('close');
            $('#click b').addClass('open');
        }
        });
    });
    $('.button').hover(function(){
        $(this).css('background-position','bottom')
    }, function(){
        $(this).css('background-position','top')    
    });
    /* scelta della lingua */
    $('.sel').prependTo('.lang');
    $('.lang a').not('.sel').hide();
    $('.lang').hover(function(){
        $('.lang a').not('.sel').slideDown(300);
        $('.lang a').not('.sel').addClass('notsel');
    },
    function(){
        $('.lang a').not('.sel').slideUp(300);
    });
    /* apre i sottomenu */
    $(" #nav ul ").css({
        display: "none"
    }); // Opera Fix
    $(" #nav li").hover(function(){
        $(this).find('ul:first').show();
        $(this).find('a:first').not('.first, .continue').addClass('up');
    },function(){
        $(this).find('ul:first').hide();
        $(this).find('a:first').not('.first, .continue').removeClass('up');
    });
    /* pulsante booking engine */
    $('.BEscriptoh14').hover(function(){
        $(this).css('background-position','bottom')
    }, function(){
        $(this).css('background-position','top')    
    });    
    /* cambia l'immagine dei luoghi */
    $('.places div').hover(function(){
        $(this).children('img').fadeOut(500);
    },
    function(){
        $(this).children('img').fadeIn(500);
    });
    /* effetto sulle immagini del footer */
    $('.foot img').hover(function(){
        $(this).fadeTo(200,0.3) 
    }, function(){
        $(this).fadeTo(200,1) 
    });
    /* tab delle località */
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active");
        $(this).addClass("active");
        $(".tab_content").hide();
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn();
        return false;
    });
    /* anchor webcam */
    $('.webcam a, .webcam_aprica a').hover(function() {
        $(this).attr('target','_blank');
    }, function(){
        $(this).removeAttr('target','_blank');
    });
});
