﻿//DOCUMENT READY
$(document).ready(function () {

    var $localPath = document.URL;
    var $pathName = $localPath.substring($localPath.lastIndexOf('/') + 1, $localPath.length);

    resizeUI();


    //MENU DINAMICO
    $('.link').show();
    $('.linkHover').hide();
    $(document).find('.divMenu_Item_Background').show();

    /* (verifica della pagina visualizzata e disabilitazione del relativo link) */
    $('.divMenu_Header').find('.divMenu_Sensible a').each(function () {
        if ($pathName.indexOf($(this).attr('href')) >= 0) {
            $(this).closest('.divMenu_Item').find('.link').hide();
            $(this).closest('.divMenu_Item').find('.linkHover').show();
            $(this).closest('.divMenu_Item').find('.divMenu_Item_Background .divMenu_Mask').slideUp({ duration: 200, esaing: "easeOutExpo" });
            $(this).parent().hide();
        }
    });

    /* (funzione richiamata al mouseOver)*/
    $('.divMenu_Header .divMenu_Sensible a').mouseover(function () {
        $(this).closest('.divMenu_Item').find('.link').hide();
        $(this).closest('.divMenu_Item').find('.linkHover').show();
        $(this).closest('.divMenu_Item').find('.divMenu_Item_Background .divMenu_Mask').slideUp({ duration: 200, esaing: "easeOutExpo" });
    });

    /* (funzione richiamata al mouseOut) */
    $('.divMenu_Header .divMenu_Sensible a').mouseout(function () {
        $(this).closest('.divMenu_Item').find('.link').show();
        $(this).closest('.divMenu_Item').find('.linkHover').hide();
        $(this).closest('.divMenu_Item').find('.divMenu_Item_Background .divMenu_Mask').slideDown({ duration: 200, easing: "easeOutExpo" });
    });

   
    //RICHIAMO FUNZIONE AREA HOME
    if ($pathName.indexOf("index.aspx") >= 0 || $pathName + "home" == "home") {    
        $(document).find('.vectorMusaBig_Footer').show();
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI');
        setTimeout(functionHome, 2000);
    }

    //RICHIAMO FUNZIONE AREA NEWS
    if ($pathName.indexOf("news.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_Yellow');
    }

    //RICHIAMO FUNZIONE AREA STABILIMENTO
    if ($pathName.indexOf("stabilimento.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_Yellow');
        $(document).find('.vectorMusaBig_Footer').show();
        functionStabilimento();
    }

    //RICHIAMO FUNZIONE AREA BIMBI
    if ($pathName.indexOf("bimbi.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_Yellow');
        $(document).find('.vectorMusaBig_Footer').show();
        functionBimbi();
    }

    //RICHIAMO FUNZIONE AREA GENITORI
    if ($pathName.indexOf("genitori.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_FucsiaYellow');
        $(document).find('.vectorMusaBig_Footer').show();
        functionGenitori();
    }

    //RICHIAMO FUNZIONE AREA GENITORI
    if ($pathName.indexOf("feste.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_FucsiaYellow2');
        $(document).find('.vectorMusaBig_Footer').show();
    }

    //RICHIAMO FUNZIONE AREA SFIDE
    if ($pathName.indexOf("sfide.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_OrangeYellow');
        $(document).find('.vectorMusaBig_Footer').show();
        functionSfide();
    }

    //RICHIAMO FUNZIONE AREA HOTELS ASSOCIATI
    if ($pathName.indexOf("hotelAssociati.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_Yellow');
        $(document).find('.vectorMusaBig_Footer').show();
        functionHotels();
    }

    //RICHIAMO FUNZIONE AREA LISTINO PREZZI
    if ($pathName.indexOf("listinoPrezzi.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_FucsiaYellow3');
    }

    //RICHIAMO FUNZIONE AREA LISTINO PREZZI
    if ($pathName.indexOf("photogallery.aspx") >= 0) {
        $(document).find('.vectorCouple_Footer').hide();
        functionPhotogallery();

    }

    //RICHIAMO FUNZIONE AREA CONTATTI
    if ($pathName.indexOf("contatti.aspx") >= 0) {
        $(document).find('#tdPrincipale_UI').removeClass().addClass('tdPrincipale_UI_Yellow');
        functionStabilimento();
    }

});

//WINDOW RESIZE
$(window).resize(function () {

    resizeUI();

});

//DOCUMENT RESIZE
$(document).resize(function () {

    resizeUI();

});

//RIDIMENSIONAMENTO STRUTTURA
function resizeUI() {

    var $maxHeight = $(window).height();
    var $headerHeight = $(document).find('.tdPrincipale_Header').height();
    var $footerHeight = $(document).find('.tdPrincipale_Footer').height();
    var $UIHeight = $maxHeight - ($headerHeight + $footerHeight);

    $(document).find('.tdPrincipale_UI').add().css('height', $UIHeight);
    $(document).find('.tbl_UI').add().css('height', $UIHeight);
    $(document).find('.vectorMusaBig_Footer').add().css('right', '0px');
}

//FUNZIONI AREA HOME
function functionHome() {

    //NEWS DINAMICHE
    $('.hplSensibleNews_Home').mouseover(function () {
        $(this).closest('.divContainerNews_Home').find('.divItemNews_Home').add().css('background-image', 'url(images/spacer_White30.png)');
    });

    $('.hplSensibleNews_Home').mouseout(function () {
        $(this).closest('.divContainerNews_Home').find('.divItemNews_Home').add().css('background-image', 'url(images/spacer.png)');
    });

   
    //POLAROID PHOTOGALLERY
    //var $newPolaroidPhotogallery_size = $(window).width() - $(document).find('.tdNewsHome').width() - 30;
    var $maxImage_width = 400;
    var $maxImage_height = 350;
    var $borderPolaroid = 10;
    var $polaroidNumbers = 0;
    var $oldZIndex = 0;

    var $maxSpace_width = $(document).find('.divContentPolaroid_Home').width();
    var $maxSpace_height = $(document).find('.divContentPolaroid_Home').height();

    //$(document).find('.divContentPolaroid_Home').add().css('width', $newPolaroidPhotogallery_size);

    /*resize Images & Polaroids*/
    $(document).find('.divPolaroid').each(function () {
        if ($(this).find('img').width() > $(this).find('img').height()) {
            if ($(this).find('img').width() > $maxImage_width) {
                $(this).find('img').add().css('width', $maxImage_width);
            }
        }
        else {
            if ($(this).find('img').height() > $maxImage_height) {
                $(this).find('img').add().css('height', $maxImage_height);
            }
        }

        $(this).width = $(this).find('img').width();
        $(this).height = $(this).find('img').height();
    });

    /*random Rotation*/
    $(document).find('.divPolaroid').each(function () {
        
        $polaroidNumbers = $polaroidNumbers + 1;
        var $angle = Math.floor(Math.random() * 45) - 20;
        $(this).transform({ 'rotate': $angle + 'deg' });
        $(this).add().attr('angle', $angle);
        $(this).find('img').add().attr('imgW', $(this).find('img').width());
        $(this).find('img').add().attr('imgH', $(this).find('img').height());
    });

    /*setting Margin*/
    var $count = 0;
    $maxSpace_width = $maxSpace_width / $polaroidNumbers;
    $(document).find('.divPolaroid').each(function () {

        /*Horizontal Position*/
        $positionH = $maxSpace_width * $count;
        $(this).add().css('margin-left', $positionH + "px");

        /*Vertical Position*/
        $positionV = Math.floor(($maxSpace_height / 4) * Math.random());

        if (Math.floor($positionV + $(this).height() + 100) > $maxSpace_height) {
            $positionV = $maxSpace_height - ($(this).height() + 100);
        }

        $(this).add().css('margin-top', $positionV);

        /*Random Z-Index*/
        $zIndex = Math.floor((Math.random() * $polaroidNumbers) + 4);
        $(this).add().css('z-index', $zIndex);
        $count = $count + 1;
    });

    /*funzione richiamata al mouseover su una polaroid*/
    $('.divPolaroid').mouseover(function () {

        $oldZIndex = $(this).css('z-index');
        var $newWidth = Math.floor($(this).find('img').attr('imgW') * 1.1);
        var $newHeight = Math.floor($(this).find('img').attr('imgH') * 1.1);
        $(this).add().css('z-index', ($oldZIndex * 1000));

        var $newAngle = ($(this).attr('angle') * -1);

//        $(this).animate({
//            'rotate': $newAngle + 'deg',
//            }, 300, 'linear');
            
            $(this).find('img').animate({
                'width': $newWidth,
                'height': $newHeight
            }, 300, 'linear');
    });

    /*funzione richiamata al mouseout su una polaroid*/
    $('.divPolaroid').click(function () {
        $(this).add().css('z-index', 1);
    });



    /*funzione richiamata al mouseout su una polaroid*/
    $('.divPolaroid').mouseout(function () {
        
        var $newWidth = Math.floor($(this).find('img').attr('imgW'));
        var $newHeight = Math.floor($(this).find('img').attr('imgH'));
        $(this).add().css('z-index', $oldZIndex);
        
//        $(this).animate({ 
//            'rotate': $(this).attr('angle') + 'deg' 
//        }, 300, 'linear');

        
        $(this).find('img').animate({
            'width': $newWidth,
            'height': $newHeight
        }, 300, 'linear');
    });
}

//FUNZIONI AREA STABILIMENTO
function functionStabilimento(){

    /*ridimensionamento contenuti*/
    var $contentHeight = $(document).find('#tblUI_stabilimento').height();
    $(document).find('.tblRight_Stabilimento').add().css('height', $contentHeight);
    var $mapHeight = $(document).find('.tdBottomRight_Stabilimento').height();
    $(document).find('.tdBottomRight_Stabilimento').add().css('height', $mapHeight + 17);
}

//FUNZIONI AREA BIMBI
function functionBimbi(){

    $(document).find('.divItemServizio').hide();

    $(document).find('.hplServizio').mouseover(function () {
        var $ID = $(this).attr('rel');

        $(document).find('.divItemServizio').each(function () {
            if ($(this).attr('rel') == $ID) {
                $(this).show();
            }
            else {
                $(this).hide();
            }
        });
    });

    $(document).find('.hplServizio').mouseout(function () {
        $(document).find('.divItemServizio').hide();
    });
}

//FUNZIONI GENITORI
function functionGenitori() {
    $(document).find('.divItemServizio').hide();

    $(document).find('.hplServizio').mouseover(function () {
        var $ID = $(this).attr('rel');

        $(document).find('.divItemServizio').each(function () {
            if ($(this).attr('rel') == $ID) {
                $(this).show();
            }
            else {
                $(this).hide();
            }
        });
    });

    $(document).find('.hplServizio').mouseout(function () {
        $(document).find('.divItemServizio').hide();
    });
}

//FUNZIONI AREA SFIDE
function functionSfide(){

    /*rollover link photogallery*/
    $('.hplLinkPhotogallery_Sfide').mouseover(function(){
        $(this).closest('.divContainerLink_Sfide').find('.divTextLink_Sfide').add().css('background-color', '#b577d8');
    });

    /*rollout link photogallery*/
    $('.hplLinkPhotogallery_Sfide').mouseout(function(){
        $(this).closest('.divContainerLink_Sfide').find('.divTextLink_Sfide').add().css('background-color', '#f14461');
    });
}

//FUNZIONI HOTEL ASSOCIATI
function functionHotels(){

    $('.divInfoHotel').hide();
    $('.divPointer').hide();
    
    var elem = $(".divTitleHotels");
    var offset = elem.offset();
    var leftValue = offset.left; 
    var topValue = offset.top;

    $('.divInfoHotel').add().css('left', leftValue);

    $('.hplHotel_Logo').mouseover(function () {
        $(this).parent().find('.divPointer').show();
        $(this).parent().find('.divInfoHotel').show();
    });

    $('.divPointer').mouseover(function () {
        $(this).show();
        $(this).parent().find('.divInfoHotel').show();
    });

    $('.divInfoHotel').mouseover(function () {
        $(this).show();
        $(this).parent().find('.divPointer').show();
    });

    $('.hplHotel_Logo').mouseout(function () {
        $('.divInfoHotel').hide();
        $('.divPointer').hide();
    });

    $('.divPointer').mouseout(function () {
        $('.divInfoHotel').hide();
        $('.divPointer').hide();
    });

    $('.divInfoHotel').mouseout(function () {
        $('.divInfoHotel').hide();
        $('.divPointer').hide();
    });

    
    /*ridimensionamento contenuti*/
    $(document).find('.tblUI_Hotels').add().css('width','100%');
    $(document).find('.tblPrincipale_Hotels').add().css('height', $(document).find('.tblUI_Hotels').height());
    $(document).find('.tblMap_Hotels').add().css('height', $(document).find('.tblUI_Hotels').height());
}

//FUNZIONI PHOTOGALLERY
function functionPhotogallery(){

    /*ridimensionamento contenuti*/
    $(document).find('.tblUI_Photogallery').add().css('width','100%');
    $(document).find('.tblUI_Photogallery').add().css('height','636px');
}

