/**
 * YouTube Embedded Video Resizer
 * Version 1.01
 * 
 * Written by Trevor Fitzgerald
 * http://trevorfitzgerald.com/
 *
 * This jQuery plugin will automatically resize all of
 * your YouTube video embeds to fill their container's
 * width. The width-height proportion will be maintained.
 *
 * ---
 *
 * Copyright (c) 2009 Trevor Fitzgerald (trevorfitzgerald.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

(function($){
	$.youtubeResize = function() {
	/*
		$('embed[src*="youtube.com"]').each(function(){
			sizeRatio = $(this).attr('width') / $(this).attr('height');
			newWidth = $(this).parent().parent().width();
			newHeight = Math.round(newWidth / sizeRatio);
			$(this)
				.attr('width', newWidth)
				.attr('height', newHeight)
				.parent()
					.attr('width', newWidth)
					.attr('height', newHeight);
		});
		$('object[data*="http://www.youtube.com/"]').each(function(){
			sizeRatio = $(this).attr('width') / $(this).attr('height');
			newWidth = $(this).parent().parent().width();
			newHeight = Math.round(newWidth / sizeRatio);
			$(this)
				.attr('width', newWidth)
				.attr('height', newHeight)
				.parent()
					.attr('width', newWidth)
					.attr('height', newHeight);
		});
	*/
		$('object').each(function(){
			sizeRatio = $(this).attr('width') / $(this).attr('height');
			newWidth = $(this).parent().parent().width();
			newHeight = Math.round(newWidth / sizeRatio);
			$(this)
				.attr('width', newWidth)
				.attr('height', newHeight)
				.parent()
					.attr('width', newWidth)
					.attr('height', newHeight);
		});
		$('embed').each(function(){
			sizeRatio = $(this).attr('width') / $(this).attr('height');
			newWidth = $(this).parent().parent().width();
			newHeight = Math.round(newWidth / sizeRatio);
			$(this)
				.attr('width', newWidth)
				.attr('height', newHeight)
				.parent()
					.attr('width', newWidth)
					.attr('height', newHeight);
		});	
		$('iframe').each(function(){
			sizeRatio = $(this).attr('width') / $(this).attr('height');
			newWidth = $(this).parent().parent().width();
			newHeight = Math.round(newWidth / sizeRatio);
			$(this)
				.attr('width', newWidth)
				.attr('height', newHeight)
				.parent()
					.attr('width', newWidth)
					.attr('height', newHeight);
		});
		
		/*	
		$('embed[src*="youtube.com"]').each(function(){
			orig_height = $(this).attr('height');
			rounded = Math.ceil(orig_height / 15);
			new_height = rounded * 15;
			$(this).attr('height', new_height);
		});
		$('object[data*="http://www.youtube.com/"]').each(function(){
			orig_height = $(this).attr('height');
			rounded = Math.ceil(orig_height / 15);
			new_height = rounded * 15;
			$(this).attr('height', new_height);
		});
		*/
		
		$('object').each(function(){
			orig_height = $(this).attr('height');
			rounded = Math.ceil(orig_height / 15);
			new_height = rounded * 15;
			//$(this).attr('height', new_height);
			$(this).wrap('<div class="clearfix" style="height:'+new_height+'px">');
			//$(this).after('</div>');
		});
		$('embed').each(function(){
			orig_height = $(this).attr('height');
			rounded = Math.ceil(orig_height / 15);
			new_height = rounded * 15;
			//$(this).attr('height', new_height);
			$(this).wrap('<div class="clearfix" style="height:'+new_height+'px">');
			//$(this).after('</div>');
		});
		$('iframe').each(function(){
			orig_height = $(this).attr('height');
			rounded = Math.ceil(orig_height / 15);
			new_height = rounded * 15;
			//$(this).attr('height', new_height);
			$(this).wrap('<div class="clearfix" style="height:'+new_height+'px">');
			//$(this).after('</div>');
		});		
	};
})(jQuery);

