// JavaScript Document
$(document).ready(function(){
	//setFontSize();
	
	if($("a[rel^='superbox']").length){
		$.superbox.settings = {
			closeTxt: "Chiudi",
			loadTxt: "Carica...",
			nextTxt: "Prossima",
			prevTxt: "Precedente"
		};
		$.superbox();
	}
	
	if($("#rotator").length){
		$("#rotator").fadeTransition({pauseTime: 7000, transitionTime: 2000, ignore: null, delayStart: 0, pauseNavigation: false});		
		$("#rotator").show();
	}
	
	if($("ul#ticker").length){
		$("ul#ticker").liScroll();
	}
	
	if($(".accordion").length){
		initMenu();
	}
	
	if($("#map").length){
		load();
	}
	
	$('.benvenuto').weatherfeed(['ITXX0251']);
	
	setTimeout("ScrollNews('','')",3000);
	
	if($("#avvio").length) $("#avvio").click();
	
	if($(".dipiu").length) $(".dipiu").hide().after('<a href="javascript:;" onclick="javascript:$(this).prev().slideToggle();" class="st-mn testo-mini"><em>&not; altre voci</em></a><br />');

});

$(window).unload(function(){ 
	if($("#map").length){
		GUnload();
	}
});

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').each(function(){
			if($(this).height()>maxheight){
				maxheight=$(this).height();
			}
			//alert($(this).height());
			$(content +' .wrapper').animate({height: maxheight},500);
		});
	}
}

function initMenu() {
	$('.accordion ul').hide();
	$('.accordion ul.active').show();
	$('.accordion li a').click(function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('.accordion ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
		}
	});
}

function getComuni(thelink,callback){
	$.getJSON("../utils/srcComuni.asp",{reg: $(thelink).val()}, function(data){
																	 
	var obj=$(thelink).next().next().next();
	//$(obj).css('background-color','red');
	$(obj).empty();
	//$(obj).append('<option value=""></option>');
		for (i=0; i<data.length; i++) {
			$(obj).append('<option value="'+ data[i].optionValue +'">'+ data[i].optionDisplay +'</option>');
	  	}
		
		if(callback) eval(callback);
	});
}
