$(document).ready(function() {
	
	init();
	allineaALtezze();
	
	function init() {
		
		// initialize scrollable
		$(".scrollable").each(function(){
				var i = 0, v = 4, f, p;
				var items = $(this).find('.items');
				var els = items.children();
				while( i < els.size()){
					els.slice( i, i + v ).wrapAll("<div/>");
					i += v;
				}
			});
		beautify_table('.co_corpo table');
		beautify_table('.corpo2 table, .corpo3 table,');
		
		if(jQuery().scrollable) {
			$(".scrollable").scrollable();
		}

		// Fancybox 
		$('a.fancybox').fancybox({
			width: 1100,
			height: 700,
			margin: 0,
			padding: 0
		});
	
	}
	function beautify_table(table){
			$(table).each(function(){
				var t = $(this);
				t.addClass('beauty');
				t.attr('cellpadding','0');
				t.attr('cellspacing','0');
				t.attr('border','0');
				if (! t.parent().is('.tabella.round.shadow')){
					t.wrap('<div/>').parent().addClass('tabella').addClass('round').addClass('shadow');
				}
				t.find('tr:odd').removeClass('bg_ddd');
				t.find('tr:even').addClass('bg_ddd');
				t.css('width','100%');
			});
	}
	
	function allineaALtezze(){
		i = 0
		$(".lista-hp-sopra .item_abstract").each(function(){
			altezza = $(this).height();
			if (altezza>=i){
				i=altezza			
			}
		});
		$(".lista-hp-sopra .item_abstract").css({"height":i});	

		h = 0
		$(".newsBox h3").each(function(){
			altezza = $(this).height();
			if (altezza>=h){
				h=altezza			
			}
		});
		$(".newsBox h3").css({"height":h});	

		g = 0
		$(".newsBox .item_abstract").each(function(){
			altezza = $(this).height();
			if (altezza>=g){
				g=altezza			
			}
		});
		$(".newsBox .item_abstract").css({"height":g});	

		f = 0
		$(".lista-hp-sotto .item_abstract").each(function(){
			altezza = $(this).height();
			if (altezza>=f){
				f=altezza			
			}
		});
		$(".lista-hp-sotto .item_abstract").css({"height":f});	
	}
	/*
	 $('.logo').click(function(){
	  	animateLogo();
			return false;
	 });

	function animateLogo(){
		$('.logo').animate({left:'+=50'}, 'normal', function(){location.href=this.href;});
	}
	*/
});
