﻿/*
//Common Javascript Costa Crociere 
//In this JavaScript is checked:
//- the height of Hot Deals
//- Tab in ExpressBooking HomePage
//- Submenu
//- Faqs Carousel HP
//- Toggle Footer
//- Tooltip
//- New Search
//- Show Hide Description Detail Cruice
//- Tab Description Detail Cruice
//- Utility Layer (resize-center-scroll)
//- Layer
//- Clear Input
//- Show Cabin Details
//- Tab Layer
//- Change Country
*/

var CostaUi = {};

//Hot Deal Height//
CostaUi.setMaxHotDealHeight = function () {
    var maxHeight = 0;
    var maxImgHeight = 0;
    var $hotDealBoxes = $("div.hot-deal");
    for (var i = 0; i < $hotDealBoxes.length; i++) {
        var boxHeight = parseInt($($hotDealBoxes[i]).outerHeight(), 10);
        maxHeight = Math.max(maxHeight, boxHeight);
        var imgHeight = parseInt($($hotDealBoxes[i]).find("img.promo").height(), 10);
        maxImgHeight = Math.max(maxImgHeight, imgHeight);
    }

    $("div.hot-deal").css("height", (maxHeight + maxImgHeight) + "px");
    $("div.hot-deal p").css("height", (maxHeight - 10) + "px");
    $("div.hot-deal img.promo").css({ bottom: "0px", left: "0px" });
    $("div.deal").css("height", (maxHeight + maxImgHeight) + "px");
}


CostaUi.setMaxElentHeight = function ()
{
    var maxHeight;
    var elementList = $(".row");
    $(elementList).each(function ()
    {
        maxHeight = 0;
        $this = $(this).children("div");

        for (var i = 0; i < $this.length; i++)
        {
            if ($(this).is(".noSetMaxElentHeight"))
            {
                return;
            }
            var boxHeight = parseInt($($this[i]).outerHeight(), 10);
            maxHeight = Math.max(maxHeight, boxHeight);
        }
        for (var i = 0; i < $this.length; i++)
        {
            var boxPadding = parseInt($($this[i]).css("padding-top"), 10) + parseInt($($this[i]).css("padding-bottom"), 10);
            $($this[i]).css("height", (maxHeight - boxPadding) + "px");
        }
    });
    
}


//Tab Reservation Home//
CostaUi.controllTabExpressBooking = function ()
{
    $("div.express-booking div").first().show();
    $("div.express-booking ul li:first").addClass("on");
    $("div.express-booking ul li a").click(function ()
    {

        var nameSplit = $(this).parent().attr("class").split(" on");
        var nameLink = nameSplit[0];
        if ($("div.express-booking div." + nameLink + "").css("display") == "block")
            return;
        $("div.express-booking div").hide();
        $("div.express-booking div." + nameLink).show();
        $("div.express-booking ul li").removeClass("on");
        $(this).addClass("on");
        $(this).parent().addClass("on");
        $(".advanced-search").hide();
        $(".findPrenotationNumber").hide();
        $(".prenotationNumber").show();
        $("a.findPrenotationNumber").show();
        $("a.advanced-search").show();
		
		// verifica espansione campi hidden di ricerca
		if ($(".showAllFields").attr("class") == "showAllFields on")
		{
		    $("#advanced-search-ul-port").show();
		    $("#advanced-search-ul-ship").show();
		}
		
        return;
    });

    $("a.advanced-search").click(function ()
    {
        $(".advanced-search").show();
        $(this).hide();
    });

    $("a.findPrenotationNumber").click(function ()
    {
        $(this).parent().parent().find(".prenotationNumber").hide();
        $("a.prenotationNumber").show();
        $(".ctn-input-data").show();
        $(".findPrenotationNumber").show();

    });

    $("a.prenotationNumber").click(function ()
    {
        $(this).parent().parent().find(".findPrenotationNumber").hide();
        $("a.findPrenotationNumber").show();
        $(".prenotationNumber").show();

    })
}

//SubMenu Position//
CostaUi.subMenuPosition = function ()
{
    var leftPosition = 5;
    var $subMenu = $(".main-menu .ctn-subMenu");
    for (var i = 0; i < $subMenu.length; i++)
    {
        $subMenu.eq(i).find("ul").css({ left: leftPosition + "px" });
        leftPosition += parseInt($subMenu.eq(i).width(), 10) + parseInt($subMenu.eq(i).css("padding-left"), 10) + parseInt($subMenu.eq(i).css("padding-right"), 10);
    }
}

