/*
 * European Veterinary Week 2008
 */

//Declare vetweek namespace
vetweek = {};

/*
 * Variables
 */

//Number of backgrounds
vetweek.nbBackgrounds		= 4;
//Current background used
vetweek.currentBackground	= 0;
//Time between background switching (in ms)
vetweek.cycleTime			= 15000;
//Minimum background size
vetweek.minBackgroundHeight	= 1000;
//Boolean for first load
vetweek.firstLoad			= true;

/*
 * Functions
 */

//Change background handler
vetweek.changeBackground = function() {
	var bgNb = vetweek.currentBackground;
	while(bgNb == vetweek.currentBackground)
		bgNb = Math.ceil(vetweek.nbBackgrounds*Math.random());
	vetweek.currentBackground = bgNb;	
	for(var i=1; i<=vetweek.nbBackgrounds;i++) {
		$("div.background" + i).fadeOut(1200);
	}	
	if(vetweek.firstLoad) {
		vetweek.firstLoad = false;
		$("div.background" + bgNb).show();
	}
	else {
		$("div.background" + bgNb).fadeIn(1200);
	}
	setTimeout("vetweek.changeBackground()",vetweek.cycleTime);
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */

vetweek.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


/*
 * Events
 */

//Startup function
$(document).ready(function() {
	//Start background cycling
	vetweek.changeBackground();
	//Resize background containers following content height
	var newHeight = $("div#container").height();
	if(newHeight < vetweek.minBackgroundHeight)
		newHeight = vetweek.minBackgroundHeight;
	$("div.background").height(newHeight);
	//Enable tooltips
	vetweek.tooltip();

        // Hide the language selection links when JS available
        $('#noScript').hide();

});