$(document).ready(function(){

	var curVid = 0;
		
	$("div.video").each(function(){
		
		curVid++;
		
		// select the YT player in this div
		var myObject = $(this).children(":first");

		// get width and height of YT player
		var myWidth = parseInt(myObject.attr("width"));
		var myHeight = parseInt(myObject.attr("height"));

		// hide the div and set ID for fancybox to point to
		$(this).hide().attr("id","video"+curVid);
				
		$("#images").prepend("<p class='video_link'><a class='video_link video_link"+curVid+"' href='#video"+curVid+"'>Watch video</a></p>");

		$("a.video_link"+curVid).fancybox({
			'hideOnContentClick': false,
			'overlayShow':	true,
			'overlayOpacity': .8,
			'overlayColor': "#000",
			'zoomOpacity':true,
			'frameWidth':myWidth,
			'frameHeight':myHeight
		});
	});

});
