/*
 * 	ezMovie 0.1 - jQuery plugin
 *	written by Ernest Zieliński
 *
 *	Copyright (c) 2010 BULL DESIGN (http://bull-design.pl)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */

/*
 *	simple example for $("#film").ezMovie();
 *
 *		<a class="film" href="film.mp4" width="640" height="480" >film</a>
 *
 *  click example  for $("#clickfilm").ezMovie(); When img tag is in the link - flash is loading after the click.
 *
 *      <a class="film" href="film.mp4" width="640" height="480" ><img src="preview_img.jpg" /></a>
 *
 *  custom settings: width, height, autostart, playerpath
 *
 *  			$("#movie").ezMovie({ "autostart":"1", "playerpath":"/player.swf", "expressinstallPath": "/expressInstall.swf"});
 *
 */

(function($) {

	$.fn.ezMovie = function(options){
		// default configuration properties
		var defaults = {
			width: 		320,
			height: 	240,
			autostart: 	0,
			playerpath: 		"/flash/player.v2.swf",
			expressinstallPath: "/flash/expressInstall.swf"
		};

		var options = $.extend(defaults, options);

		this.each(function(index) {

			var obj = $(this);
			var w = $(obj).attr('width')|| options.width;
			var h = $(obj).attr('height')|| options.height;
			var startPlay = options.autostart || 0;

			if(jQuery(obj).find('img').length)
			{
				jQuery(obj).click(function(event){
					event.preventDefault();
					jQuery(obj).replaceWith('<div id="flvMovie'+index+'" style="width:'+w+'px; height='+h+'px" ></div>');
					swfobject.embedSWF(options.playerpath, "flvMovie"+index, w, h, "9.0.0", options.expressinstallPath,{url:jQuery(obj).attr("href"),szerokosc:w,wysokosc:h,startPlaying:1},{menu:"false",align:"middle",play:"true",loop:"true",scale:"noscale",quality:"high",wmode:"transparent",allowScriptAccess:"sameDomain",salign:"lt"},{});
				});
			}
			else{
				jQuery(obj).replaceWith('<div id="flvMovie'+index+'" style="width:'+w+'px; height='+h+'px" ></div>');
				swfobject.embedSWF(options.playerpath, "flvMovie"+index, w, h, "9.0.0", options.expressinstallPath,{url:jQuery(obj).attr("href"),szerokosc:w,wysokosc:h,startPlaying:startPlay},{menu:"false",align:"middle",play:"true",loop:"true",scale:"noscale",quality:"high",wmode:"transparent",allowScriptAccess:"sameDomain",salign:"lt"},{});
			}
		});
	};
})(jQuery);

