jQuery(document).ready(function()
{
		
	$('.image a[rel]').overlay(
	{
		onBeforeLoad: function()
		{
			this.getOverlay().appendTo('body');
			$('#image_canvas, #image_canvas h3').css('opacity', 0);
			var image_url = $(this.getTrigger()).attr('href');
			var image_title = $(this.getTrigger()).children('span').text();
			var image_description = $(this.getTrigger()).children('em').html();
			
			var img = new Image();
			$(img).attr('src', image_url).load(function()
			{
				$(this).appendTo('#image_canvas');
				
			var image_width = $(img).width();
			var image_height = $(img).height();
			// alert(image_width);
			
			var overlay_width = (image_width + 48 + 266);
			
			$('#image_overlay.simple_overlay').css('margin-left', -(overlay_width/2)).animate({ width: overlay_width, height: image_height+62 }, 300);
			$('#image_canvas').css('width', image_width);			
			$('#image_canvas, #image_canvas h3').animate({ opacity: 1 }, 1000);
														   
			});
			
			
			$('#image_canvas h3').text(image_title);
			$('#image_overlay .details p').html(image_description);
			
		},
		onClose: function()
		{
			$('#image_canvas img').remove();	
		},
		top: '15%',
		left: '50%',
		mask: '#000'
	});
	
	
	$('.vimeo a[rel]').overlay(
	{
		onBeforeLoad: function()
		{
			this.getOverlay().appendTo('body');
			var video_url = $(this.getTrigger()).attr('href');
			var video_regexp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
			var video_title = $(this.getTrigger()).children('span').text();
			var video_description = $(this.getTrigger()).children('em').html();
			
			var vimeo_id = video_url.match(video_regexp);
			// alert(vimeo_id[2]);
				
		$('#video_canvas h3').text(video_title);
		$('#video_overlay .details p').html(video_description);
		
		$('#video_canvas').append('<iframe src="http://player.vimeo.com/video/'+vimeo_id[2]+'?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="640" height="360" frameborder="0"></iframe>');
		},
		top: '15%',
		mask: '#000',
		onClose: function()
		{
			$('#video_canvas iframe').remove();	
		}
	});
		
});