//SubMenu Controll//
var t = null;

CostaUi.subMenu = function ()
{
    $("ul.main-menu li.ctn-subMenu").mouseover(function ()
    {
        if (t != null)
        {
            window.clearTimeout(t);
            t = null;
        }
        CostaUi.openSubMenu($(this));
    });

    $("ul.main-menu li.ctn-subMenu").mouseout(function ()
    {
        if (t != null)
        {
            window.clearTimeout(t);
            t = null;
        }
        var $this = $(this);
        t = window.setTimeout(function () { CostaUi.closeSubMenu($this); }, 300);
    });
}

    //open
    CostaUi.openSubMenu = function ($this)
    {
        if ($this.find("ul").css("display") == "block")
        return;
        $("ul.main-menu li ul").hide();
        $("ul.main-menu li.on").removeClass("on");
        $this.find("ul").show();
        $this.addClass("on");
    }

    //close
    CostaUi.closeSubMenu = function ($this)
    {
        $("ul.main-menu li ul").hide();
        $("ul.main-menu li").removeClass("on");
    }

//Faqs Carousel HP//
    CostaUi.moveLeft = function ()
    {
        var widhtAnimation = $("div.carousel ul li").width();
        $("div.carousel ul").animate({
            left: "-" + widhtAnimation + "px"
        }, 500, CostaUi.removeAddLeft);
    }

CostaUi.moveRight = function ()
{
    var widhtAnimation = $("div.carousel ul li").width();
    $("div.carousel ul").animate({
        left: widhtAnimation + "px"
    }, 500, CostaUi.removeAddRight);
}

CostaUi.removeAddLeft = function ()
{
    var firstElemt = $("div.carousel ul li:eq(0)");
    $(firstElemt).remove();
    $("div.carousel ul").css("left", "0px");
    $("div.carousel ul").append(firstElemt);
}

CostaUi.removeAddRight = function()
{
    var thirdElement = $("div.carousel ul li:last");
    $(thirdElement).remove();
    $("div.carousel ul").css("left", "0px");
    $("div.carousel ul").prepend(thirdElement);
}

CostaUi.carousel = function()
{
    $(".arrow-sx a").click(function ()
    {
        CostaUi.moveLeft();
    });
    $(".arrow-dx a").click(function ()
    {
        CostaUi.moveRight();
    });
}

// Toggle Footer //
CostaUi.toggleFooter = function ()
{

    $(".menu-footer a").attr("rel", "elementToggle").click(function ()
    {
           
           
        $(".menu-footer li a").removeClass("on");
        var elementToToggle = $(this).attr("class");
        var element = $("ul." + elementToToggle);
        if (element.css("display") == "block")
        {
            element.slideUp();
            return;
        }
        $("ul.ctn-idden-useful-links").slideUp();
        $(this).addClass("on");
        element.slideDown();
    })

}

// Tooltip //
CostaUi.tooltip = function (target_items, name)
{
    $(target_items).each(function (i)
    {   
        
       
        $("body").append("<div class='" + name + "' id='" + name + i + "'><p>" + $(this).attr('title') + "</p></div>");
        var my_tooltip = $("#" + name + i);

        $(this).removeAttr("title").mouseenter(function ()
        {
            my_tooltip.css({ opacity: 0.9, display: "none" }).fadeIn(200);
        }).mousemove(function (kmouse)
        {
            my_tooltip.css({ left: kmouse.pageX + 15, top: kmouse.pageY - 50 });
        }).mouseleave(function ()
        {
            my_tooltip.fadeOut(200);
        });
    });
}

// New Search //
CostaUi.newSearch = function ()
{
    $("p.new-search a").click(function ()
    {
        $(this).parent().hide();
        $("span.new-search").fadeIn();
    })
}

// Show Hide Description Detail Cruice //
CostaUi.showDetail = function ()
{
    $(".activateShowHide").click(function ()
    {
        //$(".description").hide();
        $(this).parent().parent().next(".description").toggle();
    });
    
    $(".showDetail").click(function ()
    {
		var elemtProperty = $(this).parent().find(".description").css("display");
		
		if( elemtProperty == "none"){
			
		$(this).parent().find("a.showDetail").hide();
        $(this).parent().find("a.arrow").show();
        $(this).parent().find(".description").show();
        $(this).parent().find("a.arrow").addClass("open");
		return false;
		}
		else
		{
		$(".service .arrow").removeClass("open");
        $(".service .showDetail").show();
        $(this).parent().find("a.showDetail").show();
        $(this).parent().find("a.arrow").show();
        $(this).parent().find(".description").hide();
		return false;
		}
		
		//var elementClicked = $(this);
        //var destination = $(elementClicked).offset().top;
        //$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 600 );
		
    });
}

