$(document).ready(function() {
// menu
$("#menu").hide();
$("#menuToggle").toggle(
	function () {
		$(this).addClass("active");
		$("#menu").slideDown(300);
	}, function() {
		$("#menu").slideUp(100);
  		$(this).removeClass("active");
		
		}
);
$("#primo").bind("mouseover mouseout",function (event) {
   	 if(event.type=="mouseover"){
	 	$("#primoTxt").css("display", "block")
	 }
	 if(event.type=="mouseout"){
	 	$("#primoTxt").css("display", "none")
	 }
	 
});
$("#secondo").bind("mouseover mouseout",function (event) {
   	 if(event.type=="mouseover"){
	 	$("#secondoTxt").css("display", "block")
	 }
	 if(event.type=="mouseout"){
	 	$("#secondoTxt").css("display", "none")
	 }
	 
});
$("#terzo").bind("mouseover mouseout",function (event) {
   	 if(event.type=="mouseover"){
	 	$("#terzoTxt").css("display", "block")
	 }
	 if(event.type=="mouseout"){
	 	$("#terzoTxt").css("display", "none")
	 }
	 
});
	// $('a[rel^=prettyPhoto]').prettyPhoto({theme:'dark_square', slideshow:5000, autoplay_slideshow:true});
	
	
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="img/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
	}); //fade them both out
		
		return false;
	});
	
	
	//Default Action
	$(".tab_content").hide(); //Hide all content
	
	
	$("#caseHistory li a").click(function() {
		var activeVoice = $(this).attr("rel");
		// alert(activeVoice);
		$("#"+activeVoice+" .tab_content").hide(); //Hide all content
		$("#"+activeVoice+" ul.tabs li:first").addClass("active").show(); //Activate first tab
		$("#"+activeVoice+" .tab_content:first").show(); //Show first tab content
	});
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
$("#cambia1").mouseover(
	function () {
		$('#fisso1').addClass("attivato");
	}
);
$('#cambia1').mouseout(
	function() {
  		$('#fisso1').removeClass("attivato");
	}
);	
$("#cambia2").mouseover(
	function () {
		$('#fisso2').addClass("attivato");
	}
);
$('#cambia2').mouseout(
	function() {
  		$('#fisso2').removeClass("attivato");
	}
);
$("#cambia3").mouseover(
	function () {
		$('#fisso3').addClass("attivato");
	}
);
$('#cambia3').mouseout(
	function() {
  		$('#fisso3').removeClass("attivato");
	}
);		
});
