$(document).ready(function()
{
	$("#video-thumb img.play").css('opacity', 0.7);
	
	$("#video-thumb").hover(function () 
	{
		$("#video-thumb img.play").fadeTo(150, 1);
	},
	function() 
	{
		$("#video-thumb img.play").fadeTo(400, 0.7);
	});
	
	$('a.popup[href^=#]').click(function() 
	{
		var popupID = $(this).attr('rel');
		var popupURL = $(this).attr('href');
				
		var vars = popupURL.split('?');
		var dim = vars[1].split('&');
		var width = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popupID).fadeIn().css({ 'width': Number( width ) }).prepend('<a href="#" class="close">Close Window</a>');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popupID).height() + 80) / 2;
		var popMargLeft = ($('#' + popupID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popupID).css(
		{
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	
	$('a.close, #fade').live('click', function() 
	{
	  	$('#fade , .overlay').fadeOut(function() 
		{
			$('#fade, a.close').remove();  
		});
		return false;
	});
	
});
