// JavaScript Document


 



      function SetHeightBottom(){
		  	var hmain = $('.main').height();	
			var wmain = $(window).height();	
			var htop =$('#frametop').height();
			var hcenter = $('#framecenter').height();
			
			if(wmain>hmain){
				var hh = Number(wmain-hmain);
				$('#framebottom').css("height",Number(wmain-(htop+hcenter))+"px");
			}else{
				var offset_framebottom = $('#framebottom').offset();
				$('#framebottom').css("height",Number(hmain-offset_framebottom.top+10)+"px");
			}
	  }




	$(function(){
                $("form input, form textarea, form select, form button").uniform();
		//$("form ul li.data div.selector").css("width","50px");
        });		




$(document).ready(function(){
					
                        /*    era nella precedente home page                  
                        var h1 = $("#content").height();
                        var h2 = $("#header_content").height();
                        var h3 = Math.ceil(h1+65);
                        $("#frame_left_page .bordershadow-bluelight").css("height",h3+"px");
                        */
                       
                       
                       
                      /////// lightbox

                       
                       
                       
                   
                   
			//////////////////// paginazione lista news
                        if(document.getElementById("box_list_news")){    
                        SetPaging("#box_list_news .box_list_news", 4, 'it'); 
                        }
						   
			///////////////// verifico lunghezze dei box
			SetHeightBottom();				   




                       /// hack ie per versioni

                       if($.browser.msie && ($.browser.version=="9.0")){
                           
                           $('head').append('<link rel="stylesheet" href="/css/hackIE9.css" type="text/css" />');
                       }
			
			
			if ($.browser.msie) {
			$('.bordershadow-bluelight, .bordershadow-blue').each(function(){
			var elm = $(this);
			var left, top, zindex;
			
			
			var ieshadow = $("<div class='ie-shadow'></div>");
			$(elm).after(ieshadow);
			$(ieshadow).width($(elm).width()+10).height($(elm).height()+10);
			
			if($(elm).css("position")=="absolute"){ // se il div � assoluto
			
			var pos = $(elm).offset();
			var marginLeft = Number(parseInt($(elm).css("margin-left"))-5);
			left = ((pos.left)-5)
			top = ((pos.top)-5);
			zindex = $(elm).css("z-index");
			
			$(ieshadow).css("left",  marginLeft+"px").css("top", top + "px").css("z-index",(zindex-1));
			
			
			}else{
			var pos = $(elm).position();
			left = ((pos.left)-5)
			top = ((pos.top)-5);
			$(ieshadow).css("left",  left + "px").css("top", top + "px");
			}
			
			
			})
		}


  /////////////////////// effetto thumb
  
  $("a.hoverthumb").each(function(index){
							

			var w, h;
			var span = $('<span></span>');
			$(span).addClass("hoverthumb");
			$(this).prepend(span);
			$(span).hide();
			
			$(this).hover(
			  function () {
					 w = $(this).find("img").width();	
			         h = $(this).find("img").height();
					 $(span).css("width",(w-10)+"px").css("height",(h-10)+"px");
					 $(span).fadeIn();
			  }, 
			  function () {
					$(span).fadeOut();
			  }
			);

								 
  });









///////////////////////////// menu catalogo prodotti ///////////////////////////////
				$("#frame_left_page .menu_catalogue li.open").each(function(){
                                    
				   var ul_parent = $(this).parent();
                                   var ul_children = $("ul", this);
                                   $(ul_parent).show();
                                   $(ul_children).show();

				   
				});


/*********************    pagina dettaglio prodotto  *********************************/


   
   $(".content_product div.toogle").each(function(index){
       var text = $(this).text();
       if(text==""){
           $(".menu_product li").eq(index).hide();
       }
       
   });
   
   
   var num_text_product = $(".content_product div.toogle").size();
   if(num_text_product>1){
       $(".menu_product li:eq(0) a").addClass("active");
       $(".content_product div.toogle").hide();
       $(".content_product div.toogle").eq(0).show();
   }
   
   
   $(".menu_product li").each(function(){
        var divId = $("a", this).attr("href");
        $("a", this).click(function(){
           $(".menu_product li a").removeClass("active");
           $(this).addClass("active");
           $(".content_product div.toogle").hide();
           $(divId).show(); 
           return false;
        });
        
        
   });
   





/////////////////////////////// news rotator home page e pagine azienda ///////////////////////




	  var page_news_show = 0;



          function ShowNews(){
	   
	        //alert(page_n + " di "+page_news);
			
		 if(page_news_show==page_news_total){ page_news_show = 0; }
			 
	                 $('.box-short-news').hide();
			 $('#box-news-home .ie-shadow, #short_news .ie-shadow').hide();
			 var da = (page_news_show*2);
			 var a = da+1;
                         
			 for(var i=da; i<=a; i++){
			 $('.box-short-news').eq(i).show();
                         var topie = $('.box-short-news').eq(i).position().top;
			 $('#box-news-home .ie-shadow, #short_news .ie-shadow').eq(i).css("top",(topie-5));
			 $('#box-news-home .ie-shadow, #short_news .ie-shadow').eq(i).show();
			 //$('#short_news .bordershadow-bluelight').eq(i).contents().hide().fadeIn();
			 }
	         page_news_show++;
	   }
	   
	   

           var num_news = $('.box-short-news').size();
	   var page_news_total = Math.ceil(num_news/2);
	   
	   
	   if(num_news>2){
	     $('.box-short-news').hide();
		 $('.box-short-news').hide();
		 ShowNews();
		 setInterval(function() {
               ShowNews();
        }, 5000);
	   }









 ////////////////////////////////// news toogle
 
 					var newslength = $(".newstoogle").size();
					if(newslength>1){
						
					$(".newstoogle").not(':eq(0)').addClass("closed");
					
						$(".newstoogle").each(function(index){
													   
						   $("h3", this).attr("id",index);
						   
						   $("h3", this).click(function(){
								
								var index = $(this).attr("id");
								
                                $(".newstoogle").addClass("closed");
								$(".newstoogle").removeClass("open");
								$(".newstoogle").find("div").hide();
								
								var div = $(".newstoogle").eq(index).addClass("open");
								var divtoogle= $(div).find("div");
								var h = $(divtoogle).innerHeight();
								var marginIE = 0;
								
								if ($.browser.msie) {
								 marginIE = 40;	
								}

								
									$(divtoogle).css("height","1px").animate({
									height: (h+marginIE)+'px'}, 1000, function() { 
									
									 //$(divtoogle).css("height",(h-marginIE)+"px")
									
									});
								/*
								if($(divtoogle).hasClass("closed")){
									$(divtoogle).addClass("open");
									$(divtoogle).removeClass("closed");
									var h = $(divtoogle).innerHeight();
									$(divtoogle).css("height","1px").animate({
									height: h+'px'}, 1000, function() { });
								}else{
								    $(divtoogle).addClass("open");
								}*/
							

								//$(".newstoogle:not:eq(1)").find("div").addClass("closed").css("backgroundColor","#FFCC00");
								
							});
						   
						
						});
						
					}






            //////////////////// finestra modale
			

	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
		var src = $(this).attr('href');
		var html = $(id).html();
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#modal-mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#modal-mask').fadeIn(1000);	
		$('#modal-mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

              
		//Set the popup window to center
		
		$("#modal-window").css('top',  winH/2-$("#modal-window").height()/2);
		$("#modal-window").css('left', winW/2-$("#modal-window").width()/2);
		
	
	    $(".content","#modal-window").html('<iframe src="' + src + '" height="'+$("#modal-window").height()+'" width="'+$("#modal-window").width()+'" style="border:none;">');
	    $("#modal-window").show();
		//transition effect
		//$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.modal-window .close, #modal-window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#modal-mask').hide();
		$('.modal-window, #modal-window').hide();
	});		
	
	//if mask is clicked
	$('#modal-mask').click(function () {
		$(this).hide();
		$('.modal-window, #modal-window').hide();
	});



	

	
	
});
