﻿$(function() {
    $(".linkLightbox").lightBox();
    $("#canali > a").hover(
        function() {
            $(this).stop(false, true).animate({ bottom: 60 }, 1000);
        },
        function() {
            $(this).stop(false, true).animate({ bottom: 5 }, 1000);
        }
    );
    $("#canali_fascia a").hover(
        function() {
            $("#canali > a:eq(" + $(this).index() + ")").stop(false, true).animate({ bottom: 60 }, 1000);
        },
        function() {
            $("#canali > a:eq(" + $(this).index() + ")").stop(false, true).animate({ bottom: 5 }, 1000);
        }
    );

    $('#navigator_mac').Fisheye(
				{
				    maxWidth: 70,
				    items: 'a',
				    itemsText: 'span',
				    container: '#navigator_mac_container',
				    itemWidth: 50,
				    proximity: 80,
				    alignment: 'left',
				    valign: 'bottom',
				    halign: 'center'
				}
			);

    $("#bottoni_Home a").hover(
            function() {
                $(this).children("img").attr("src", $(this).children("img").attr("src").replace(".png", "_sel.png"));
            },
            function() {
                $(this).children("img").attr("src", $(this).children("img").attr("src").replace("_sel.png", ".png"));
            }
        );
    $("#img_bottom_tendina").click(function() {
        if ($("#text_ext_tendinaCosaFacciamo").is(":visible")) {
            $(this).attr("src", $(this).attr("src").replace("Nascondi", "Plus"));
            $("#text_tendinaCosaFacciamo").stop(true, true).slideDown();
            $("#text_ext_tendinaCosaFacciamo").stop(true, true).slideUp();
        } else {
            $(this).attr("src", $(this).attr("src").replace("Plus", "Nascondi"));
            $("#text_tendinaCosaFacciamo").stop(true, true).slideUp();
            $("#text_ext_tendinaCosaFacciamo").stop(true, true).slideDown();
        }
    });

    $("#img_bottom_tendina_home").click(function() {

        $("#tendinaHomeTesto").attr("style", "display:block");
        $("#text_tendinaCosaFacciamo").stop(true, true).slideUp();
        $("#text_ext_tendinaCosaFacciamo").stop(true, true).slideDown();

    });

    $("#img_bottom_tendina_home_chiudi").click(function() {

        $("#text_tendinaCosaFacciamo").stop(true, true).slideDown();
        $("#text_ext_tendinaCosaFacciamo").stop(true, true).slideUp();
        $("#tendinaHomeTesto").attr("style", "display:none");

    });



    if (($(".pagina_oggetti").size() > 1)) {
        $(".freccia.destra").addClass("abilitata");
    }

    $(".freccia.ricarica_ajax").click(function() {
        
        var indexToShow = $(".pagina_oggetti:visible").index();
        var indexNext = 0;

        if ($(this).hasClass("sinistra")) {
            indexToShow = indexToShow - 1;
            indexNext = indexToShow - 1
        } else {
            indexToShow = indexToShow + 1;
            indexNext = indexToShow + 1
        }


        if ($(".pagina_oggetti:eq(" + indexToShow + ")").size() <= 0) {
            return;
        }

        $(".pagina_oggetti:visible").fadeOut();
        $(".pagina_oggetti:eq(" + indexToShow + ")").fadeIn();

        if ($(this).hasClass("sinistra")) {
            $(".freccia.destra").addClass("abilitata");
        } else {
            $(".freccia.sinistra").addClass("abilitata");
        }

        if ($(".pagina_oggetti:eq(" + indexNext + ")").size() <= 0) {
            $(this).removeClass("abilitata");
            $(this).children("img").attr("src", $(this).children("img").attr("src").replace("_sel.jpg", ".jpg"));
        }

        if ($("#navigator_pagine_ajax").size() > 0) {
            $("#navigator_pagine_ajax").html((indexToShow+1) + "/" + $(".pagina_oggetti").size());
        }
    });

    if ($("#navigator_pagine_ajax").size() > 0) {
        $("#navigator_pagine_ajax").html("1/" + $(".pagina_oggetti").size());
    }

    $(".freccia").hover(
        function() {
            if ($(this).hasClass("abilitata")) {
                $(this).children("img").attr("src", $(this).children("img").attr("src").replace(".jpg", "_sel.jpg"));
            }
        },
        function() {
            $(this).children("img").attr("src", $(this).children("img").attr("src").replace("_sel.jpg", ".jpg"));
        }
    );

    $(".oggetto_griglia").hover(
        function() {
            $("body > .dettaglio_oggetto_griglia").remove();
            var clone = $(this).children(".dettaglio_oggetto_griglia").clone();
            $("body").append($(clone));
            //$(this).children(".dettaglio_pop_prodotto").remove();
            var dettaglio = $("body > .dettaglio_oggetto_griglia");
            $(dettaglio).stop(true, true).fadeIn(1000, function() { $(this).find(".titolo_dettaglio_oggetto_griglia").fadeIn(1000).animate({ top: "-18px" }); });

        }, function() {
            $("body > .dettaglio_oggetto_griglia").hide();
            $("body > .dettaglio_oggetto_griglia").remove();
        }
    );
    $(".oggetto_griglia").mousemove(function(e) {
        $('body > .dettaglio_oggetto_griglia').css("left", e.pageX);
        $('body > .dettaglio_oggetto_griglia').css("top", e.pageY + 20);
    });
});
