// menu DX

var timerOutMenuDx = null;
$(document).ready(function() {

    $('.fasciaGrigiaOfferte:eq(' + $('.selezionatoOfferta').index(this) + ')').css("background-color", "#ccc");
    //$('.ulMenuInternoLiv2 a').attr('href', $(this).attr('href') + '#ancoraMenu3liv');

    $('#carrelloFantasiaDinamica .testoFantasia .boxDinamicoMenuDx').hide();
    $('#menuright').stop(true, true).hover(function() {
        clearTimeout(timerOutMenuDx);
    },
    function() {
        clearTimeout(timerOutMenuDx);
        timerOutMenuDx = setTimeout(
            function() {
                $('#carrelloFantasiaDinamica .testoFantasia').stop(true, true).animate({ "width": 60 }, 400);
                $('#menuright .ulMenuDx .linkJavascript').removeClass("selezionato_dx");
                $('#carrelloFantasiaDinamica .boxDinamicoMenuDx').fadeOut();
            }, 1500);
    }
    );

    $('#carrelloFantasiaDinamica').stop(true, true).hover(function() {
        clearTimeout(timerOutMenuDx);
    },
    function() {
        clearTimeout(timerOutMenuDx);
        timerOutMenuDx = setTimeout(
            function() {
                $('#carrelloFantasiaDinamica .testoFantasia').stop(true, true).animate({ "width": 60 }, 400);
                $('#menuright .ulMenuDx .linkJavascript').removeClass("selezionato_dx");
                $('#carrelloFantasiaDinamica .boxDinamicoMenuDx').fadeOut();
            }, 1500);
    }
    );

    $('.itemOfferte').hover(
        function() {
            $('.fasciaGrigiaOfferte:eq(' + $('.itemOfferte').index(this) + ')').css("background-color", "#cccccc");
        }
    ,
        function() {
            if (!$('.linkDettaglio:eq(' + $('.itemOfferte').index(this) + ')').hasClass('selezionatoOfferta')) {
                $('.fasciaGrigiaOfferte:eq(' + $('.itemOfferte').index(this) + ')').css("background-color", "#ffffff");
            }
        }
    );

    $('.fasciaGrigiaOfferte:first').css("background-color", "#cccccc");

    $('.linkDettaglio').click(
        function() {
            if ($(this).hasClass("selezionatoOfferta")) {
                $(this).removeClass("selezionatoOfferta")
                $('.fasciaGrigiaOfferte:eq(' + $('.linkDettaglio').index(this) + ')').css("background-color", "#fff");
            } else {
                $(this).addClass("selezionatoOfferta")
                $('.fasciaGrigiaOfferte:eq(' + $('.linkDettaglio').index(this) + ')').css("background-color", "#cccccc");
            }
        }
    );

    $("#menuright .ulMenuDx .linkJavascript").click(function() {
        if ($(this).hasClass("selezionato_dx")) {
            $(this).removeClass("selezionato_dx");
            $('#fantasiaDinamica .testoFantasia');
            $('#carrelloFantasiaDinamica .testoFantasia').stop(true, true).animate({ "width": 60 }, 400);
            $('#carrelloFantasiaDinamica .boxDinamicoMenuDx:eq(' + $('#menuright .ulMenuDx .linkJavascript').index(this) + ')').hide();

        } else {
            if ($('#carrelloFantasiaDinamica .testoFantasia:eq(' + $('#menuright .ulMenuDx .linkJavascript').index(this) + ')').width() < 208) {
                // $('#carrelloFantasiaDinamica .testoFantasia').stop(true, true).animate({ "width": 60 }, 400);
            }
            $("#menuright .ulMenuDx .linkJavascript").removeClass("selezionato_dx");
            $(this).addClass("selezionato_dx");
            $('#carrelloFantasiaDinamica .boxDinamicoMenuDx').stop(true, true).hide();
            $('#carrelloFantasiaDinamica .testoFantasia').stop(true, true).animate({ "width": 208 }, 1000);
            $('#carrelloFantasiaDinamica .boxDinamicoMenuDx:eq(' + $('#menuright .ulMenuDx .linkJavascript').index(this) + ')').show(); //.hide();
        }
    });
});

