$(document).ready(function(){
	
	
	
	// rollover e blur sul menu principale
	$("#navbar a").hover(
		function(){	$(this).siblings().css('background-position', 'top'); },
		function(){ $(this).siblings().css('background-position', 'bottom'); }
	);
	$("#navbar a").focus(function() {
		$(this).blur();
	});
	
	
	
	/* BoF Carousels */
	$("#sponsor").jCarouselLite({
		visible: 11,
		vertical: true,
		hoverPause:true,
		easing: "easeInOutCirc",
		auto: 900,
		speed: 1000
	});
	$("#calendario > div").jCarouselLite({
		visible: 14,
		scroll: 7,
		circular: false,
		easing: "easeInOutCirc",
		btnNext: "#calendario .next",
		btnPrev: "#calendario .prev",
		speed: 600
	});
	// Prossimi appuntamenti
	if( $("#prossimiAppuntamenti > div").find('li').size() > 1 ){
		$("#prossimiAppuntamenti > div").jCarouselLite({
			visible: 1,
			vertical: true,
			hoverPause:true,
			auto: 3000,
			speed: 1000
		});
	}
	//caroselli footer
	$("#footer .insCarousel > div").each(function() {
		if( $(this).find('li').size() > 3 ){
			var animazione = new Array("easeOutBounce", "easeInBounce", "easeInOutBounce", "easeInCirc", "easeOutCirc");
			var key = Math.floor(Math.random()*6);
			$(this).jCarouselLite({
				visible: 3,
				vertical: true,
				hoverPause:true,
				easing: animazione[key],
				auto: 1000,
				speed: 1500
			});
		}
	});
	/* EoF Carousels */
	
	
	
	
	
	/* ToolTips */
	$('#sponsor img').tipsy({gravity: 'e', title: 'alt'});
	
	$('#calendario ul li a').tipsy({gravity: $.fn.tipsy.autoNS, html: true, offset: 10, title: function() { 
		var strip =  this.getAttribute('original-title').split('::::');
		strip[2] = strip[2].replace(/\n/g, '<br />');
		strip[2] = strip[2].replace(/-br-/g, '<br />');
		return strip[0] +'<p class="red">'+ strip[1] +'</p>'+ strip[2];
	}});
	
	
	
	/* menu */
	$('#menu img').attr('alt','');
	
	$('#menu #links a').click(function() {
		var target = $(this).attr('name');
		if( $('#menu #sottomenu').find('#'+target).css('display') == 'none' ){
			$('#menu #sottomenu div').fadeOut('fast');
			/* Aggiornamento cookie per i sottodomini */
			$.get( 'http://'+ top.location.host + '/includes/subDomain.trigger.php', { subDom: target }, function() {
				$('#menu #sottomenu').find('#'+target).fadeIn('fast');
			});
		}
	});
	
	
	
	
	
	
	
	/* calendario */
	$('#calendarioPartite ul li').not(':last').css('border-bottom','1px dashed #c0c0c0');
	
	
	
	
	
	
	/* inserimento nuovo urlo */
	$('.shoutAdd').live('submit', function() {
		var qstring = 'add=1';
		qstring += '&autore='+ encodeURIComponent($(this).find('input[name=autore]').val());
		qstring += '&contenuto='+ encodeURIComponent($(this).find('input[name=contenuto]').val());
		
		var questo = $(this);
		$.post( 'http://'+ top.location.host + '/includes/shoutboard.trigger.php', qstring, function(data) {
			// al completamento svuoto gli input e aggiorno la lista
			$(questo).find('input[type=text]').val('');
			$('#ShoutBoard ul').empty().load('http://'+ top.location.host + '/includes/shoutboard.trigger.php #ShoutBoard ul li');
		});
		return false;
	});
	// aggiornamento lista urli
	$('.shoutAdd .refresh').live('click', function() {
		$('#ShoutBoard ul').empty().load('http://'+ top.location.host + '/includes/shoutboard.trigger.php #ShoutBoard ul li');
		return false;
	});
	
	
	
	
	
	/* lightbox x li eventi */
	$("a.eventDisplay").click(function() {
		$.colorbox({ href:'http://'+ top.location.host + '/includes/nextevent.trigger.php?datalink='+$(this).attr('href') });
		return false;
	});
	
	
	
	
	
});