// Tab Description Detail Cruice //
CostaUi.tabDetail = function ()
{
    // Pietro Bini - 7/7/2011
    // valorizzazione valore per aggiornamento tabella pacchetti escursioni 
    var tabName = "ExcursionPackagesTab";
    if ($("input[name*=hfExcursionPackagesTab]")!= null)
    {
          $("input[name*=hfExcursionPackagesTab]").val(tabName);
    }

    $(".tab a").click(function ()
    {
        var nameTab = $(this).attr("class");
        $(".service .showDetail").show();
        $(".service .arrow").removeClass("open");
        $(".description").hide();
        $(".ctn-tab").children("div").hide();
        $(".ctn-tab div." + nameTab).show();
        $(".tab li").removeClass();
        $(this).parent().addClass("on");
    })
}

// Tab Inside Page //
CostaUi.tabInsidePage = function () {

    $(".tabulation").hide();
    $(".tabulation:first").show();
    $(".tab li:first").addClass("on");
    $(".tab a").click(function () {
        var nameTab = $(this).attr("class");
        $(".tabulation").hide();
        $(".tabulation." + nameTab).show();
        $(".tab li").removeClass();
        $(this).parent().parent().addClass("on");
    })
}

CostaUi.tabDetailSelectFirst = function ()
{
    $(".ctn-tab").children("div").hide();
    $(".ctn-tab").children("div:first").show();
    $(".ctn-tab div.tab1").show();
    $(".tab li:first").addClass("on");
    
}

// metodo utilizzato per nascondere i tab Escursione o Pacchetto Escursione nel caso in cui non ci siano dati
CostaUi.HideTabEmptyMyCosta = function (ClientIDTab,ClientIDUc,hide,itemIndex)
{
    if (hide == "True")
    {
        classOn = $("#"+ClientIDTab+"").attr("class");
        if (classOn == "on")
        {   
            $(".ctn-tab").children("div:first").show();
            $(".ctn-tab div.tab1").show();
            $(".tab li:first").addClass("on");
            $(".ctn-tab div.tab2").hide();
            $(".ctn-tab div.tab3").hide();
        }
        $("#"+ClientIDTab+"").hide();        
        $("#"+ClientIDTab+"").removeClass();
    }
    else
    {
        $("#"+ClientIDTab+"").show();        
    }
}

// Utility Layer //
function center(elem)
{
    var hBody = $(window).height();
    var wBody = $(window).width();
    var hZoom = $(elem).height();
    var wZoom = $(elem).width();
    
    var h = ((hBody - hZoom) / 2);
    var w = (wBody - wZoom) / 2;

    if (h <= 0) h = 24;
    if (w <= 0) w = 0;
    $(elem).css("top", h).css("left", w);
}

$(window).resize(function ()
{
    var overlay = $("#mask").css("display");
	
    if (overlay == 'block') 
    {
        $("#mask").fadeTo(0, 0.4).height($(window).height() + $(window).scrollTop());

        var activLayer = $("div.layer");
        
        for (i = 0; i < activLayer.length; i++)
        {
            if (activLayer.eq(i).css("display") == 'block')
            {
                var nameLayerCenter = activLayer.eq(i).attr("class").split(" ")[1];
                center("div." + nameLayerCenter);
            }
        }
        
        center("div.content-video-layer");
    }
	else
	{
		// Pietro Bini 
		// la variabile  valorizzata solo nella pagina CruiseDetail ed è utilizzata per visualizzare il contenuto del placeholder sotto la tabella in EDITING
		if ($(".hdnShowLayerFirst") != null)
		{
			// se è 1 deve essere visualizzata
			if ($(".hdnShowLayerFirst").attr("value") == 1)
			{		
				CostaUi.showFirstDetailsEdit();
			}
		}
	}
    return;
});

$(window).scroll(function ()
{
    var overlay = $("#mask").css("display");
    if (overlay == 'block')
    {
        $("#mask").fadeTo(0, 0.4).height($(window).height() + $(window).scrollTop());
        var activLayer = $("div.layer");
        for (i = 0; i < activLayer.length; i++)
        {
            if (activLayer.eq(i).css("display") == 'block')
            {
                var nameLayerCenter = activLayer.eq(i).attr("class").split(" ")[1];
                center("div." + nameLayerCenter);
            }
        }
		center("div.content-video-layer");
    }
    return;
});

