/**
 * jQuery FlashTag plugin
 * @author Lucas Ferreira - http://lucasferreira.com/
 * @version 1.1b
 * @date October 30, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Lucas Ferreira (lucasferreira.com)
 * @example Visit http://www.lucasferreira.com/flashtag/ for more informations about this jQuery plugin
 */

if(typeof jQuery == "undefined")
{
	alert("jQuery lib is needed for this script.");
}
else
{
	(function($) {

		$.fn.flash = function(movie, id, width, height, initParams, youtube)
		{
			if(typeof movie == "object")
			{
				if(typeof movie["src"] == "undefined" && typeof movie["url"] == "undefined")
				{
					return false;
				}
				
				if(typeof movie["id"] == "undefined") movie["id"] = null;
				if(typeof movie["width"] == "undefined") movie["width"] = "100%";
				if(typeof movie["height"] == "undefined") movie["height"] = "100%";
				
				var initParams = {}, _excep = ["src", "url", "id", "width", "height"];
				for(var i in movie)
				{
					var _EOF = false;
					for(var e in _excep)
					{
						if(_excep[e] == i)
						{
							_EOF = true;
							break;
						}
					}
					
					if(!_EOF)
					{
						initParams[i] = movie[i];
					}
				}
				
				var height = movie["height"];
				var width = movie["width"];
				var id = movie["id"];
				var movie = (movie["src"] || movie["url"]);
			}
			
			var _tempInstance = ((!youtube) ? new Flash(movie, id, width, height, initParams) : new Flash.YouTube(movie, id, width, height, initParams));
			
			if(initParams && initParams["variables"])
			{
				for(var i in initParams["variables"])
				{
					_tempInstance.addVariable(i.toString(), initParams["variables"][i]);
				}
			}
			
			if(this.length > 0)
			{
				this.each(function(){ _tempInstance.writeIn(this); });
			}
			
			return this;
		};

		$.fn.youtube = function(youtube_url, id, width, height, initParams)
		{
			return this.flash(youtube_url, id, width, height, initParams, true);
		};

	})(jQuery);
}
