$(document).ready(function() {

   $('area').focus(function(){ //ie7 
    
        if($.browser.msie && this.blur){
             $('div.resellerProductAd').hide(0);
            this.blur();
        }
    })

    $("#edit-search-block-form-1").focus();

    $('.upperMenuLink').mouseenter(function() {
        widthLink = $(this).width();
        $(this).find('.borderLink').animate({width: widthLink,height:'1px'}, 100, function() {});
    }),
    $('.upperMenuLink').mouseleave(function() {
        $(this).find('.borderLink').animate({width: '0%'}, 100, function() {});
    });
    
    $('#k1').mouseover(function() {

        $('div.subMenus:not(#subK1,.menuOpened)').animate({height: 'hide'}, 200, function() {}),
        $('#subK1').animate({height: 'show'}, 200, function() {});
    }),
    $('#k2').mouseover(function() {

        $('div.subMenus:not(#subK2,.menuOpened)').animate({height: 'hide'}, 200, function() {}),
        $('#subK2').animate({height: 'show'}, 200, function() {});
    }),
    $('#k3').mouseover(function() {

        $('div.subMenus:not(#subK3,.menuOpened)').animate({height: 'hide'}, 200, function() {}),
        $('#subK3').animate({height: 'show'}, 200, function() {});
    }),
    $('#krossing').mouseover(function() {

        $('div.subMenus:not(#subKrossing,.menuOpened)').animate({height: 'hide'}, 200, function() {}),
        $('#subKrossing').animate({height: 'show'}, 200, function() {});
    })      
});
$(document).ready(function() {
    if ($("#infoContentText").height() < 120) {
        $('#greyTabs').css({marginTop: '-'+(108-($("#infoContentText").height()))+'px'}, 0, function() {});
    } else {
        $("#infoContentText").css({'width':'auto'});
    }
});