// Layer Controll //
CostaUi.openLayer = function ()
{
    $(".open-layer").click(function ()
    {
        var layerNumber = $(this).attr("rel");
        // gestione IE7 problema attributo position-relative 
        if($.browser.msie && $.browser.version.slice(0,3) == "7.0" ) {
            $("#containerID").removeClass("contenitore");
            $("#containerID").addClass("contenitore-IE7");  
            $("#wrapper").css("position","static");
        }
       $("#mask").fadeTo(0, 0.4);  
       $("."+layerNumber+"").fadeIn();
       center("."+layerNumber+"");
       $(window).resize();
        return false;
    });
}

CostaUi.openLayerExec = function (layerNumber)
{
        $("#mask").fadeTo(0, 0.4);
        $("."+layerNumber+"").fadeIn();
        center("."+layerNumber+"");
        $(window).resize();
}

CostaUi.openLayerCruiseDetail = function (layerNumber,clientIdPnl)
{
        $("#"+clientIdPnl+"").show();
        $("#"+clientIdPnl+"").parent().find(".submitButton").hide();
        $("#mask").fadeTo(0, 0.4);
        $("."+layerNumber+"").fadeIn();
        center("."+layerNumber+"");
        $(window).resize();
}

CostaUi.closeLayer = function ()
{   
    $("#mask").click(function ()
    {   
        $(this).fadeOut();
        $(".layer").fadeOut();
        // gestione IE7 problema attributo position-relative 
        if($.browser.msie && $.browser.version.slice(0,3) == "7.0" ) {
            $("#containerID").addClass("contenitore");
            $("#containerID").removeClass("contenitore-IE7");  
            $("#wrapper").css("position","relative");
        }
        return false;
    });

    $(".closeLayer").click(function ()
    {
        // gestione IE7 problema attributo position-relative 
        if($.browser.msie && $.browser.version.slice(0,3) == "7.0" ) {
            $("#containerID").addClass("contenitore");
            $("#containerID").removeClass("contenitore-IE7");
            $("#wrapper").css("position","relative"); 
        }
        $("#mask").fadeOut();
        $(".layer").fadeOut();
        $(".layer .ctn-gallery").hide();
        $(".layer .ctn-video").hide();
        return false;
    });
}

// metodi per gestione EDITING 
CostaUi.showChangeCountry = function ()
{   
        $(".layer").fadeIn();
        return false;
}

CostaUi.hideChangeCountry = function ()
{   
        $(".layer").fadeOut();
        return false;
}

// FINE metodi per gestione EDITING 

CostaUi.showFirstDetailsEdit = function ()
{   
        //$("#mask").fadeTo(0, 0.4);
        $(".first").fadeIn();
        //center(".first");
        //$(window).resize();
        $(".change-country").hide();
        $(".change-country").css("display","none");
        $(".first").css("top",0);
		$(".first").css("position","relative");		
		$(".first").css("display","block");		
        return false;
}

CostaUi.closeLayerOldPage = function ()
{   
    $("#mask").fadeOut();
    $(".layer").fadeOut();
    $(".layer .ctn-gallery").hide();
    $(".layer .ctn-video").hide();
    return false;
}

// Clear Input //
CostaUi.clearInput = function ()
{    
    $("form input").click(function ()
    {
        if (!this._haschanged) { this.value = '' }; this._haschanged = true;
    })
}

// Show Cabin Details //
CostaUi.showCabinDetails = function ()
{
    $(".ctn-cabin .submitButton").click(function ()
    {
        $(".ctn-cabin .submitButton").show();
        $(".cabin-details .confirmButton").hide();
        $(".ctn-cabin .cabin-details").hide();
        $(this).hide();
        $(this).parent().parent().parent().find(".cabin-details").show();
    });

    $(".cabin-details input").click(function ()
    {
        $(".cabin-details .confirmButton").show();
    })
}

// funzione creata per visualizzare chiudere il messaggio di errore nella pagina newsletter
CostaUi.closeMsgErrorNewsLetter = function()
{
   $(".close-error").click(function ()
   {
        $("#pnlBtnYesNo").addClass("NotVisibileError");
        $("#pnlMsgErr").addClass("NotVisibileError");
        $(".newsletter .form td.error").removeClass("error");
        return false;
    });
                                               
}

