// JavaScript Document
$(document).ready(function(){
	autoAltezza();
	
	$('.mappa').live('click', function(e) {
		e.preventDefault();
		
		path='mappa.asp';
		href=$(this).attr('href');
		nhref=href.split('?');
		if(href.indexOf('?')) path+='?'+ nhref[1];
		//alert(path);
		$('#mappa').load(path).hide().fadeIn('slow');
	});
	
	

/*	$(".rollover").hover(function(){
		//alert($("#mappa-all").attr("src"));
		document.temp=$("#mappa-all").attr("src");
		$("#mappa-all").attr("src","images/"+ $(this).attr("rel"));
	}, function(){
		$("#mappa-all").attr("src",document.temp);
	});
*/	

	$(".rollover").live('mouseover', function(){
		document.temp=$("#mappa-all").attr("src");
		$("#mappa-all").attr("src","images/"+ $(this).attr("rel"));
	});
	$(".rollover").live('mouseout', function(){
		$("#mappa-all").attr("src",document.temp);
	});
	
	
	
	/* Modal Window */
	//select all the a tag with name equal to modal
	$(".modal").live("click", function(e) {
		
		//Cancel the link behavior
		e.preventDefault();
		
		var id = $(this).attr('href');
		
		//alert($(id).is(":visible"));
		if(!($(id).is(":visible"))){
			$(".window:visible").each(function() {
				$(this).animate({
					top: '-=20',
					height: 'toggle',
					opacity: 'toggle'
				}, 400);
			});
		
			//transition effect
			$(id).animate({
				top: '+=20',
				height: 'toggle',
				opacity: 'toggle'
			}, 700);
		}
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//$('#mask').hide();
		$(this).parent().parent().animate({
			top: '-=20',
			height: 'toggle',
			opacity: 'toggle'
		}, 400);
	});
	
	if($('#sx').length) setTimeout("ScrollNews('','')",3000);
	
	if($('.date-pick').length){
		$('.date-pick').datePicker({startDate:'01/01/1996', clickInput:true});
	}
});

var num=1;
function ScrollNews(content,direction){
	if((content!='')&&(direction!='')){
		var totali=$(content +" [name^='item']").length;
		//alert(totali);
		//alert(num);
		if(direction=='+'){
			num++;
			if(num>totali) num=1;
		}else if(direction=='-'){
			num--;
			if(num<1) num=totali;
		}else{
			num=direction;
		}
		
		//alert(num);
		$(content +" .wrapper").scrollTo("[name='item"+num+"']", {duration:1000});
		
		maxheight=$(content +' .wrapper .col').eq(num-1).height();
		$(content +' .wrapper').animate({height: maxheight},1000);
		
	}else{
		var maxheight=0;
		$(content +' .wrapper .col').eq(0).each(function(){
			if($(this).height()>maxheight){
				maxheight=$(this).height();
			}
			//alert($(this).height());
			$(content +' .wrapper').animate({height: maxheight},500);
		});
	}
}

var temp='';
function autoAltezza(){
	var he1=$('#centro').height()+38;
	var he2=$('#dx').height();
	
	if(he1>he2) $('#dx').height(he1);
	
	var he1=$('#centro-p').height()-28;
	var he2=$('#dx-p').height();
	
	if(he1>he2) $('#dx-p').height(he1);
	
	/*var he1 = document.getElementById('#centro').style.height-28;
	var he2 = document.getElementById('#dx').style.height;
	
	if(he1>he2) document.getElementById('#dx').style.height = he1;*/
}
