if (!videostrip) {
	var videostrip = {};
}

if (typeof videostrip.bind == "undefined") {
	
	videostrip.bind = function (obj, fun, args) {
		return function() {
	    	if (obj === true) {
				obj = this;
			}
			var f = typeof fun === "string" ? obj[fun] : fun;
	    	return f.apply(obj, Array.prototype.slice.call(args || []).concat(Array.prototype.slice.call(arguments)));
		};
	}
}

if (typeof videostrip.PlayerPlacer == "undefined") {

	videostrip.PlayerPlacer = {
			
		changeVideo: function(targetElement, cnti_key, play_key, width, height, autostart)
		{
			var elm = document.getElementById(targetElement);
			if (!elm)
			{
				return;
			}

			width = (width == "auto") ? parseInt(elm.style.width) : parseInt(width);
			height = (height == "auto") ? parseInt(elm.style.height) : parseInt(height);
			
			// create the <iframe/> element
			elm.innerHTML = '<iframe id="' + "videostrip_widget_iframe_video" + '" src="about:blank" width="' + width + '" height="' + height + '" frameborder="0" scrolling="no"><\/iframe>';

			if (document.frames)
			{
				// IE
				var iframe = document.frames['videostrip_widget_iframe_video'];
				this.putInIframe(iframe, cnti_key, play_key, width, height, autostart);
			}
			else
			{
				// Firefox dynamic IFRAMEs are not available immediately
				this.g_waitForIframe = setInterval(videostrip.bind(this, this.checkIframe), 100, cnti_key, play_key, width, height, autostart);
			}
		},
		
		checkIframe: function(cnti_key, play_key, width, height, autostart)
		{
			var iframe = document.getElementById("videostrip_widget_iframe_video");
			if (!iframe)
			{
				if (window.parent)
				{
					iframe = window.parent.document.getElementById("videostrip_widget_iframe_video");
				}
			}
			if (iframe)
			{
				// IFRAME is now available in the DOM
				clearInterval(this.g_waitForIframe);
				this.putInIframe(iframe, cnti_key, play_key, width, height, autostart);
			}
		},
		
		putInIframe: function(iframe, cnti_key, play_key, width, height, autostart)
		{
			if (iframe)
			{
				var myDocument = iframe.document;
				if (!myDocument) 
				{
					myDocument = iframe.contentDocument;
				}
				if (myDocument)
				{
					myDocument.open("text/html", "replace");
					if (typeof autostart == "undefined" || autostart == "auto")
					{
						sAutostarter = "";
					}
					else if (autostart === true || autostart == "true")
					{
						sAutostarter = "&startmode=AUTOSTART";
					}
					else
					{
						sAutostarter = "&startmode=CLICKTOSTART";
					}
					myDocument.write('<html><head><title>www.videostrip.com<\/title><\/head><body style="margin: 0px;"><script type="text/javascript" src="http://load01.videostrip.com/serve_cad.php?playerwidth=' + width + '&playerheight=' + height + '&cnti_key=' + cnti_key + '&play_key=' + play_key + sAutostarter + '"></scr' + 'ipt>' +'<scr' + 'ipt type="text/javascript">window.setTimeout("document.close();", 2500);<\/scr' + 'ipt><\/body><\/html>');
				}
			}
		}
	}
}
