// JavaScript Document

var triggers;
initialize = function(){
    // TOPMENU    	
    $.jFastMenu("#topMenu");
	
	var bottomMenu = $("#bottomMenu");
	bottomMenu.find("ul:first").css({width:bottomMenu.width(),float:"none"});
	bottomMenu.css("width", bottomMenu.parent().width());
	bottomMenu.find("li.toplevel:last").css("border","none");
	
	var presentation = $("#presentation");
	$("#presentation").find("a:nth-child(4n) .thumbnail").css("margin-right", 0);
	presentation.find(".thumbnail").hover(function(){
		$(this).css("background-color", "#88D6F5");
	},
	function(){
		$(this).css("background-color", "");
	});
	
	
	var venuepresentation = $(".venuespresentation");
	if(venuepresentation !== null){			
		venuepresentation.find(".thumbnail:nth-child(3n)").css("margin-right", 0);
	}
	
	$(".bigTitle:first").css("margin-top", 0);
	
	
	var photogallery = $(".photogallery");
	if(photogallery !== null){	
		$(".photogallery").find(".thumbnail:nth-child(3n)").css("margin-right", 0);
		
		photogallery.find(".thumbnail").hover(function(){
			$(this).css("background-color", "#88D6F5");
			
			var imgname = $(this).find('img').attr("src");				
			imgname = imgname.slice(0,imgname.length-4);
			var imgext = $(this).find('img').attr("src").slice(imgname.length);				
			var imgLargeName = imgname +"_large" + imgext;
			
			$('#photoOverlay').find('img').attr('src', imgLargeName).bind("load").trigger("load");			
			
			imgLargeName = null;
			imgext = null;
			imgname = null;
		},
		function(){
			$(this).css("background-color", "");
		});
		
		
		triggers = $("img[rel]").overlay({
			top:'20%',
			mask: {				
				color: '#505050',
				loadSpeed: 200,
				opacity: 0.4
			},
			oneInstance: true,
			closeOnClick: true,
			onClose:function(){
				var wrap = this.getOverlay().find("div.contentWrap");
				wrap.find('img').attr('src','');
				wrap.find('p').text('');
				wrap = null;
				
				var mask = $("#exposeMask");
				mask.remove();
				mask = null;				
			},
			onBeforeLoad: function() {			
				if(this.getTrigger().attr("rel") == '#photoOverlay'){
					var theTrigger = this.getTrigger();
					var overlay = this.getOverlay();
					var wrap = this.getOverlay().find("div.contentWrap");
					wrap.find('p').text(theTrigger.attr("title")).hide();	
					wrap = null;
				}
			},
			onLoad: function() {			
				var wrap = this.getOverlay().find("div.contentWrap");				
				wrap.find('p').css('width',wrap.find("img").width()).fadeIn();
				wrap = null;	
			}
		});		
	}	
}

$(document).ready(initialize);
