﻿$(document).ready(function() {
    $(".linkLightbox2").lightBox();
    var elementiVisibili = false;

    $('#boxFoto')
    .cycle({
        fx: 'fade',
        sync: 1
    });
    
    $('#rotatorClaim')
    .cycle({
        fx: 'fade',
        sync: 1        
    });

    $(".chiudiGallery").click(function(){
        chiudiGallery();
    });
    /*$('#rotatorNews').cycle({
        fx: 'fade',
        sync: 0,
        delay: -4500
    });

    $('#rotatorOfferte').cycle({
        fx: 'fade',
        sync: 0,
        delay: -6500
    });*/
    var timerLineaAlta = null;
    $(".MenuAlto > li").hover(
        function()
        {
            var position = $(this).position();
            
            var left = position.left;
            var width = $(this).width();
            
            //var asd = "---";
            var spostamentoLineaVecchio = $("#lineaRossaAlta").position();
            //$("#pippo").html("leftli: " + left + " -- leftsottolineatura: " + spostamentoLineaVecchio.left + " -- dovrebbe" + ($("#spostamentoLineaRossa").position()).left + " -->"+ asd);
            

           // $("#spostamentoLineaRossa").show().css("left",left + "px");
            $("#lineaRossaAlta").show().stop(true,true).animate({
                width: width + 'px',
                left: left + 'px'
            }, 500, function() {
                //asd
            });

            
            clearTimeout(timerLineaAlta);
        },
        function()
        {
            timerLineaAlta = setTimeout(function(){
            var element = (($(".MenuAlto > li.selezionato").size()>0) ? $(".MenuAlto > li.selezionato") : $(".MenuAlto > li:first"));
            var position = element.position();
            
            var left = position.left;
            var width = element.width();
            
            $("#lineaRossaAlta").show().stop(true,true).animate({
                    width: width + 'px',
                    left: left + 'px'
                }, 600, function() {
                    $("#lineaRossaAlta").hide();
                });
            }, 500);
        }
    );
    
    $(".boxGallery").hover(function(){
        $(".boxGallery .sfondoClaim").stop(true,true).animate({
                height: '119px'
            }, 800, function() {
                //asd
            });
    },function(){
        $(".boxGallery .sfondoClaim").stop(true,true).animate({
                height: '0px'
            }, 800, function() {
                //asd
            });
    });
    
    $(".imgGalleryInternaCOLORI").hide();
    $(".linkLightbox").hover(function(){
        $(this).children(".imgGalleryInternaCOLORI").stop(true,true).fadeIn(1000);
    },
    function(){
        $(this).children(".imgGalleryInternaCOLORI").stop(true,true).fadeOut(1000);
    });
    
    var timerLinea = null;
    $(".menuPrincipale > li").hover(
        function()
        {
            var position = $(this).position();
            
            var left = position.left;
            var width = $(this).width();
            
            //var asd = "---";
            var spostamentoLineaVecchio = $("#spostamentoLineaRossa").position();
            //$("#pippo").html("leftli: " + left + " -- leftsottolineatura: " + spostamentoLineaVecchio.left + " -- dovrebbe" + ($("#spostamentoLineaRossa").position()).left + " -->"+ asd);
            

           // $("#spostamentoLineaRossa").show().css("left",left + "px");
            $("#spostamentoLineaRossa").show().stop(true,true).animate({
                width: width + 'px',
                left: left + 'px'
            }, 500, function() {
                //asd
            });

            
            clearTimeout(timerLinea);
        },
        function()
        {
            timerLinea = setTimeout(function(){
            var element = (($(".menuPrincipale > li.selezionato").size()>0) ? $(".menuPrincipale > li.selezionato") : $(".menuPrincipale > li:first"));
            var position = element.position();
            
            var left = position.left;
            var width = element.width();
            
            $("#spostamentoLineaRossa").show().stop(true,true).animate({
                    width: width + 'px',
                    left: left + 'px'
                }, 600, function() {
                    $("#spostamentoLineaRossa").hide();
                });
            }, 500);
        }
    );
    
    var xAnteprime = $(".boxGalleryAnteprimeClass .linkLightbox").size();
    var elementiDaAggiungere = (3 - (xAnteprime % 3));
    //alert(3-(xAnteprime%3)+" asd");
    if(elementiDaAggiungere != 3){
        for(var i=0; i< elementiDaAggiungere; i++){
            $(".boxGalleryAnteprimeClass").append("<a href=\"#\" style=\"width: 70px; height: 70px; position: relative; background-color:#ededed;\" class=\"linkLightbox\"></a>");
        }
    }
});
function apriGallery(){
    $('html,body').animate({ scrollTop: 452 }, 'slow', 'linear', function() {
        //funzione fine
    });
    $("#bordoBoxGallery").css("border-bottom","solid 1px #d7d3d0");
    $("#boxGalleryAnteprime").animate({
    height: '510px'
    }, 1000, function() {
        // Animation complete.
    });

}

function chiudiGallery(){
    $("#bordoBoxGallery").css("border-bottom","none");
    $("#boxGalleryAnteprime").animate({
    height: '0px'
    }, 1000, function() {
        // Animation complete.
    });

}

function archieAnimateHeight(el, t, s){
    var count = 0;
    var elem = el;
    var tempo = t;
    var spazio = s;
    var timer = null;
    setTimeout(function(){ridondanza();}, 40);

    function ridondanza(){
        count++;
        if(count < tempo/40){
            //$("#pippo").html("count: "+count);
            //alert("asd");
            elem.style.height =  parseInt((803-(parseFloat((Math.log(count) / Math.log(tempo/40)))*spazio)),10) + "px";
            timer = setTimeout(function(){ridondanza();}, 40);
        }else{
            //$(".boxAnimImg .immaginePagina").css("position","relative");$(".cuoriciniProdotti").fadeIn(1800);
        }
    }
}

function Ricerca(e) {
    // Recupero il codice del tasto appena premuto

    if (e.keyCode) {
        code = e.keyCode;
    } else {
        if (e.which) {
            code = e.which;
        }
    }
    if (code == 13) {

        __doPostBack('ctl00$cmdCerca', '');
        return false;

    }


}
