var mediaHeight;

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(
		   function() { $(this).addClass(c);  },
		   function() { $(this).removeClass(c); }
    	);
	});
};

$(document).ready(function(){
	if (document.all) { $("#menu li").hoverClass("sfHover"); }
	if (document.all) { $("#menu2 li").hoverClass("sfHover"); }
	
	$("#page").corner();

	differenza = $('#multimedia').height() - $('#Brochures').height();
	massimo = Math.max($('#Brochures').height(),$('#Datasheets').height());
	massimo = Math.max(massimo, $('#Videos').height());
	
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
		var ieversion=new Number(RegExp.$1)
		if (ieversion==6) {}
		else {
			if( massimo > 350 ) {
				diff2 = massimo - 350;
				massimo = 350;
				$('#Brochures ul, #Datasheets ul, #Videos ul').height(350);
				$('.tab').height(380);
				$('#testo').height($('#testo').height() - 350);
				//$('#multimedia').height($('#multimedia').height()-320);
			}
		}
	} else {
		if( massimo > 350 ) {
			diff2 = massimo - 350;
			massimo = 350;
			$('#Brochures ul, #Datasheets ul, #Videos ul').height(350);
			$('.tab').height(380);
			$('#testo').height($('#testo').height() - 350);
			//$('#multimedia').height($('#multimedia').height()-320);
		}
	}
	
	if((massimo + differenza) < $('#testo').height()) {
		$('#multimedia').height($('#testo').height());
	} else {
		$('#testo').height((massimo + differenza));
	}
	
	/*if($('#multimedia').height() < $('#testo').height()) {
	   $('#multimedia').height($('#testo').height());
	} else {
	   $('#testo').height($('#multimedia').height());
	}*/
	mediaHeight = $('#multimedia').height();
});

$(document).ready(function(){
	$("#nav a").click(function() {
		id = $(this).attr("id").substring(3,4);
		if( id == 1 ) {
			$("#nav a").removeClass("sx");
		}
		if( id == 2 ) {
			$("#nav1").addClass("sx");
			$("#nav3").removeClass("sx");
		}
		if( id == 3 ) {
			$("#nav3").addClass("sx");
			$("#nav1").removeClass("sx");
		}
		if($('#multimedia').height() < $('#testo').height()) {
			$('#multimedia').height(mediaHeight);
		}
	});
});

/*$(document).ready(function() {
	$("#search").click(function() {
		if( $("#formRicerca").hasClass("hidden") ) {
			$("#formRicerca").removeClass("hidden");
			$("#s").focus();
		} else {
			if( $("#s").val() != "" && $("#s").val() != "keyword search" ) {
				$("#formRicerca").submit();
			}
			else {
				$("#s").animate( { backgroundColor: '#227ac4' }, 200)
				.animate( { backgroundColor: 'white' }, 200)
				.animate( { backgroundColor: '#227ac4' }, 200)
				.animate( { backgroundColor: 'white' }, 200)
				.animate( { backgroundColor: '#227ac4' }, 200)
				.animate( { backgroundColor: 'white' }, 200);
				$("#s").val("keyword search");
			}
		}
	}),
	$("#s").focus(function() {
		$("#s").val("");
	});
});*/
