/**
 * This file defines an amsVideo class to control FLV API/Interface
 *
 * @package amsVideo
 * @version 1.0
 * @author Soung Kim
 * @copyright 2005 Automated Marketing Solutions Inc.
 * @link www.prospectstoprofits.com
 */


/**
 * amsVideo  - Basic onComplete, Cookie storing
 *
 * CHANGE LOG:
 * - 2007-02-07 - Soung Kim: This file was created
 */


function PlayCompleted(obj_id) {
  if (!document.getElementById(obj_id)) {
    return;
  }

  var flashDiv = document.getElementById(obj_id);
    while (flashDiv.firstChild) {
       flashDiv.removeChild(flashDiv.firstChild);
    }

  setCookie_v('FLVPlayedCompleted', 'completed', 'Thu, 2 Aug 2028 20:47:11 UTC', '', '', false);

}


function FlashVideoPlay(HolderDiv,divid,swffile,top,left,width,height,transparent,bgcolor) {

  if (getCookie_v('FLVPlayedCompleted') == 'completed') {
      return;
  }

setCookie_v('FLVPlayedCompleted', 'completed', 'Thu, 2 Aug 2028 20:47:11 UTC', '', '', false);

  var flashCode =  "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+width+"' height='"+height+"' id='ams_flv_video' align='middle'>";
      flashCode += "<param name='allowScriptAccess' value='sameDomain' />";
      flashCode += "<param name='quality' value='high' />";
      if (transparent == true) {    flashCode += "<param name='wmode' value='transparent' />"; }
      if (bgcolor != '') {  flashCode += "<param name='bgcolor' value='"+bgcolor+"' />";  }
      flashCode += "<param name='movie' value='"+swffile+"' />";
      flashCode += "<embed src='"+swffile+"' quality='high' wmode='transparent' bgcolor='#ffffff' width='"+width+"' height='"+height+"' name='ams_flv_video' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
      flashCode += "</object>";




 var outerDiv = document.getElementById(HolderDiv);
  // var outerDiv = document.getElementsByTagName("body").item(0)


    /*
      outerDiv.id = 'divid';
      outerDiv.style.position = 'relative';
      outerDiv.style.width = '100%';
      outerDiv.style.display = 'block';
    */
  var innerDiv = document.createElement('div');

      innerDiv.id = divid;
      innerDiv.style.position = 'absolute';
      innerDiv.style.display = 'block';
      innerDiv.style.top = top+'px';
      innerDiv.style.left = left+'px';
      innerDiv.style.width = width+'px';
      innerDiv.style.textAlign = 'center';
      innerDiv.style.zIndex = '9000';


    innerDiv.innerHTML = flashCode;

    outerDiv.appendChild(innerDiv);



}

function setCookie_v(name, value, expires, path, domain, secure)
{
	var date_expires = new Date(expires);
	document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + date_expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}


function getCookie_v(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie_v(name, path, domain) {
    if (getCookie_v(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}




function FindCurrentExecPoint(newcontent) {
  var scripts = document.getElementsByTagName('script');
	for(i=0; i<scripts.length; i++)
	{
		if(i == scripts.length -1)
		{
		 	var targetid = scripts[i].parentNode;
			targetid.innerHTML += newcontent;
			break;
		}
	}
}

function AMSFlvPlayer(file,fwidth,fheight) {
  if(!fwidth) {
      fwidth = "320";
  }
  if (!fheight) {
    fheight = "240";
  }

  var html = "";
      html += "<!-- Begin Flash Video for Progressive download -->";
      html += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' width='"+fwidth+"' height='"+fheight+"' id='FLVPlayer'>";
      html += "<param name='movie' value='/lib/flash/FLVPlayer_Progressive.swf'/>";
      html += "<param name='quality' value='high' />";
	  html += "<param name='salign' value='lt' />";
      html += "<param name='scale' value='noscale' />";
	  html += "<param name='FlashVars' value='&skinName=/lib/flash/clearSkin_3&streamName="+file+"&autoPlay=false&autoRewind=false'/>";

	  html += "<embed src='/lib/flash/FLVPlayer_Progressive.swf' flashvars='&skinName=/lib/flash/clearSkin_3&streamName="+file+"&autoPlay=false&autoRewind=false' ";
      html += " quality='high' scale='noscale' width='"+fwidth+"' height='"+fheight+"' name='FLVPlayer'  type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
      html += "</object>";
      html += "<!-- End Flash Video for Progressive Download -->";

      //FindCurrentExecPoint(html);

	var scripts = document.getElementsByTagName('script');
	for(i=0; i<scripts.length; i++)
	{
		if(i == scripts.length -1)
		{
		 	var targetid = scripts[i].parentNode;
			targetid.innerHTML += html;
			break;
		}
	}

}





