$(document).ready(function() {
	
	 var cookieMenu = $.cookie('menu');
  if (cookieMenu == 'menuSecondari') { // da menu secondari modifica css senza animazione
    	$('#menu ul li a.selected').css({
        	height: '55px',
			paddingTop: '55px'
        });
        $('#menuLeft ul li a.selected').css({
        	width: "215px"
        });	
    }
});
    
$(window).load(
    function() {
// break long text
	$(".search_result_image .url").each(function() {
	   $(this).html($(this).html().replace(/^(\S{70})(\S+)/,'$1 $2'));
	});

// show hide link in search
	$('.links').hide();
	$('.show_links').show() ;
	$('.show_links').live('click', function () { 
	$(this).next('.links').show('500');
	$(this).removeClass('show_links').addClass('hide_links');
	});
	$('.hide_links').live('click', function () { 
		$(this).next('.links').hide('500');
		$(this).removeClass('hide_links').addClass('show_links');
	});

// show hide footer sitemap
	$('.footerOne').hide();
	$('.showFooterSitemap').show();
    $(".showFooterSitemap").live('click', function () { 
            $('.footerOne').slideToggle('500');
			

			$('.showFooterSitemap').removeClass('showFooterSitemap').addClass('hideFooterSitemap');
    		//$('html, body').animate({
			//			scrollTop: $(".footerOne").offset().top
			//		}, 2000);

        });
	$(".hideFooterSitemap").live('click', function () { 
            $('.footerOne').slideToggle('500');
			$('.hideFooterSitemap').removeClass('hideFooterSitemap').addClass('showFooterSitemap');
    
        });    
// dimensione testo
    if ($.cookie('TEXT_SIZE')) {
        $('body').addClass($.cookie('TEXT_SIZE'));
    }
    $('.resizer li').click(function(){
        var textSize = $(this).attr('class');
        $('body').removeClass('small medium large').addClass(textSize);
        $.cookie('TEXT_SIZE', textSize, {
            path: '/',
            expires: 10000
        });
    });

    
    // non visualizzare secondColumn.bottom vuoto

    if ($('.secondColumn.bottom').is(':empty')) { 
    $('.secondColumn.bottom').hide(); 
	}
	
    // animazione iniziale per la HOME  
    $("#menu.home .bp_item").height('55px');
    $("#menu.home .bp_item").animate({
        height: '220px'
    }, 800);
    
    
    
    var heightNormal = '40px';
    var heightSelected = '55px';    
    
    // animazione uscita pagina  
    // click menuPrincipale nella HOME
    $("#menu.home .bp_item h3 a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'fromHome', {
            path: '/'
        });
        // animazione uscita pagina
        var toLoad = $(this).attr('href');
        
        $("#menu.home .bp_item p").animate({ 
            marginTop: '-500px'
        }, 200);
        $("#menu.home .bp_item").animate({
            height: '55px'
        }, 500);
        setTimeout(function(){
            window.location = "http://www.blackpoints.ch/" + toLoad;
        }, 600)
        return false;
    });
    
    // click menuLeft nella HOME
    $("#menuLeftHome a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'fromHome', {
            path: '/'
        });
        // animazione uscita pagina
        var toLoad = $(this).attr('href');
        $("#menu.home .bp_item p").animate({ 
            marginTop: '-500px'
        }, 200);
       
        $("#menu.home .bp_item").animate({
            height: '55px'
        }, 500);
        setTimeout(function(){
            window.location = "http://www.blackpoints.ch/" + toLoad;
        }, 500)
        return false;
    });
    
    
    // click menu PRINCIPALE
    $("#menu a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'principale', {
            path: '/'
        });
        // animazione uscita pagina
        var toLoad = $(this).attr('href');  
        $("#menu ul li a.selected").animate({
            paddingTop: '15px'
        }, 300);
        $("#menuLeft ul li a.selected").animate({
            width: '189px'
        }, 300);
        setTimeout(function(){
            window.location = "http://www.blackpoints.ch/" + toLoad;
        }, 700);
        return false;
    });
    
    // click menuLeft
    $("#menuLeft a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'menuLeft', {
            path: '/'
        });
        // animazione uscita pagina
        var toLoad = $(this).attr('href');
        $("#menuLeft ul li a.selected").animate({
            width: '189px'
        }, 300);
        $('#menu ul li a.selected').css({
            paddingTop: '55px'  
        }, 300);
        $("#menu ul li a.selected").animate({
            paddingTop: '15px'
        }, 300);
        setTimeout(function(){
            window.location = "http://www.blackpoints.ch/" + toLoad;
        }, 700);
        return false;
    });
    
    // click logo (link alla HOME)
    $("#logo a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'goToHome', {
            path: '/'
        });
        // animazione uscita pagina
        var toLoad = $(this).attr('href');
        $('#menu ul li a.selected').css({
            paddingTop: '55px'  
        });
        $("#menu ul li a.selected").animate({
            paddingTop: '15px'         
        },300);
       
        $("#menuLeft ul li a.selected").animate({
            width: '188px'
        }, 300);
        setTimeout(function(){
            window.location = "http://www.blackpoints.ch/" + toLoad;
        }, 700);
        return false;
    });    
    
    
    // click menu Secondari (nessuna animazione)
    $("#menuB a").click(function(){ // scrivi cookie
        $.cookie('menu', null);
        $.cookie('menu', 'menuSecondari', {
            path: '/'
        });
        var toLoad = $(this).attr('href');
        window.location = "http://www.blackpoints.ch/" + toLoad;
        return false;
    });
    $("#menuC a").click(function(){
        $.cookie('menu', null);
        $.cookie('menu', 'menuSecondari', {
            path: '/'
        });
        var toLoad = $(this).attr('href');
        window.location = "http://www.blackpoints.ch/" + toLoad;
        return false;
    });
    
    $(".secondColumn .bp_pagedescription_column h3 a").click(function(){
        $.cookie('menu', null);
        $.cookie('menu', 'menuSecondari', {
            path: '/'
        });
        var toLoad = $(this).attr('href');
        window.location = "http://www.blackpoints.ch/" + toLoad;
        return false;
    });
    
    
    // animazioni caricamento pagina
    
    var cookieMenu = $.cookie('menu');
    
    // animazione per Home
    if (cookieMenu == 'menuLeft') { // se si arriva da MenuLeft
        $("#menuLeft a").click(function(){ // scrivi cookie
            $.cookie('menu', null);
            $.cookie('menu', 'menuLeft', {
                path: '/'
            });
            var toLoad = $(this).attr('href');
        $("#menu.home .bp_item").animate({
                height: '55px'           
            }, 300);            
            setTimeout(function(){
                window.location = "http://www.blackpoints.ch/" + toLoad;
            }, 700);
            return false;
        });
    }

    // animazione altre pagine
    if (cookieMenu != 'menuSecondari') { // animazione caricamento pagina (tranne se si arriva da menuSecondari) 
        // menu Principale
        $('#menu ul li a.selected').css({
        	height: '55px',
			paddingTop: '15px'
        });
        $("#menu ul li a.selected").animate({
            height: heightSelected,
            paddingTop: '55px'
        }, 300);
        
        // menuLeft
        $("#menuLeft ul li a.selected").width("189px");
        $("#menuLeft ul li a.selected").css('z-index', '3');
        $("#menuLeft ul li a.selected").animate({
            width: '215px'
        }, 300);        
    }     
    
    // animazione menuB - frecce
    if (typeof document.body.style.maxHeight != "undefined") { // per escludere ie6 //
        $("#menuB a:not(.selected)").hover(function(){
            $(this).css({
                backgroundPosition: "-371px 0"
            });
            $(this).animate({
                backgroundPosition: "-143px 0"
            }, 250);
            $(this).css({
                backgroundRepeat: 'no-repeat'
            });
            $(this).css({
                color: '#fff'
            });
            
        }, function(){
            $(this).animate({
                backgroundPosition: "-371px 0"
            }, 250).delay(50).css({
                color: '#000'
            });
            $(this).css({
                backgroundRepeat: 'no-repeat'
            });
            $(this).css({
                color: '#000'
            });
        });
        
        $("#menuC a:not(.selected)").hover(function(){
            $(this).css({
                backgroundPosition: "-371px 0"
            });
            $(this).animate({
                backgroundPosition: "-143px 0"
            }, 250);
            $(this).css({
                backgroundRepeat: 'no-repeat'
            });
            $(this).css({
                color: '#fff'
            });
            
        }, function(){
            $(this).animate({
                backgroundPosition: "-371px 0"
            }, 250);
            $(this).css({
                backgroundRepeat: 'no-repeat'
            });
            $(this).css({
                color: '#000'
            });
        });
    }
    else {
        var menuB = $("#menuB ul").width();
        var menuC = $("#menuC ul").width() + 20;
        var teaser = 700 - menuB - menuC;
        if (teaser > 446){
        var teaser = 446;
        }
        $("#teaser").width(teaser);
        $("#teaser").css("display", "block")
    };
        }
);