// gallery
$(document).ready(function() {
    $('#boxComandiGallery span').fadeTo(0, 0.5, function() { });
    $('#boxComandiGallery a').hide();
    $('#boxComandiGallery').stop(true, true).hover(function() {
        $('#boxComandiGallery a').stop(true, true).fadeIn();
        $('#boxComandiGallery span').stop(true, true).fadeTo(500, 1, function() { });
    },
    function() {
        $('#boxComandiGallery a').stop(true, true).fadeOut();
        $('#boxComandiGallery span').stop(true, true).fadeTo(1200, 0.5, function() { });
    });

    /* timer riseleziona menu */
    var timerRiseleziona = null;
    $('#boxMenuFasciaLogo').mouseout(function() {
        timerRiseleziona = setTimeout(function() { riseleziona(); }, 1000);
    });

    /* deseleziona menu */
    $('#boxMenuFasciaLogo').mouseover(function() {
        clearTimeout(timerRiseleziona);
        $('.ulMenuSx li .selezionato_liv1').removeClass('selezionato_liv1');
    });

    function riseleziona() {
        $('.ulMenuSx li.selezionato a').addClass('selezionato_liv1');
    }
});

// gallery rotazione
$(document).ready(function() {
    $('#boxImgGallerry')
    .cycle({
        fx: 'fade',
        sync: 1,
        speed: 2000,
        timeout: 8000,
        //pager: '#navGallery',
        next: '#nextImg',
        prev: '#prevImg'
    });

    $('#pauseImg').click(function() {
        $('#boxImgGallerry').cycle('pause');
    });

    $('#nextImg').click(function() {
        $('#boxImgGallerry').cycle('resume');
    });

    $('#prevImg').click(function() {
        $('#boxImgGallerry').cycle('resume');
    });

    $('#prevImg').hover(function() {
        $('#labelComantiGallery').html("previous");
    },
    function() {
        $('#labelComantiGallery').html("gallery");
    });

    $('#pauseImg').hover(function() {
        $('#labelComantiGallery').html("pause");
    },
    function() {
        $('#labelComantiGallery').html("gallery");
    });

    $('#nextImg').hover(function() {
        $('#labelComantiGallery').html("next");
    },
    function() {
        $('#labelComantiGallery').html("gallery");
    });
});


// offerte dettaglio

$(document).ready(function() {
    //$('.itemOfferte .descLungaOfferta').hide();
    //$('.itemOfferte .descBreveOfferta').show();

    $('.itemOfferte .linkDettaglio').click(function() {
        $('.itemOfferte .descBreveOfferta:eq(' + $('.itemOfferte .linkDettaglio').index(this) + ')').stop(true, true).toggle(400);
        $('.itemOfferte .descLungaOfferta:eq(' + $('.itemOfferte .linkDettaglio').index(this) + ')').stop(true, true).toggle(400);

        if ($(this).html() == "Chiudi") {
            $(this).html("Vedi i dettagli");
        } else {
            $(this).html("Chiudi");
        }

    });
});


$(document).ready(function() {
    var pathX = "";
    $('.boxPiccolaGalleryOLD a').hover(
        function() {
            /*pathX = $(this).parent().attr('rel');
            
            $(this).parent().attr('rel', $(this).attr('src'));
            $(this).attr('src', pathX);*/
            //alert(pathX);
            $(this).children(0).hide();
        }
    ,
        function() {
            $(this).children(0).show();
            /*pathX = $(this).parent().attr('rel');
            $(this).parent().attr('rel', $(this).attr('src'));
            $(this).attr('src', pathX);*/
        });

    $('.boxPiccolaGalleryOLD a').click(
        function() {
            $('#boxImgGallerry .imgFluida').attr('src', $(this).attr('rel'));
        });
});

/* validità email */
function emailvalidate(str) {
    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    if (str.indexOf(at) == -1) {
        return false;
    }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false;
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false;
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false;
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false;
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false;
    }

    if (str.indexOf(" ") != -1) {
        return false;
    }
    return true;
}

/* rotator offerte */
var sonoUscito = true;
$(document).ready(function() {
    $("#box-offerte-testo .itemOffertaRot").hover(
    function() {
        //clearTimeout(timerRotOfferte);
        if (sonoUscito) {
            $('#box-offerte-testo .descBreveOffertaRot:eq(' + $('#box-offerte-testo .itemOffertaRot').index(this) + ')').stop(true, true).toggle(300);
            $('#box-offerte-testo').cycle('pause');
        }
        sonoUscito = true;
    },
    function() {
        $('#box-offerte-testo .descBreveOffertaRot:eq(' + $('#box-offerte-testo .itemOffertaRot').index(this) + ')').stop(true, true).toggle(400);
        $('#box-offerte-testo').cycle('resume');
        sonoUscito = false;
        setTimeout(function() { sonoUscito = true; }, 600);
    });
});

$(document).ready(function() {
    $('#box-offerte-testo')
    .cycle({
        fx: 'fade',
        sync: 1,
        speed: 1000,
        timeout: 6000
    });
});


$(function() {
    if ($("#boxImgGallerry .imgFluida").size() < 2) {
        $("#boxOmbraComandiGallery").hide();
    }
});
