//handler per la gestione eventi
$(document).ready(function(){


    
    //handler per i prodotti
    $(function(){
      $("ul#left-menu li ul").hide(); 
      $("ul#left-menu>li>a").click(function() {
      	$(this).addClass("current");
      	var $subnav = $(this).next();
    		if($subnav.is(":visible")) {
    		$subnav.animate({height: "toggle"}, 750, "easeInOutExpo").prev().removeClass("current");
    		}
    		if(!$subnav.is(":visible")) {
    		$("ul#left-menu li ul:visible").animate({height: "toggle"}, 750, "easeInOutExpo").prev().removeClass("current");
    		$subnav.animate({height: "toggle"}, 750, "easeInOutExpo");
    		}
    		return false;
    	});
    });    
    
    $("#fornitori").click(function(){location.href="fornitori";}); 
    $("#materiale").click(function(){location.href="prodotti#mat_edile";});  
    //--------------------------------------------------------------------------

    //carico il menu
    switch($("body").attr("id")) {
    	 case "chisiamo": id=1; break;
	     case "prodotti": id=2; break;
	     case "servizi": id=3; break;
	     case "contatti": id=4; break;	
	     default: id=0;
    }   
    loadLamps(id);
    //--------------------------------------------------------------------------
    
    
    //form-contatti
    $("#user").focus(function() { $(this).addClass("border-active"); });
    $("#user").blur(function() { $(this).removeClass("border-active"); });    
    $("#email").focus(function() { $(this).addClass("border-active"); });
    $("#email").blur(function() { $(this).removeClass("border-active"); });    
    $("#message").focus(function() { $(this).addClass("border-active"); });
    $("#message").blur(function() { $(this).removeClass("border-active"); });    
    $("#form-contatti").submit( function() {return checkFormContatti();} );
    //--------------------------------------------------------------------------
    
    
    //jmaps    
    var url = 'http://maps.google.it/maps?f=q&hl=it&geocode=&q=cestra+ceramiche&jsv=139e&sll=41.663855,13.398879&sspn=0.011574,0.027895&ie=UTF8&latlng=41691370,13394430,1863647454373552135&ei=BCRASYbYFYKq2wL77uUT&sig2=n5Twc_cmM5ey77YBxj6WGw&cd=1';
    
    if(document.body.clientWidth >= 900) {
        $('#map1').css("width","500px");
        $('#map1').css("height","350px");
    }
    
    $('#map1').jmap('init', {
                        'mapType':'hybrid',
                        'mapCenter':[41.6610460997659, 13.40755820274353],
                        'mapZoom':17,
                        'mapShowjMapsIcon':false
    });
  	$('#map1').jmap('AddMarker', {
  			            'pointLatLng': [41.66060925848492, 13.407123684883118],
  			            'pointHTML': '<p>Via Maria km 5,600 - Giglio di Veroli (FR)</p><p><a href="'+url+'" target="_blank">Ottieni indicazioni</a></p>'
  	});  
    //--------------------------------------------------------------------------
    
    
   

    //accessible-news-slider
    $("#news_slider").accessNews({
	        headline : "<b>News da CestraCeramiche.it</b>",
	        speed : "normal",
			slideBy : 1
	  });

    var dim = $("#content").width() - 10;
    $('.candy_coated').css("width", dim + "px");
    $('.candy_coated .next').css("left",(dim-60)+"px");
    
    $('.news').click( function() {
        var href= this.href;
        var id = href.substr( href.indexOf("=")+1, 4);

        open_popup("news.php","id="+id, 350, 300, 150, 100);
        return false;
    });
    
        //resize dello script al resize della pagina
        $(window).bind('resize', function() {    
            var dim = $("#content").width() - 10;
            $('.candy_coated').css("width", dim + "px");
            $('.candy_coated .next').css("left",(dim-60)+"px");
        });
    //--------------------------------------------------------------------------


    //jcarousel
    jQuery('#mycarousel').jcarousel({
        visible: 4,
        auto: 2,
        scroll: 1,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    //--------------------------------------------------------------------------

    
    //fancybox
	  $("a.fancy").fancybox();
    //--------------------------------------------------------------------------
    
    
    
    //al momento blocco tutti i click  (da togliere a fine testing)
    /*$("a").click( function() {
        return true;
    });*/
 
});

