$(document).ready(function() {
	
	// EVENTI HOMEPAGE
	$(".event").hover(function() {
		$(".art").remove();
		$(this).prepend("<div class=\"art\"></div>");	
		if(!$(this).hasClass("current")) {
			$(".event_splash").stop(false,true);	
			
			$(".event").removeClass("current");
			$(this).addClass("current");
			indx = $("#events_items .event").index(this);

			$(".event_splash").fadeOut("slow");
			$(".event_splash:eq("+indx+")").fadeIn("slow");	
		}			
	});
	$("#events_list #events_items .event").each(function() {
		n = $("#events_items .event").index(this);
		$(this).prepend("<span class=\"n\">"+(n+1)+".</span>");
	});	
	$(".event:first").trigger("mouseover");
	$(".event").click(function(e) {
		e.preventDefault();
		location.href = $(this).find("a").attr("href")
	});
	if($("#events_list #events_items .event").size()<2) {
		$("#events_list #events_items").css("background","none");
	}
	// *****************************************	
	
	// TARGET BLANK - aggiungi l'attributo REL="new_window" per link che si aprono in una nuova finestra
	$("a[rel=external]").attr("target","_blank");
	// *****************************************	
	
	// LOGO CLICCABILE	
	$("#logo").click(function() {
		location.href = $(this).find("h1 a").attr("href");
	});
	// *****************************************
	
	// LAYOUT, altezza colonne
	var left_col_height = $("#contents_left").height();
	var contents_height = $("#contents_body").height();
	if(contents_height<left_col_height) $("#contents_body").height(left_col_height);
	// *****************************************		
	
});

$(window).load(function() {
	
	// SEZIONI DISABILITATE
	$(".disabled").each(function() {
		$(this).fadeTo(0,0.4);
		$(this).attr("href","#");
		$(this).find("a").attr("href","#");
	});
	// *****************************************			
	
	// TABS HOMEPAGE
	$("#hometabs li > a").hover(function() {
		if(!$(this).parent().find("div").hasClass("current")) {
			$("#hometabs li .current").slideUp("fast").removeClass("current");
			$(this).parent().find("div").slideDown("fast").addClass("current");						
		}
	});
	// *****************************************	
	
	// LEFT MENU	
	$("#left_menu ul li").hover(function() {
		if($(this).hasClass("pop")) {
			$(this).find("div").fadeTo("fast",0.9).show();
			$(this).children("a").addClass("currentH");
		} else {
			$(this).children("a").addClass("hover");
		}
	},function() {
		if($(this).hasClass("pop")) {
			$(this).find("div").hide();
			$(this).children("a").removeClass("currentH");		
		} else {
			$(this).children("a").removeClass("hover");			
		}
	});
	
	if($.browser.msie) {
		$("#left_menu_list li.l1").click(function() {
			v = $(this).children("a").attr("href");
			if(v!="" && v!=undefined && v!="#") location.href = v;
		});
	}
	// *****************************************
	
	// CONFERENCE TIMETABLE
	$("#conference_timetable ul li a").append("<span></span>");
	// *****************************************
	
	// CONFERENCE AGENDA
	$("#conference_agenda table tr").hover(function() {
		$(this).find("td").addClass("highlight");
	},function() {
		$(this).find("td").removeClass("highlight");		
	});
	
	agenda_previous = $("#conference_timetable ul li a.current").parent().prev().find("a").attr("href");
	if($("#conference_timetable ul li a.current").parent().prev().size()==0) {
		$("#agenda_navigation #previous").hide();
	} else {
		$("#agenda_navigation #previous").attr("href",agenda_previous);
	}
	agenda_next = $("#conference_timetable ul li a.current").parent().next().find("a").attr("href");
	if($("#conference_timetable ul li a.current").parent().next().size()==0) {
		$("#agenda_navigation #next").hide();
	} else {
		$("#agenda_navigation #next").attr("href",agenda_next);
	}	
	// *****************************************	
	
	// PAST COURSES GALLERY
	if($("#past_course_gallery").size()>0) {	
		$("#past_course_gallery_desc span").html("<strong>1</strong> / "+$("#past_course_gallery div img").size());	
		$("#past_course_gallery div").cycle({
			next : $("#past_course_gallery_nav .button1"),
			prev : $("#past_course_gallery_nav .button1b"),
			timeout : 0,
			cleartype: 1,
			prevNextClick : past_course_gallery_nav		
		});
	}
	// *****************************************							
});

function past_course_gallery_nav(isNext, zeroBasedSlideIndex, slideElement) {
	$("#past_course_gallery_desc span").html("<strong>"+(zeroBasedSlideIndex+1)+"</strong> / "+$("#past_course_gallery div img").size());
}

function bus_timetable_print() {
	bg = $("h1.contents_title_smaller").css("background-image");
	$("h1.contents_title_smaller").css("background-image","none");
	window.print();
	$("h1.contents_title_smaller").css("background-image",bg);	
}