//Hide Ul CruiseFinder HomePage//
CostaUi.ShowULCruiseFinder = function ()
{
    $("#advanced-search-ul-port").removeClass("advanced-search");
    $("#advanced-search-ul-port").addClass("advanced-search-visible");
    $("#advanced-search-ul-ship").removeClass("advanced-search");
    $("#advanced-search-ul-ship").addClass("advanced-search-visible");
    $(".showAllFields").addClass("on");   
    return false;
}

//Parte relativa ai link statici dell'Header
CostaUi.openLinkHeader = function()
{
   $("#link_header_registrati").click(function ()
   {
        var linkPage =  $("#HdnWhyRegisterLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            document.location.href = linkPage;
        }
    });
    
   $("#link_header_forgotpassword").click(function ()
   {
        var linkPage =  $("#HdnForgotPasswordLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            document.location.href = linkPage;
        }
    });
    
   $("#link_header_myCosta").click(function ()
   {
        var linkPage =  $("#HdnMyCostaLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            document.location.href = linkPage;
        }
    });
    
   $("#link_header_becomeACostaClub").click(function ()
   {
        var linkPage =  $("#HdnBecomeACostaClubLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            //alert(address);
            document.location.href = linkPage;
        }
        
      
    });
    
   $("#link_header_editProfile").click(function ()
   {
        var linkPage =  $("#HdnEditProfileLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            //alert(address);
            document.location.href = linkPage;
        }
        
      
    });
   
    $("#link_header_changePassword").click(function ()
   {
        var linkPage =  $("#HdnChangePasswordLink").attr("value");
        var hostName =  $("#HdnHostNameLink").attr("value");
        
        if ((hostName != "#") && (linkPage != "#"))
        {
            var address = "https://" + hostName + "/" + linkPage;
            //alert(address);
            document.location.href = linkPage;
        }
        
      
    });                                                
}

// Clear Input //
CostaUi.clearInput = function () {
    $("form input").click(function () {
        if (!this._haschanged) { this.value = '' }; this._haschanged = true;
    });
}

// Show Cabin Details //
CostaUi.showCabinDetails = function ()
{
    $(".ctn-cabin .submitButton").click(function ()
    {
        $(".ctn-cabin .submitButton").show();
        $(".cabin-details .confirmButton").hide();
        $(".ctn-cabin .cabin-details").hide();

        $(this).hide();
        $(this).parent().parent().parent().find(".cabin-details").show();
    });

    $(".cabin-details input").click(function ()
    {
        $(".cabin-details .confirmButton").show();

    })

}

// Tab Layer //
CostaUi.tabLayer = function () {
    $(".layer .ctn-tab a").click(function () {
        var nameTab = $(this).attr("rel");
        $(".layer .ctn-tab a").removeClass("on");
        $(".layer .ctn-gallery").hide();
        $(".layer .ctn-video").hide();
        $(this).addClass("on");
        $(".layer div." + nameTab + "").show();

        var classLayer = $(this).parent().parent().parent().attr("class").split(" ");
        var nameLayerCenter = classLayer[1];
        center("div." + nameLayerCenter);
    });
}

// Change Country //
CostaUi.changeCountry = function () 
{
    $("a.changeCountry").click(function () 
    {
        $("ul.continents li").removeClass("on");
        $(this).parent().addClass("on");
        var whatToShow = $(this).attr("rel");
        $("ul.state").hide();
        $("ul.state." + whatToShow).show();
    })
}

// Tab Offer Choosing Option //
CostaUi.tabOfferChooseFirst= function () {
    $(".tab-offer").hide();
    $(".tab-offer:first").show();
    $(".tab li:first").addClass("on");

}

CostaUi.tabOfferChoose = function () {
    $(".tab a").click(function () {   
                             
        var nameTab = $(this).attr("class");
        
        // scrittura nuovo indice tab selezionato
        $(".hdnIndexCurrentTab").val(nameTab);
        
        $(".service .showDetail").show();
        $(".service .arrow").removeClass("open");
        $(".description").hide();
        $(".tab-offer").hide();
        $(".tab-offer." + nameTab).show();
        $(".tab li").removeClass();
        $(this).parent().parent().addClass("on");
                
    return false;
    });
}