$(document).ready(function() {
    var linkpositiontop = $(".leftMenuLinksActive").position();
    var k1linkpositiontop = $("#k1").position();
    if(linkpositiontop) {
      $('#leftMenuDotImg').css({marginTop: (linkpositiontop.top + 2)+'px'});
    } else {
        if(k1linkpositiontop) {
          $('#leftMenuDotImg').css({marginTop: (k1linkpositiontop.top + 2)+'px'});
        }
    }
});
$(document).ready(function() {

    var k1position = $("#k1").position();
    var k2position = $("#k2").position();
    var k3position = $("#k3").position();
    var krossingposition = $("#krossing").position();
    var dotmargin = $("#leftMenuDotImg").css('margin-top');


    $('#k1').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: (k1position.top+2)+'px'}, 100, function() {});
    }),
    $('#k2').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: (k2position.top+2)+'px'}, 100, function() {});
    }),
    $('#k3').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: (k3position.top+2)+'px'}, 100, function() {});
    }),
    $('#krossing').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: (krossingposition.top+2)+'px'}, 100, function() {});
    }),
    $('#contenitori').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: ($("#contenitori").position().top+2)+'px'}, 100, function() {});
    }),
    $('#orologi').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: ($("#orologi").position().top+2)+'px'}, 100, function() {});
    }),
    $('#luci').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: ($("#luci").position().top+2)+'px'}, 100, function() {});
    }),
    $('#accessori').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop: ($("#accessori").position().top+2)+'px'}, 100, function() {});
    }),
    $('#search').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop:  ($("#search").position().top+2)+'px'}, 100, function() {});
    }),
    $('#listino1').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop:  ($("#listino1").position().top+2)+'px'}, 100, function() {});
    }),
    $('#listino2').mouseover(function() {
        $('#leftMenuDotImg').animate({marginTop:  ($("#listino2").position().top+2)+'px'}, 100, function() {});
    }),

    $('div#leftMenuLinks').mouseleave(function() {
        $('div.subMenus:not(.menuOpened)').animate({height: 'hide'}, 200, function() {}),
        $('#leftMenuDotImg').animate({marginTop: dotmargin });
    });
    
    openMenu = function () {
        if ($("#infoContentText").height() > 115) {
            $('#info').animate({marginTop: '-211px'}, 400,"linear", function() {
                $('#infoScheda,#infoVideo,#comeMontare,#doveComperare,#doveComperareAlt').css({'display':'block'});
            });

            $('#infoContentBorder').show(0, function() {});
        } else {
            $('#info').animate({marginTop: '-'+(($("#infoContentText").height()+93))+'px'}, 400, function() {
                $('#infoScheda,#infoVideo,#comeMontare,#doveComperare,#doveComperareAlt').css({'display':'block'});
            });
        }
        $('#infoLinkUp').hide(0, function() {});
        $('#infoLinkDown').show(0, function() {});
        $('#greyBar').hide(0, function() {});
    }
    closeMenu = function () {
            $('#infoScheda,#infoVideo,#comeMontare,#doveComperare,#doveComperareAlt').css({'display':'none'});
            $('#info').animate({marginTop: '-37px'}, 400, function() {});
            $('#infoLinkUp').show(0, function() {});
            $('#infoLinkDown').hide(0, function() {});
            $('#greyBar').show(0, function() {});
    }
    showLeft = function () {

        $('#slideshow,#backLink,#leftslide').animate({marginLeft: '0px'}, 400);
        $('#rightSlide').animate({marginLeft: '0px'}, 400);
        if(!$.browser.msie){
            //$('div#infoHeader div#h2').css({'margin-left':'-21px'});
            $('div#theProductSlider div#leftSlide img').css({'opacity':'1','visibility':'visible'});
        } else {
            $('div#theProductSlider div#leftSlide').show();
        }
        $('#bigImgLink').css({'visibility':'visible'});
        $('#theProductSlider').css({'position':'relative','float':'left'});
        $('#videoSlide').animate({marginLeft: '788px'}, 400);
        $('#videoSlideContainer').hide();
        $('div#info .jScrollPaneContainer').css({'left':'-28px'});
        $('#infoHeader').unbind('click');
        $('#infoHeader').toggle(function(){openMenu ();},function(){closeMenu();});
    }
    showRight = function () {
        if($.browser.msie){
            $('div#theProductSlider div#leftSlide').hide();
        } else {
            $('div#theProductSlider div#leftSlide img').css({'opacity':'0','visibility':'hidden'});
        }
        $('#bigImgLink').css({'visibility':'hidden'});
        $('#theProductSlider').css({'position':'static','float':'none'});
        $('#slideshow,#backLink').animate({marginLeft: '-788px'}, 400,'linear');
        $('#rightSlide').animate({marginLeft: '-789px'}, 400,'linear');
        $('#videoSlide').animate({marginLeft: '0px'}, 400,'linear',function(){
                $('#videoSlideContainer').show();
                $("#infoHeader").click(function(){showLeft();});
            }
        );
        $("#infoHeader").trigger("click");
    }

    $('#infoHeader').toggle(function(){openMenu ();},function(){closeMenu();}),
    $('#backLinkVideo').click(function(){
        showLeft();
    });
    $('#infoVideo').click(function(){
        showRight();
    }),

    $('#slideProd .slideProductSingle').mouseenter(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'110px'},400, function() {});
    }),
    $('#slideProd .slideProductSingle').mouseleave(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'160px'},400, function() {});
    }),
    $('div#slideProdNoScroll .slideProductSingle').mouseenter(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'110px'},400, function() {});
    }),
    $('div#slideProdNoScroll .slideProductSingle').mouseleave(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'160px'},400, function() {});
    }),

    $('div#slideProdNoScrollMiddle .slideProductSingle').mouseenter(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'301px'},400, function() {});
    }),
    $('div#slideProdNoScrollMiddle .slideProductSingle').mouseleave(function() {  
        $(this).find('.slideProductSingleInfoTrigger').animate({height:'336px'},400, function() {});
    }),
