$(document).ready(function(){
    // when DOM is ready..

    // Add automatically a pdf icons to pdf links
    $("#leftcontent a[href$='.pdf']").addClass("pdf");

    // Add automatically an email icons to email links
    $("#leftcontent a[href^='mailto:']").addClass("email");

    //vticker
    $('#rightcontent .ticker').jCarouselLite({
        vertical: true,
        visible: 8,
        auto:1500,
        speed:750,
        circular:true,
        hoverPause: true
    //   scroll: 7
    });


    // pngfix
    $(document).pngFix();

    // slideup of the footer contents..
    //    $('.buttonfooter').click(function() {
    //        if ($("#footercontent").is(":hidden")) {
    //            $("#footercontent").toggle('fast');
    //            $('.buttonfooter').css('backgroundPosition','0 0');
    //        } else {
    //            $("#footercontent").toggle('fast');
    //            $('.buttonfooter').css('backgroundPosition','0 -25px');
    //        }
    //    });

    // classes and divs to have rounded corners except for the bastard IE and
    // the Opera browser, used from stupid people (like A.G.) :D
    if ($.browser.mozilla || $.browser.webkit || $.browser.safari)  {
        $('.rounded').corner('5px');//.css('-moz-box-shadow', '0 0 7px #cdcdcd');
        $('.rounded10').corner('10px');
        $('.roundedbottom').corner('bottom');
        $('.roundedtop').corner('top');
        $('#leftcontent .title').corner('5px');
        $('#b2bcontent .title').corner('5px');
        $('#leftcontent img').corner('5px');
        $('#leftcontent .reserved_access').corner('5px');
        $('#leftcontent .gallerycontainer').corner('5px');
        $('#rightcontent .ticker').corner('5px');
    }
    // script useful to identify browser and version
    //    jQuery.each(jQuery.browser, function(i, val) {
    //      $("<div>" + i + " : <span>" + val + "</span>")
    //      .appendTo(document.body);
    //    })


    //adding shadowed class for supported browsers
    if ($.browser.mozilla || $.browser.webkit || $.browser.safari)  {
        $('.shadowed_dark').css('box-shadow','0px 0px 4px #8a8a8a').css('-moz-box-shadow','0px 0px 4px #8a8a8a').css('webkit-box-shadow', '0px 0px 4px #8a8a8a');
        $('.shadowed_dark_top').css('box-shadow','0px -1px 4px 2px #CECECE').css('-moz-box-shadow','0px -1px 4px 2px #CECECE').css('webkit-box-shadow', '0px -1px 4px 2px #CECECE');
        $('.shadowed_dark_bottom').css('box-shadow','0px 4px 4px #CECECE').css('-moz-box-shadow','0px 4px 4px #CECECE').css('webkit-box-shadow', '0px 4px 4px #CECECE');
        $('.shadowed_light').css('box-shadow','0px 0px 7px #fff').css('-moz-box-shadow','0px 0px 7px #fff').css('webkit-box-shadow', '0px 0px 7px #fff');
    }

    //inset shadow for menus
    if ($.browser.mozilla || $.browser.webkit || $.browser.safari)  {
        $('#nav li').mouseover(function(){
            $(this).css('box-shadow','2px 2px 5px #8A8A8A').css('-moz-box-shadow',' 0px 0px 5px #8A8A8A').css('webkit-box-shadow', ' 2px 2px 5px #8A8A8A');
        })
        $('#nav li').mouseleave(function(){
            $(this).css('box-shadow','none').css('-moz-box-shadow','none').css('webkit-box-shadow', 'none');
        })
        $('#nav li ul li').mouseover(function(){
            $(this).css('box-shadow',' 2px 2px 5px #8A8A8A').css('-moz-box-shadow','0px 0px 5px #8A8A8A').css('webkit-box-shadow', ' 2px 2px 5px #8A8A8A');
            $(this.parentNode.parentNode).css('box-shadow',' 2px 2px 5px #8A8A8A').css('-moz-box-shadow','0px 0px 5px #8A8A8A').css('webkit-box-shadow', ' 2px 2px 5px #8A8A8A');
        })
        $('#nav li ul li').mouseleave(function(){
            $(this).css('box-shadow','none').css('-moz-box-shadow','none').css('webkit-box-shadow', 'none');
            $(this.parentNode.parentNode).css('box-shadow','none').css('-moz-box-shadow','none').css('webkit-box-shadow', 'none');
        })
    }


    $(window).scroll(function() {
        var starts = 1650;
        if ( (document.documentElement.scrollTop > starts) || (self.pageYOffset > starts) )
        {
            $('#rightcontentpalmares').css('position','fixed');
            $('#rightcontentpalmares').css('top', '20px');
        }
        else
        {
            $('#rightcontentpalmares').css('position','absolute');
            $('#rightcontentpalmares').css('top', 'auto');
        }
    })



    // overlay and colorbox for brochures
    $(".view").colorbox({
        transition:"elastic",
        speed: '150',
        width:"95%",
        height:"97%",
        iframe:'true',
        scrolling: 'true',
        opacity: 0.65,
        title: function(){
            var url = $(this).attr('href');
            return '<a href="'+url+'" target="_blank">Open In New Window</a>';
        }
    });

    // overlay and colorbox for multimedia slideshow
    $(".viewslideshow").colorbox({
        transition:"elastic",
        speed: '150',
        iframe:'true',
        width:"770px",
        height:"740px",
        scrolling: 'true',
        opacity: 0.65
    });
    $(".whereweare").colorbox({
        transition:"elastic",
        speed: '150',
        iframe:'true',
        width:"95%",
        height:"97%",
        scrolling: 'true',
        opacity: 0.65
    }).qtip({
        content: {
            text: false // Use each elements title attribute
        },
        position: {
            corner: {
                tooltip: 'bottomMiddle',
                target: 'topMiddle'
            }
        },
        style: {
            width: 200,
            padding: 5,
            background: '#FFFFFF',
            color: '#444444',
            textAlign: 'center',
            border: {
                width: 5,
                radius: 5,
                color:  '#24a9cb'
            },
            tip: 'bottomMiddle',
            name: 'dark',
            'font-family': 'Trebuchet MS, Arial, Helvetica, sans-serif',
            'font-size' : '14px'
        },
        show: {
            effect: {
                type: 'fade'
            }
        }
    }) ;

    // overlay and colorbox for Signora del Vento page
    $("a[rel='cometcup']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for Signora del Vento page
    $("a[rel='SdV']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay generic gallery
    $("a[rel='genericGallery']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for adv page
    $("a[rel='adv_spidertechgallery']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for adv page
    $("a[rel='adv_2009']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for adv page
    $("a[rel='adv_2008']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for adv page
    $("a[rel='adv_2007']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    $("a[rel='adv_2006']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });

    // overlay and colorbox for small photo calandario panini on spidertech page
    $("a[rel='calpaninispidertech']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:false,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    // overlay and colorbox for small single image on spidertech page
    $("a[rel='smallspidertechimages']").colorbox(
    {
        slideshow: false,
        rel:'nofollow',
        transition: 'elastic',
        opacity:0.80
    });
    // overlay and colorbox for small single image on spidertech page
    $("a[rel='smallspidertechimages_analisi']").colorbox(
    {
        transition: 'elastic',
        slideshow:true,
        preloading:true,
        slideshowSpeed:4000,
        slideshowAuto:false,
        opacity:0.80
    });
    $("a[rel='smallspidertechimages_wede']").colorbox(
    {
        width: "600px", // without this property images are too narrow and the text below overlaps
        transition: 'elastic',
        opacity:0.80,
        title: function(){
            $('#cboxTitle').css({
                'letter-spacing': '-1px',
                'font-size': '12p',
                'color' : 'black'
            });
            $('#cboxCurrent').css({
                'visibility' : 'hidden'
            });
            $('#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow').css({
                'letter-spacing' : '-1px'
            })
        }
    });
    // overlay and colorbox for small single images
    $("a[rel='singleimage']").colorbox(
    {
        slideshow: false,
        rel:'nofollow',
        transition: 'elastic',
        opacity:0.80
    });
    // overlay and colorbox for reserved form
    $("a.reserved_in_text").colorbox(
    {
        inline:true,
        href:"#rightcontent .reservedform",
        transition: 'elastic',
        width:"300px",
        scrolling:false,
        opacity:0.80
    });

    // increase or decrease fonts
    var originalFontSize = $('#leftcontent .text').css('font-size');
    var originalFontSizeh4 = $('#leftcontent .text h4').css('font-size');
    $(".reset").click(function(){
        $('#leftcontent .text').css('font-size', originalFontSize);
        $('#leftcontent .text h4').css('font-size', originalFontSizeh4);
    });
    $(".aplus").click(function(){
        var currentFontSize = $('#leftcontent .text').css('font-size');
        var currentFontSizeh4 = $('#leftcontent .text h4').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var currentFontSizeNumh4 = parseFloat(currentFontSizeh4, 10);
        var newFontSize = currentFontSizeNum*1.2;
        var newFontSizeh4 = currentFontSizeNumh4*1.3;
        $('#leftcontent .text').css('font-size', newFontSize);
        $('#leftcontent .text h4').css('font-size', newFontSizeh4);
        return false;
    });
    $(".aminus").click(function(){
        var currentFontSize = $('#leftcontent .text').css('font-size');
        var currentFontSizeh4 = $('#leftcontent .text h4').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var currentFontSizeNumh4 = parseFloat(currentFontSizeh4, 10);
        var newFontSize = currentFontSizeNum*0.8;
        var newFontSizeh4 = currentFontSizeNumh4*0.8;
        $('#leftcontent .text').css('font-size', newFontSize);
        $('#leftcontent .text h4').css('font-size', newFontSizeh4);
        return false;
    });
  
    $('.aplus').click(function(){
        $('').css('fontSize','1.1em');
    })
    // qtip per i countdown..
    $('a.sponsorship:[href][title]').qtip({
        content: {
            text: false // Use each elements title attribute
        },
        position: {
            corner: {
                tooltip: 'rightBottom',
                target: 'topLeft'
            }
        },
        style: {
     

            color: '#444444',
            textAlign: 'center',
            tip: 'rightBottom',
            name: 'cream',
            'font-family': 'Arial, Helvetica, sans-serif',
            'font-size' : '16px'
        },
        show: {
            effect: {
                type: 'fade'
            }
        }
    });
    // qtip delle brochures e dei downloads nella right bar
    $('a.brochures:[href][title]').qtip({
        content: {
            text: false // Use each elements title attribute
        },
        position: {
            corner: {
                tooltip: 'rightMiddle',
                target: 'leftMiddle'
            }
        },
        style: {
            width: 200,
            padding: 5,
            background: '#FFFFFF',
            color: '#444444',
            textAlign: 'center',
            border: {
                width: 5,
                radius: 5,
                color:  '#24a9cb'
            },
            tip: 'rightMiddle',
            name: 'dark',
            'font-family': 'Trebuchet MS, Arial, Helvetica, sans-serif',
            'font-size' : '14px'
        },
        show: {
            effect: {
                type: 'slide'
            }
        }
    });
    // qtip dei fumetti nella right bar
    $('a.comics:[href][title]').qtip({
        content: {
            text: false // Use each elements title attribute
        },
        position: {
            corner: {
                tooltip: 'rightMiddle',
                target: 'leftMiddle'
            }
        },
        style: {
            width: 200,
            padding: 5,
            background: '#FFFFFF',
            color: '#444444',
            textAlign: 'center',
            border: {
                width: 5,
                radius: 5,
                color:  '#24a9cb'
            },
            tip: 'rightMiddle',
            name: 'dark',
            'font-family': 'Trebuchet MS, Arial, Helvetica, sans-serif',
            'font-size' : '14px'
        },
        show: {
            effect: {
                type: 'slide'
            }
        }
    });

    $('#rightcontent .reserved').addClass('reserved');

    // +--------------------------------------+
    // | AREA B2B                             |
    // +--------------------------------------+
    // 
    // Questo codice carica lo slidernav nella pagina B2B visualizzando
    // le categorie di prodotti con l'effetto iPhone contacts, ora chiamato direttamente
    // nel file b2b/index.php per gerstire le varie lingue
    // $('#slider').sliderNav();

    $("#sc_cart").smartCart();


    $(".imagecart").fancybox({
        'overlayShow'	: true,
        'overlayOpacity' : 0.25,
        'hideOnOverlayClick' : true,
        'hideOnContentClick' : true,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'showCloseButton' : true,
        'autoScale'     : 'true'
    });
    
// Fase Show al mouse hover
//    $("#slider .slider-content ul ul li").mouseover(
//        function () {
//            $('ul', this).show(150);
//        });
//    // Fase di Hide al mouse leave
//    $("#slider .slider-content ul ul li").mouseleave(
//        function () {
//            $('ul', this).hide(150);
//        });


//    $('#slider .slider-content ul ul li').click(function() {
//        $("#slider .accordion-products").toggle();
//    });


//    Per il busy box questa funzione fa la chiusura della funzione
//    aperta nel file index.php di b2b
      $.unblockUI()

});