// Menu MyCosta //
CostaUi.submenuMyCosta = function () {
    $(".mainMyCostaMenu a.openSubMenu").click(function () {

        $(".mainMyCostaMenu a").removeClass("on");
        $(this).addClass("on");
        var submenuName = $(this).attr("name");
       // $("ul.subMenuMyCosta").addClass(submenuName);
        if ($("ul." + submenuName + "").css("display") == "block") {
            $("ul." + submenuName + "").slideUp();
            //$("ul.subMenuMyCosta").removeClass(submenuName);
            $(this).removeClass("on");
            return;
        }
        else {
            $("ul.subMenuMyCosta").slideUp();
            $("ul.subMenuMyCosta." + submenuName + "").slideDown();
             // $("ul.subMenuMyCosta").removeClass(submenuName);
      }
    })
}

// Show Hide Description MyCosta //
CostaUi.showDetailMyCosta = function () {
	
    $(".activateShowHide").click(function () {
        $(this).parent().parent().next(".description").toggle();
        //$(".description").hide();
        //$(this).parent().parent().next(".description").show();
    });

    $(".showDetail").click(function () {
                   
        $(".service .arrow").removeClass("open");
        $(".service .showDetail").show();
        $(".service .description").hide();
        $(this).parent().find("a.arrow").show();
        $(this).parent().find(".description").show();
        $(this).parent().find("a.arrow").addClass("open");
    });
}

CostaUi.ShowDetailDescExc = function(portClientId){

     $('#'+portClientId).show();   
}

// Multi Cruice //
CostaUi.openMultiCruice = function () 
{
    $(".show-detail").click(function () {
        $(this).hide();
        $(this).next(".hide-detail").show();
        var elementToShow = $(this).attr("rel");
        $(".passenger-info." + elementToShow + "").slideToggle();

    });
    $(".hide-detail").click(function () {
        $(this).hide();
        $(this).prev(".show-detail").show();
        var elementToShow = $(this).attr("rel");
        $(".passenger-info." + elementToShow + "").slideToggle();

    })
}

// Registrazione V4
CostaUi.openLogin = function ()
{
    $("a.open-login").click(function ()
    {
        $("div.open-login").slideDown();
        $(this).hide();
        $("a.close-login").show();
    })
}

CostaUi.closeLogin = function ()
{
    $("a.close-login").click(function ()
    {
        $("div.open-login").slideUp();
        $(this).hide();
        $("a.open-login").show();
    })
}

// Script per mostrare il pannello di Login nel caso di accesso con Cause=AuthRequired
CostaUi.showPnlSetFocus = function ()
{
        $("div.open-login").slideDown();
        $("a.close-login").show();
        $("a.open-login").hide();
        $("div.open-login").find(".txtUserName").focus();        
}

// Script per mostrare il pannello di Login nel caso di errore
CostaUi.showPnlErrLogin = function ()
{
        $("div.open-login").slideDown();
        $("a.close-login").show();
        $("a.open-login").hide();
}

// Script per mostrare il pannello di Login nel caso di errore
CostaUi.showPnlErrForgot = function ()
{        
        $("div.extra-info").slideDown();               
}

// open section Secret Question in Forgot Password Result V4 
CostaUi.openExtraInfo = function ()
{
    $("a.extra-info").click(function ()
    {
        $("div.extra-info").slideDown();
    })

}

// Personalize Your Cruise

// Show Hide Description MyCosta //
CostaUi.showDetailMyCostaPC = function ()
{        
        $(".activateShowHide").click(function () {
            $(this).parent().parent().next(".description").toggle();
        });



    $(".showDetail").click(function ()
    {
        var $parent = $($(this).parents("li")[0]);
        
        var elemtProperty = $parent.find(".description").css("display");
        
        if (elemtProperty == "none")
        {
            $parent.find(".description").show();
            $parent.find("a.arrow").addClass("open");
            return false;
        }
        else
        {
            $parent.find("a.arrow").removeClass("open");
            $(".service .showDetail").show();
            $parent.find("a.showDetail").show();
            $parent.find("a.arrow").show();
            $parent.find(".description").hide();
            return false;
        }


    });
}

CostaUi.tabDetailPC = function () 
{
    $(".tab a").click(function ()
    {
        var $parent = $($(this).parents("div.ctn-tab"));
        var nameTab = $(this).attr("class");
        $parent.find(".service .showDetail").show();
        $parent.find(".service .arrow").removeClass("open");
        $parent.find(".description").hide();
        $parent.children("div").hide();
        $parent.find("div." + nameTab).show();
        $parent.find(".tab li").removeClass();
        $(this).parent().addClass("on");
    })
}

