/**
 * flowplayer.embed 3.0.2. Flowplayer JavaScript plugin.
 * 
 * This file is part of Flowplayer, http://flowplayer.org
 *
 * Author: Tero Piirainen, <info@flowplayer.org>
 * Copyright (c) 2008 Flowplayer Ltd
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * SEE: http://www.opensource.org/licenses
 * 
 * Date: 2008-11-25 11:29:03 -0500 (Tue, 25 Nov 2008)
 * Revision: 1316 
 */ 
(function() {
	function toAbsolute(url, base) {		
		if(url==undefined&&base!=undefined) { return base; }
		if (url.substring(0, 4) == "http") { return url; }
		if (base) {			
			return base + (base.substring(base.length -1) != "/" ? "/" : "") + url; 
		}
		base = location.protocol + "//" + location.host;		
		if (url.substring(0, 1) == "/") { return base + url; }
		var path = location.pathname;		
		path = path.substring(0, path.lastIndexOf("/"));
		return base + path + "/" + url;
	}
	$f.addPlugin("embed", function(options) {
		var self = this;
		var conf = self.getConfig(true);
		var opts = {
			width: self.getParent().clientWidth || '100%',
			height: self.getParent().clientHeight || '100%',
			url: toAbsolute(self.getFlashParams().src), 
			index: -1,
			id: "_" + ("" + Math.random()).substring(2, 10),
			allowfullscreen: true,
			allowscriptaccess: 'always'
		};		 
		$f.extend(opts, options);
		opts.src = opts.url;
		opts.w3c = true;
		delete conf.playerId;		
		delete opts.url;
		delete opts.index;
		this.getEmbedCode = function(runnable, index) {		
			var html = flashembed.getHTML(opts, {config: conf});
			if (!runnable)  {
				html = html.replace(/\</g, "&lt;").replace(/\>/g, "&gt;"); 	
			}				
			return html;			
		};
		return self;
	});
})();
