window.addEvent('domready', function(){
	
	$$('.homeImage').each(function(homeImage){
		
		var hoverPane = homeImage.getElement("span.homeImageOverlay");
		if(hoverPane){
			hoverPane.set('opacity', '0');
			hoverPane.setStyle('display', 'block');
			
			homeImage.addEvent('mouseover', function(){
				hoverPane.set('tween', {duration: '400'});
				hoverPane.tween('opacity', '1');
			});
			
			homeImage.addEvent('mouseleave', function(){
				hoverPane.set('tween', {duration: '400'});
				hoverPane.tween('opacity', '0');
			})
		}
	});
	
});


// show the current event card
function showVideo(videoID){
	var overlay = $('eventsOverlay');
	var card = $('eventsCard');
	var info = $('eventsInfo');
	
	overlay.setStyle('display','block');
	card.setStyle('display','block');
	
	if(overlay.getStyle('opacity') != .6){
		overlay.setStyle('opacity',0);
		var fade = new Fx.Morph(overlay, {duration: 200, transition: Fx.Transitions.Sine.easeOut}).start({'opacity':.6});
	}
	
	var contents = '<object width="490" height="279" data="http://www.youtube.com/v/'+videoID+'?version=3&amp;hl=en_GB&amp;rel=0" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/'+videoID+'?version=3&amp;hl=en_GB&amp;rel=0" /><param name="allowfullscreen" value="true" /></object>';
	
	info.set('html',contents);
	
	centerEventDialog();
	setTimeout(centerEventDialog,100);
	setTimeout(centerEventDialog,200);	
}


//centers the dialog
function centerEventDialog(){
	var card = $('eventsCard');
	var win = window.getCoordinates();
	var winscroll = window.getScroll();
	var car = card.getCoordinates();
	
	card.setStyle('top', winscroll.y + 70);
	card.setStyle('left', (win.width / 2) - (car.width / 2));	
}

//hides the card and fades the overlay out
function closeEvent(){
	var overlay = $('eventsOverlay');
	var card = $('eventsCard');
	
	overlay.setStyle('opacity',.6);
	var fade = new Fx.Morph(overlay, {duration: 200, transition: Fx.Transitions.Sine.easeOut}).start({'opacity':0});
	card.setStyle('display','none');
}