CostaUi.tabDetailSelectFirstPC = function ()
{
    $("div.ctn-tab").children("div").hide();
    $("div.ctn-tab").children("div:first").show();
    $("div.ctn-tab div.tab1").show();
    $("div.ctn-tab").find("li:first").addClass("on");
}



CostaUi.tabLayerPC = function () {
    $(".layer .ctn-tab a").click(function () {
        var nameTab = $(this).attr("rel");
        $(".layer .ctn-tab a").removeClass("on");
        $(".layer .ctn-gallery").hide();
        $(".layer .ctn-video").hide();
        $(this).addClass("on");
        $(".layer div." + nameTab + "").show();

        var classLayer = $(this).parent().parent().parent().attr("class").split(" ");
        var nameLayerCenter = classLayer[1];
        center("div." + nameLayerCenter);
    });
}

CostaUi.OpenSelectedPopUp = function (layerNumber) {

     CostaUi.openLayerExec(layerNumber);
      CostaUi.closeLayer();    
      $(this).find(".description").show();                 
}

CostaUi.OpenPopUpVideo = function()
{

    $("#mask").fadeTo(0, 0.4);
    $(".content-video-layer").show();   
    center(".content-video-layer");
    
    var newtop = $(".content-video-layer").position().top + ($(window).scrollTop()); 
    $(".content-video-layer").css('top', newtop + 'px');
    
    $(window).resize();
    CostaUi.fullScreenControllLayer();
    CostaUi.closeVideoLayer();
    return false;               
};

CostaUi.ShowCtnGallery = function()
{

    if ($(".layer .ctn-gallery").css("display") == "none")
        $(".layer .ctn-gallery").show();
   
    return false;
};

CostaUi.tabDetailMyCostaItem = function (itemIndex) 
{
	$('#div_CntTab_'+itemIndex).children('div').hide();
    $('#div_CntTab_'+itemIndex).children('div:first').show();
    $('#div_CntTab_'+itemIndex+' ul li:first').addClass('on');
    $('#div_CntTab_'+itemIndex+' ul li a').click(function () {
        var nameTab = $(this).attr('class');
        $('.service .showDetail').show();
        $('.service .arrow').removeClass('open');
        $('.description').hide();
        $('#div_CntTab_'+itemIndex).children('div').hide();
        $('#div_CntTab_'+itemIndex+' div.' + nameTab).show();
        $('#div_CntTab_'+itemIndex+' ul li').removeClass();
        $(this).parent().addClass('on');
    })
}
								
CostaUi.tabDetailMyCosta = function () 
{
    $(".ctn-tab").children("div").hide();
    $(".ctn-tab").children("div:first").show();
    $(".tab li:first").addClass("on");
    $(".tab a").click(function () {
        var nameTab = $(this).attr("class");
        $(".service .showDetail").show();
        $(".service .arrow").removeClass("open");
        $(".description").hide();
        $(".ctn-tab").children("div").hide();
        $(".ctn-tab div." + nameTab).show();
        $(".tab li").removeClass();
        $(this).parent().addClass("on");

    })
}

// Layer Map //

var layerIsVisible = false;
CostaUi.mapTooltipContlol = function ()
{
    $("div.inside-map a,div.map a").live("mouseover", function (e)
    {
        if (!layerIsVisible)
        {
            layerIsVisible = true;
            var $this = $(this);
            CostaUi.mapTooltipShow($this, e);
        }
    });

    $("div.inside-map a,div.map a").live("mouseleave", function ()
    {
        CostaUi.mapTooltipHide();
    });
}

CostaUi.mapTooltipShow = function ($this, e)
{
    var name = $this.find("span").text();
    var asseX = parseInt((e.pageX + 15), 10);
    var asseY = parseInt(e.pageY - 20, 10);
    $(".tooltip-map span").html(name);
    $(".tooltip-map").css({ "top": asseY + "px", "left": asseX + "px" });
    $(".tooltip-map").fadeIn('fast', function ()
    {
        layerIsVisible = false;
    });
}

CostaUi.mapTooltipHide = function ()
{
    $(".tooltip-map").fadeOut('fast');
}

// Video JS //
CostaUi.resetToDefaultParamether = function (cssModification, offset)
{
    cssModification = { width: "705px", height: "396px", left: offset.x, top: offset.y, position: "relative" };
    $(".content-video").css(cssModification);
};