/*
    $('.jScrollPaneDrag').mouseenter(function(){
        $(this).css({background:'#F16F2E'});
    });
*/
    $('#slideshow').cycle({ 
        fx:     'fade', 
        speed:  'fast', 
        timeout: 0, 
        next:   '#next2', 
        prev:   '#prev2',
        sync:1,
	cleartypeNoBg: true
    }),
    $('#bigImgLink').cycle({ 
        fx:     'fade', 
        speed:  'fast', 
        timeout: 0, 
        next:   '#next2', 
        prev:   '#prev2',
        sync:1,
	cleartypeNoBg: true
    }),
    $('#slideshownews').cycle({ 
        fx:     'fade', 
        speed:  'fast', 
        timeout: 3000,
        sync:1,
	cleartypeNoBg: true
    }),
    $('div#slidesubtitle').cycle({ 
        fx:     'fade', 
        speed:  'fast', 
        timeout: 0, 
        next:   '#next2', 
        prev:   '#prev2',
        sync:1,
	cleartypeNoBg: true
    }),
    $('#slideProd').cycle({ 
        fx:     'scrollHorz', 
        speed:  'fast', 
        timeout: 0, 
        next:   '#next2', 
        prev:   '#prev2',
	cleartypeNoBg: true
    }),
    $('#homeGallery .view-content').cycle({ 
        fx:     'fade', 
        speed:  'fast',
        random: 1,
        timeout: 4000,
        sync:1,
	cleartypeNoBg: true
    }),
    $(document).keydown(function(e){
            if(e.which == 37){ $('#prev2').click();}
            else if(e.which == 39){ $('#next2').click();}
    }),
    $('#contactsListScrollableBBB').jScrollPane({topCapHeight: '30px',bottomCapHeight: '30px'});

    $('#resellerListScroll .regioniListItem').hide(0);

    $('#privatiContainer').jScrollPane({topCapHeight: 48,bottomCapHeight: 48,animateTo:false,dragMaxHeight:150});
    $('.newsListContainerArchive').jScrollPane({topCapHeight: 48,bottomCapHeight: 48,animateTo:false,dragMaxHeight:150});
    $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'27',animateTo:true, animateInterval:50, animateStep:5});



    jQuery.each(jQuery.browser, function(i) {
       if($.browser.msie){
            $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'17',animateTo:true, animateInterval:50, animateStep:5});
       }else{
            $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'27',animateTo:true, animateInterval:50, animateStep:5});
       }
     });

    if($.browser.webkit){
           $('div#searchBox form input#edit-search-block-form-1').css({'height':'15px'});
    }
    reinitialiseScrollPane = function() {
        $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'27',animateTo:false});

        jQuery.each(jQuery.browser, function(i) {
           if($.browser.msie){
                $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'17',animateTo:false});
           }else{
                $('#resellerListScroll').jScrollPane({topCapHeight: 48,scrollbarMargin:'27',animateTo:false});
           }
         });
    }

    $('#keyColumn').jScrollPane();
    if($('#rightSearch .resultTitle').size() > 3) {
        $('#rightSearch').jScrollPane({topCapHeight: 22,bottomCapHeight: 18});
    } else {
        $('#rightSearch').css({'overflow':'visible'});
        $('#rightSearch').css({'float':'left'});
    }

    $('#nodeNewsContent').jScrollPane({scrollbarMargin:'70'}),
    $('#infoContent').jScrollPane({scrollbarMargin:'70',scrollbarOnLeft:false}),

    $('div#contactsForms').mouseenter(function(){
        $('div#contactsContainer').animate({marginLeft: '-567px'}, 500, function() {});
    }),
    $('div#contactsListContainer').mouseenter(function(){
        $('div#contactsContainer').animate({marginLeft: '0px'}, 500, function() {});
    }),

    $('div#contactsFormMenu > div').click(function(){
        $('div#contactsFormForm > div').hide();
        $('div#contactsFormMenu > div').css({backgroundColor:'#6e6e6e'});
        $(this).css({backgroundColor:'#f36e30'});
    });

    $('div#contactsFormMenuInfo').click(function(){
        $('div#contactsFormFormInfo').show();
    }),
    $('div#contactsFormMenuPress').click(function(){
        $('div#contactsFormFormPress').show()
    }),
    $('div#contactsFormMenuAmministrazione').click(function(){
        $('div#contactsFormFormAmministrazione').show()
    }),
    $('div#contactsFormMenuReclami').click(function(){
        $('div#contactsFormFormReclami').show()
    }),
    $('div#contactsFormMenuJobs').click(function(){
        $('div#contactsFormFormJobs').show()
    })
});
//Cartinaaaa
$(document).ready(function() {


   /* $('#cartinabg').load(function(){
        
    $('#mapRegioni').hide();
            $('#mapRegioni').show();
        
    });*/
    
    $('#resellerListScroll .regioniListItem').hide(0);
    $('#resellerListScroll .jScrollPaneDrag').hide(0);
    $('#resellerListScroll .regioniListItem').css({marginTop:'0px'});

    $('map#resellers > area,map#resellersWorld > area').hover(function(){
    
        $('div#mapRegioni img:not(.clickedRegion)').hide();
        var regione = $(this).attr("id");
        $('div#mapRegioni img#img'+regione).show();
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({backgroundColor:'#6e6e6e'});
        $('div#regioniResellers ul li a#'+regione).css({color:'#ffffff'});
    },  function(){
        $('div#mapRegioni img:not(.clickedRegion)').hide();
        var regione = $(this).attr("id");
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({backgroundColor:''});
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({color:'#969696'});
    });

    $('div#regioniResellers ul li a').hover(function(){
        $('div#mapRegioni img:not(.clickedRegion)').hide();
        var regione = $(this).attr("id");
        $('div#mapRegioni img#img'+regione).show();
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({backgroundColor:'#6e6e6e'});
        $('div#regioniResellers ul li a#'+regione).css({color:'#ffffff'});
    },  function(){
        $('div#mapRegioni img:not(.clickedRegion)').hide();
        var regione = $(this).attr("id");
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({backgroundColor:''});
        $('div#regioniResellers ul li a#'+regione+':not(a.clickedRegion)').css({color:'#969696'});
    });

    var $resellerListScroll = $('#resellerListScroll');

    $('div#regioniResellers ul li a').bind(
	    'click',
	    function()
	    {
            $('div.resellerProductAd').hide(0);
            $('.jScrollPaneDrag').show(0);

		    var targetElementSelectorString = $(this).attr('id');

            $('div#mapRegioni img').hide();

            $('div#regioniResellers ul li a')
                .css({backgroundColor:'', color : '#969696'})
                .removeClass('clickedRegion');
                
            $('.clickedRegion').removeClass('clickedRegion');

            $('div#mapRegioni img#img'+targetElementSelectorString)
                .show()
                .addClass('clickedRegion');

            $('div#regioniResellers ul li a#'+targetElementSelectorString)
                .css({backgroundColor:'#f36e30'})
                .css({color:'#ffffff'})
                .addClass('clickedRegion');

            $('div.regioniListItem').show();
            //$('div.regioniListItem').css({'margin-right':'0px'});
            $('div.regioniListItem:not(div#'+targetElementSelectorString+')').hide();
		    $resellerListScroll[0].scrollTo('#'+targetElementSelectorString);

            reinitialiseScrollPane();
            $('#resellerListScroll')[0].scrollTo(1);
		    return false;
	    }
    );
    $('map#resellers area:not(#goBack)').bind(
	    'click',
	    function()
	    {
	        if(this.blur) this.blur();
	    
            $('.jScrollPaneDrag').show(0);
            $('div.resellerProductAd').hide(0);

		    var targetElementSelectorString = $(this).attr('id');

            $('div#mapRegioni img').hide();

            $('.clickedRegion')
                .css({backgroundColor:'', color : ''})
                .removeClass('clickedRegion');

            $('div#mapRegioni img#img'+targetElementSelectorString)
                .show()
                .addClass('clickedRegion');

            $('div#regioniResellers ul li a#'+targetElementSelectorString)
                .css({backgroundColor:'#f36e30', color : '#ffffff'})
                .addClass('clickedRegion');

            $('div.regioniListItem').show();
            //$('div.regioniListItem').css({'margin-right':'0px'});
            $('div.regioniListItem:not(div#'+targetElementSelectorString+')').hide();
		    $resellerListScroll[0].scrollTo('#'+targetElementSelectorString);

            $('div.regioniListItemWorld').show();
            //$('div.regioniListItem').css({'margin-right':'0px'});
            $('div.regioniListItemWorld:not(div#'+targetElementSelectorString+')').hide();
		    $resellerListScroll[0].scrollTo('#'+targetElementSelectorString);

            reinitialiseScrollPane();
            $('#resellerListScroll')[0].scrollTo(1);

		    return false;
	    }
    );
    $('map#resellersWorld area:not(#goBack)').bind(
	    'click',
	    function()
	    {
            $('.jScrollPaneDrag').show(0);
		    var targetElementSelectorString = $(this).attr('id');

            if($('#resellerListScroll #'+targetElementSelectorString).children().size() > 0) {
                $('#resellerListAdvice').hide();
                $('.regioniListItemWorld').hide();
                $('.regioniListItemWorld').fadeIn(200);
    			$('#resellerListScroll')[0].scrollTo('#'+targetElementSelectorString,{onAfter:$('#resellerListAdvice').hide()});
            } else {
                $('#resellerListAdvice').hide();
                $('#resellerListAdvice').fadeIn(200);
                $('.regioniListItemWorld').hide();
    			$('#resellerListScroll')[0].scrollTo('#resellerListAdvice');
            }
		    return false;
	    }
    );
    $('div.resellerListNation:first').css({'margin-top':'0px'});
    if($.browser.mozilla){
            $(".switchMapLinkLogged").css({'margin-top':'-47px'});
    };
});
/*
    REGISTRATION FORM
*/
$(document).ready(function() {
    $('div#registerButton').click(function(){
        $('div#registerLogin').animate({marginLeft:'-596px'},100);
    });
});

