jQuery(document).ready(function($) {
	
	var bxWidth = 290; // (pixels)
	var sPad = 5; // (pixels)
	var sWidth = bxWidth - (sPad + 20);
	var lWidth = 700;
	
	$('iframe[src*="youtube.com"]').each(function() {
		
		var oWidth = $(this).attr('width');
		var oHeight = $(this).attr('height');
		var oAR = oWidth / oHeight;
		var sHeight = sWidth / oAR;
		$(this).attr('width',sWidth);
		$(this).attr('height',sHeight);
		$(this).wrap('<div class="ytWrap" />');
			var bxHeight_css = sHeight + 'px';
			var bxWidth_css = bxWidth + 'px';
		$(this).parent().css({
			'height':	bxHeight_css,
			'width':	bxWidth_css});
		
	});
	
	var content_for_new_div = '\
<a href="javascript:void(0);">\
	&nbsp;\
</a>\
<div style="clear:both;"></div>\
	';
	
	$('div.ytWrap').append(content_for_new_div);
	
	$('div.ytWrap a').click(function() {
	
		var ytVidBx = $(this).parent();		
		var ytVid = ytVidBx.children('iframe');
		var oWidth = ytVid.attr('width');
		var oHeight = ytVid.attr('height');
		var oAR = oWidth / oHeight;
		var lHeight = lWidth / oAR;
		
		// display the modal
		var modalVar = '<div id="ytModal"><div>' + ytVidBx.html() + '</div></div>';
		$('body').prepend(modalVar);
		// zoom the video
		$('#ytModal iframe').attr({'width':lWidth, 'height':lHeight});
		
		$('.ytWrap iframe').each(function() {
			/*var ytURL = $(this).attr('src');
			ytURL = ytURL + '&amp;wmode=transparent';
			$(this).attr('src',ytURL);*/
			$(this).css('display','none');
		});
		
		// this needs to be inside the small youtube-video 
		// ... 'click' function so that this 'click' listener 
		// ... gets set inside of the dom.
		$('#ytModal a').click(function() {
			$('iframe[src*="youtube.com"]').each(function() {
				/*var ytURL = $(this).attr('src');
				newURL = ytURL.replace('&amp;wmode=transparent','');
				$(this).attr('src',newURL);*/
				$(this).css('display','inline-block');
			});
			$('#ytModal').remove();
		});
		
	});
	
});