CostaUi.fullScreenControll = function (isReplay)
{

    isFullScreen = false;
    var defaultOffset = $(".content-video").offset();
    var offset = { 'x': defaultOffset.left, 'y': defaultOffset.top };

    if (isReplay)
    {
        var cssModification;
        CostaUi.resetToDefaultParamether(cssModification, offset);
    }

    $("a.openfullscreen").click(function ()
    {
        var cssModification;
        if (!isFullScreen)
        {
            isFullScreen = true;
            CostaUi.openFullScreen(cssModification, offset);
        }
        else
        {
            isFullScreen = false;
            CostaUi.closeFullScreen(cssModification, offset);
        }
        return false;
    });

};

CostaUi.openFullScreen = function (cssModification, offset)
{

    cssModification = { position: "absolute", zIndex: "999999", left: offset.x, top: offset.y };
    $(".content-video").css(cssModification);
    cssModification = { width: "100%", height: "100%", left: "0px", top: "0px" };
    $(".content-video").animate(cssModification, 500);
};

CostaUi.closeFullScreen = function (cssModification, offset)
{
    cssModification = { width: "705px", height: "396px", left: offset.x, top: offset.y };
    $(".content-video").animate(cssModification, 500, function ()
    {
        $(".content-video").css({ position: "relative", left: "0px", top: "0px", zIndex: "1" });
    });
};

CostaUi.eventFinishVideoFlash = function ()
{
    $(".content-video").hide();
    $(".content-video-structure").hide();
    $(".ctn-visual").show();
};

CostaUi.eventFinishVideoHtml = function ()
{
    $("video").bind("ended", function ()
    {
        $(".content-video").hide();
        $(".content-video-structure").hide();
        $(".ctn-visual").show();
    });
};

CostaUi.replayVideo = function ()
{
    $(".replay").click(function ()
    {
        var htmlVideo = $(".content-video").html();
        $(".content-video").html(htmlVideo);
        $(".ctn-visual").hide();
        $(".content-video").show();
        $(".content-video-structure").show();
        CostaUi.eventFinishVideoHtml();
        var checkIsFullscreen = ($(".content-video").css("position") == "absolute") ? true : false;
        CostaUi.fullScreenControll(checkIsFullscreen);
        return false;
    });
};

// Inizialize //
CostaUi.init = function ()
{
    CostaUi.controllTabExpressBooking();
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.carousel();
    CostaUi.toggleFooter();
    CostaUi.setMaxElentHeight();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.changeCountry();
    CostaUi.tabInsidePage();
}

// Inizialize Without Footer//
CostaUi.initWithoutFooter = function ()
{
    CostaUi.controllTabExpressBooking();
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.carousel();
    CostaUi.setMaxElentHeight();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.changeCountry();
    CostaUi.tabInsidePage();
}

// Inizialize Offerte //
CostaUi.initOfferte = function ()
{
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.openLinkHeader();
    CostaUi.openLayer();
    CostaUi.closeLayer();
    CostaUi.changeCountry();
}

// Inizialize Registrazione //
CostaUi.initRegistrazioneV4 = function ()
{
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.openLinkHeader();
    CostaUi.openLayer();
    CostaUi.closeLayer();
    CostaUi.changeCountry();
}

// Inizialize Header Footer//
CostaUi.initHeaderFooterV4 = function ()
{
    CostaUi.closeLayerOldPage();
    CostaUi.openLayer();
    CostaUi.closeLayer();
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.changeCountry();
}


// Inizialize MyCosta//
CostaUi.initMyCosta = function ()
{
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.submenuMyCosta();
    CostaUi.openLayer();
    CostaUi.closeLayer();
    CostaUi.tabLayer();
    CostaUi.openMultiCruice();
    CostaUi.carousel();
}

// Inizialize MyCosta Personalize Cruise//
CostaUi.initMyCostaPersonalizeCruise = function ()
{
    CostaUi.subMenuPosition();
    CostaUi.subMenu();
    CostaUi.tooltip(".tooltip", "layerTooltip");
    CostaUi.openLayer();
    CostaUi.closeLayer();
    CostaUi.tabLayerPC();
    CostaUi.openMultiCruice();
}

function goto(url)
{
    location.href = url;
}


function SelectATab (tabIndex) 
{
    var tabName = "tab" + (tabIndex+1);
    var tab = $(".tab a")[tabIndex];

        var $parent = $($(tab).parents("div.ctn-tab"));

        $parent.find(".service .showDetail").show();
        $parent.find(".service .arrow").removeClass("open");
        $parent.find(".description").hide();
        $parent.children("div").hide();
        $parent.find("div." + tabName).show();
        $parent.find(".tab li").removeClass();
        $(tab).parent().addClass("on");   
}

