


//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.

function LC_PLAYER_ACGenerator(){
	this.isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	this.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
}

LC_PLAYER_ACGenerator.prototype.ControlVersion = function()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
LC_PLAYER_ACGenerator.prototype.GetSwfVer = function(){
	
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
		
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	
	else if ( this.isIE && this.isWin && !this.isOpera ) {
		flashVer = this.ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
LC_PLAYER_ACGenerator.prototype.DetectFlashVer = function(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = this.GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(this.isIE && this.isWin && !this.isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

LC_PLAYER_ACGenerator.prototype.AddExtension = function(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

LC_PLAYER_ACGenerator.prototype.Generateobj = function(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (this.isIE && this.isWin && !this.isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  document.write(str);
}

LC_PLAYER_ACGenerator.prototype.FL_RunContent = function(){
  var ret = 
    this.AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  this.Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

LC_PLAYER_ACGenerator.prototype.AC_SW_RunContent = function(){
  var ret = 
    this.AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  this.AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

LC_PLAYER_ACGenerator.prototype.AC_GetArgs = function(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = this.AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

// lcPlayer JavaScript
//
// Copyright Advertising.com 2008

/* 
 *  ### BASE CLASS DEFINITIONS 
 *  The following function definitions apply to both lcPlayer and lcOverlayPlayer
 */

var loadComplete = false;

lcPlayer = function(divName, level_nwid){}


lcPlayer = function(divName, level_nwid) {
 
  this.DEFAULT_SWF_PATH = "lcFlashPlayer";
  this.width = 425;
  this.height = 420;
  this.DEFAULT_FORMAT = "Video-Flash-300-320x240";
  this.DEFAULT_UIMODE = "normal"; 

  //VideoManagerInstance
  this.render = false;
  this.inited = false;  
  //parameter initializations  
  var uimode = 'normal';
  var level = level_nwid;//'Test Affiliate:Test Site';
  this.nwid = "";
  this.mode = "right";
  
  //video properties
  this.videoPath = null;
  this.bgcolor = null;  
  this.format =  this.DEFAULT_FORMAT;
  this.uimode = (uimode != null) ? uimode : this.DEFAULT_UIMODE;
  this.level = (level_nwid != null) ? level_nwid :this.level;  
  this.regions = null;
  this.customAttr = null;
  this.templateName = null;
  this.pageURL = escape(location.href);
  this.baseURL = null;
  this.content = "";
  //JSP
  this.swfBasePath = "http://videoplayer.lightningcast.com/players/fp/";

 // Div name, flash name, and container name
  this.divName = divName;
  this.name = "lcPlayer_" + divName; 
 	this.flash = null;
	this.generator = new LC_PLAYER_ACGenerator();
  // Initialize player
	this.player = null;
	this.rendered = false;
	this.created = false;
 	
	
	// Callback pointer for use in addLoadListener.  
	this.onDOMReady = null;
	
	this.adUrl = null;
	this.adRatio = null;
	
	// LVP-37
	this.animateBanners = true;
	
	lcPlayer.self = this;
		
	LCDisplayRegion.regions = new Array();
}
lcPlayer.prototype = new lcPlayer(); 
lcPlayer.constructor = lcPlayer;





/* ----------------------------------------------------
 * Initialization methods
 *----------------------------------------------------- */
// Mark out the properties, so they are initialized, and included into the flashvars.	
lcPlayer.prototype.initProperties = function() {
		
		this.uimode = ((this.uimode != null) && (this.uimode in {normal:"normal",controls:"controls",none:"none",overlay:"overlay"}) ) ? this.uimode : this.DEFAULT_UIMODE;
		
		this.flashVars = "uimode="+this.uimode;
		
		// calculate how to set level and nwid based on format passed in
		if(this.level.indexOf(":") != this.level.lastIndexOf(":") && (this.level.indexOf(":") != 0) ){ // if level is  Nwid:Affiliate:Site, then indexOf(":") != lastIndexOf(":")  
			//alert("level = " + this.level);
			// get an array of the combined nwid & level. Then split at the colons, to get an array of [nwid, affiliate, site]
			var nwid_level = this.level.split(":");
			// save the nwid (first entry in array)
			this.nwid =  nwid_level[0];
			// combine 2nd & 3rd entries in array to create valid "level" param
			this.level = escape(nwid_level[1] + ":" + nwid_level[2]);
			this.flashVars += "&nwid="+this.nwid+"&level="+this.level;
		}else if(this.level.indexOf(":") == 0){ 		// if leading colon was found  ( LVP-40 )
			this.flashVars += "&level="+this.level; 	// omit nwid altogether so component passes level in "Nwid:Affiliate:Site" or ":Nwid:Affiliate:Site" format
		}else{	
			this.flashVars += "&nwid="+this.nwid+"&level="+this.level;
		}
		// other FlashVars:
		
		this.flashVars += "&format="+this.format+ "&pageURL="+this.pageURL;	
		this.swfObject = this.swfBasePath + this.DEFAULT_SWF_PATH;
		
		//set optional attributes at player creation
		if(this.bgcolor != null){
			this.flashVars += "&bgColor="+this.bgcolor;
		}
		if( this.getRegions != null ) {
		this.flashVars += "&regions="+escape(this.getRegions());
		}
		
		if ( this.videoPath != null ) 
		{ this.flashVars += "&initialVideoPath="+this.videoPath; }
		
		if (this.templateName != null)
		{ this.flashVars += "&templateName="+this.templateName; }
		
		if (this.customAttr != null)
	    {this.flashVars += "&attr="+ this.customAttr; }
		
		
		if (this.baseURL != null)
		{ this.flashVars += "&baseURL="+this.baseURL; }
		
		if ( ((this.adUrl != null) && (this.adUrl != undefined)) && ((this.adRatio != null) && (this.adRatio != undefined)) ) 
		{ this.flashVars += "&adUrl="+this.adUrl + "&adRatio="+this.adRatio; }
}
	
// Create the HTML to render the player.
lcPlayer.prototype.renderPlayer = function() {	
	
	   this.initProperties();
		 
		this.requiredMajorVersion = 9;
		this.requiredMinorVersion = 0;
		this.requiredRevision = 45;
		this.content = "";
		this.flash = "";
		var hasProductInstall = this.generator.DetectFlashVer(9, 0, 45);
		var hasRequestedVersion = this.generator.DetectFlashVer(this.requiredMajorVersion, this.requiredMinorVersion, this.requiredRevision);		

	if (hasProductInstall && !hasRequestedVersion ) {
			var MMPlayerType = (this.generator.isIE == true) ? "ActiveX" : "PlugIn";
			var MMredirectURL = window.location;
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			var MMdoctitle = document.title;
		
			this.flash = this.AC_FL_RunContent(
				"src", "playerProductInstall",
				"FlashVars", "MMredirectURL="+MMredirectURL+"&MMplayerType="+MMPlayerType+"&MMdoctitle="+MMdoctitle+"",
				"width", "100%",
				"height", "100%",
				"align", "middle",
				"id", this.name,
				"quality", "high",
				"bgcolor", "#000000",
				"name", this.name,
				"allowScriptAccess","always",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);

		} else if (hasRequestedVersion) {
			this.flash = this.AC_FL_RunContent(
				"src", this.swfObject,
				"width", this.width,
				"height", this.height,
				"align", "middle",
				"id", this.name,
				"quality", "high",
				"bgcolor", "#cccccc",
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'transparent',
				'devicefont', 'false', 
				"name", this.name,				
				"flashvars", this.flashVars, 
				"allowScriptAccess","always",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer",
				"menu", "true",
				'allowFullScreen', 'false'
			);
		} else {
			this.flash = "This content requires the <a href=http://www.adobe.com/go/getflash/>Adobe Flash Player</a>.";
			this.pluginError = true;
		}
	    this.rendered = true;
		return this.writeStandardPlayer(); 	// writeHTMLEmbed() is actually a call to either writeStandardPlayer() or writeOverlay(), 
										// depending on which constructor is used. This is set in the lcPlayer and lcOverlayPlayer constructors. 
}


lcPlayer.prototype.writeStandardPlayer = function(){
	
		this.width = this.checkPX(this.width);
		this.height = this.checkPX(this.height);
	
		this.content = "";
		
		//this.content += "<iframe>";
		this.content += "<div style='position:absolute'><div id='" +this.name+"_lcPlayerBanner' class='lcBanner' style='position:absolute; border:";
		this.content += "0px solid black; width:300px; height:250px; left:0px; top:0px; z-index:100;'></div>";
		
		this.content += "<div id='" + this.name + "_Container" + "' class='lcPlayer' style='position:absolute; z-index:300; top:0px; width:"+this.width+"px;height:"+this.height+"px;'>" +this.flash + "</div></div>";
		
		
		return this.content;
}


lcPlayer.prototype.checkPX = function(prop){
	var px = String(prop).indexOf("px");
	if(px != -1){
		prop = prop.substring(0,px);
	}
	return Number(prop);
}

/* ----------------------------------------------------
 * Utility methods
 *----------------------------------------------------- */
 lcPlayer.prototype.getElement = function(id) {
		var elem;
	   
	   if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[id]
		} else {
			if (document[id]) {
				elem = document[id];
			  } else {
				elem = document.getElementById(id);
			  }
			return elem;
		}
}

lcPlayer.prototype.createError = function (errmsg){
	var div = getElement(this.divName);
	var err = "<div id='error' style='backgroundcolor:red; border:1px solid black;'>"+errmsg+"</div>";
	div.innerHTML += err;
}

lcPlayer.prototype.createPlayer = function() {
	
	if(this.rendered == false){
		this.renderPlayer();
	}
	var div = this.getElement(this.divName);
	var me = this;
	if (div == null) {
		this.addLoadListener(this.createPlayer)//, 500);
		return;
	}
	this.pluginError = false;
	div.innerHTML = this.content;
	this.player = this.getElement(this.name);
	this.container = this.getElement(this.name + "_Container");	
	
	
	
	this.companionBannerRegion = this.name + "_lcPlayerBanner";	
	this.companionBanner = this.getElement(this.name + "_lcPlayerBanner");
	this.created = true;
	
}


window.onload = function(){
	loadComplete = true;
}
lcPlayer.prototype.addLoadListener = function(fn){
	
	this.onDOMReady = fn;
	
    if(typeof window.addEventListener !='undefined') {  window.addEventListener('load',function(){   lcPlayer.self.onDOMReady(); },true); }
    else if(typeof document.addEventListener !='undefined')    document.addEventListener('load',function(){ lcPlayer.self.onDOMReady(); },false);
    else if(typeof window.attachEvent !='undefined')    window.attachEvent('onload',function(){ lcPlayer.self.onDOMReady(); });
    else{
        var oldfn=window.onload
        if(typeof window.onload !='function')    window.onload=fn;
        else    window.onload=function(){oldfn();lcPlayer.self.onDOMReady();}
    }
}


// All public properties use this proxy to minimize player updates

/*******************************************8
*Public API
*
*****************************************/
lcPlayer.prototype.setProperty = function(property, value) {
	 switch(property) {
		 case "level": 
			this.level = value;
			// cannot call functions on Flash movie until it's been drawn/rendered/loaded, so check for created before setting properties on it. 
			// otherwise this will cause an error. 
		    if(this.created==true){  
				this.player.setLevel(this.level);
			}
		 break;
		 case "nwid": 
			this.nwid = value; 
			if(this.created==true){
				this.player.setNetworkID(this.nwid);
			}
		 break;
		 case "format": 
			this.format = value;
			if(this.created==true){
				this.player.setFormat(this.format);
			}
		 break;
		 case "attr": 
			this.customAttr = value; 
			if(this.created==true){
				this.player.setCustomAttributes(this.customAttr);
			}
		break;
		 case "templateName" : 
			this.templateName = value; 
			if(this.created==true){
				this.player.setTemplateName(this.templateName);
			}
		 break; 
	 }
		
}

/**
* main play video method
*/

lcPlayer.prototype.playVideo = function(videoPath) {  
    var me = this;
	//alert("playVideo")
	if( (this.rendered == true) && (this.created == true) ) {
		this.videoPath = videoPath;
		//alert("rendered")
		if(this.player.PercentLoaded() < 100){
			//alert("timeout")
			setTimeout(function(){ me.playVideo(me.videoPath); },500);
			return;
		}
		//alert("playing " + this.videoPath);
		this.player.jsplay(this.videoPath);
		return;
	}
	setTimeout(function(){ me.playVideo(videoPath); },500); // */
}


/**
* Play/Pause Toggle
*
*/

lcPlayer.prototype.playPause = function() {
	this.player.playpause();
}

/**
* Stop playback of the video.
*/

lcPlayer.prototype.stop = function() { this.player.jsstop(); }

/**
 * Specifies the position of the playhead, in seconds.
 * @default null
 */

lcPlayer.prototype.getPlayHeadTime = function() 
{ 
	  return this.player.playheadTime(); 
}
/***
* Get current sate of the player
* state: PLAYING,BUFFERING,STOPPED
*/

lcPlayer.prototype.getState = function()
{
	return this.player.state();
}

lcPlayer.prototype.getVideoMeta = function ()
{
	return this.player.videoMetaData();
}


lcPlayer.prototype.setVolume = function(val){
	this.player.setVolume(val);
}

/**
 * Calls loadSpecificPlaylist on the LC Component in the Flash movie
 * @playlistURL String
 */
 
lcPlayer.prototype.loadSpecificPlaylist = function(playlistURL) {  	
	var me = this;
	if(this.player.PercentLoaded() < 100){
		setTimeout(function(){ me.loadSpecificPlaylist(playlistURL); },500);
	}else{
		//format, regions, attr
		if(playlistURL.indexOf("?") == -1){
			playlistURL += "?";
		}
		this.player.loadSpecificPlaylist(playlistURL, this.format, this.getRegions(), this.customAttr);    
	}
}



lcPlayer.prototype.getBannerByRegion = function(regionName){
	var obj = this.player.bannerMetaData(regionName);
	return obj;
}

/*
 * ### Global namespace functions
 *
 * These functions are generally called from the Flash movie and so can't belong to a class or prototype
 *
 */
function playStarted(){
   lcPlayer.self.dispatchEvent("playStarted");
}

function playStopped(){
	lcPlayer.self.dispatchEvent("playStopped");
}

function playComplete(){
	lcPlayer.self.dispatchEvent("playComplete");
}
function playlistFinished(){
	lcPlayer.self.dispatchEvent("playlistFinished");
}

//Flash callback for the StandardBanner companion for pre-roll
// ** REPLACED with workaround below
//function showStandardBanner(args) {  
//	lcPlayer.self.placeCompanionBanner(args);    
//}


// workaround to make sure Flash calls the right place function
lcPlayer.showStandardBanner = function(args){
	lcPlayer.self.placeCompanionBanner(args);  
}

//Flash callback to hide the banner after pre-roll video play has completed
lcPlayer.hideStandardBanner = function()
{    
	if( (lcPlayer.self.uimode != "overlay") && (lcPlayer.self.animateBanners == true) ){
  		lcPlayer.self.hideCompanionBanner();
	}
}
// Notify all listeners when a new event is dispatched.
lcPlayer.prototype.dispatchEvent = function(eventObj) {
    if (this.listeners == null) { return; }
	var type = eventObj;//.type;
	var items = this.listeners[type];
	if (items == null) { return; }
	for (var i=0; i<items.length; i++) {
    	var item = items[i];
		item.func.apply(item.target, [eventObj]);
	}
}


/**
 * Add an event listener to the video.
 *
 * @param eventType A string representing the type of event.  e.g. "init"
 * @param object The scope of the listener function (usually "this").
 * @param function The function to be called when the event is dispatched.
 */

lcPlayer.prototype.addEventListener = function(eventType, functionRef) {
	if (this.listeners == null) {
		this.listeners = {};
	}
	if (this.listeners[eventType] == null) {
		this.listeners[eventType] = [];
	} else {
		this.removeEventListener(eventType,  functionRef);
	}
		this.listeners[eventType].push({target:this, func:functionRef});
 }
	
/**
 * Remove an event listener from the video.
 *
 * @param eventType A string representing the type of event.  e.g. "init"
 * @param object The scope of the listener function (usually "this").
 * @param functionRef The function to be called when the event is dispatched.
 */
lcPlayer.prototype.removeEventListener = function(eventType,  functionRef) {
	for (var i=0; i<this.listeners[eventType].length; i++) {
		var listener = this.listeners[eventType][i];
		if (listener.func == functionRef) {
			this.listeners[eventType].splice(i, 1);
			break;
	  }
	}
}





//Place the StandardBanner into a banner region below the player for easing in and out
lcPlayer.prototype.placeCompanionBanner = function (banner)
{	
	//We only do fly-out for normal mode
	if (this.uimode == "normal")
	{
	 	LC_PLAYER_showBanner(banner,this.companionBanner); 
	
		this.pos = 0;

	    if (this.mode == "left")
	    { 
		 	this.doPosChangeMem(this.companionBanner,this.pos,-301,20,30,.5);
	    } else {
			this.doPosChangeMem(this.companionBanner,this.pos,426,20,30,.5);
	    }
	}
	//Display the banners for all the other associated regions
	var rgns = LCDisplayRegion.regions;

	for (var i = 0; i < rgns.length; i++) {
	 	var regNm = rgns[i].name;
		//alert("in placeCompanionBanner: " + regNm + ": " + rgns[i].width + ", " + rgns[i].height);
		bannerObj = this.getBannerByRegion(regNm);
		
		lcDisplayBanner(bannerObj.region, bannerObj.href, bannerObj.clickThru, bannerObj.rollover, rgns[i].width , rgns[i].height);
	} // */
	
}
function LC_PLAYER_showBanner(bannerArgs,divObj) {
 	if (bannerArgs === null) { return; }
  	if (divObj === undefined || divObj === null) {
    	alert("No DIVOBJ FOUND");
  	}
 	try {	
		document.lcBanner.loadBanner(bannerArgs.href,bannerArgs.clickThru,divObj, 300, 250);
	} catch (e) {  } 
}

//Hide it after the pre-roll has finished playing
lcPlayer.prototype.hideCompanionBanner = function ()
{	
	if( (document.lcBanner.isSWF==false) && (this.animateBanners==true) ) {
		this.pos = parseInt(this.companionBanner.style.left);
		this.doPosChangeMem(this.companionBanner,this.pos,63,20,30,.5);	
	}
}


// 300x250 companion banner animate method - OLD
lcPlayer.prototype.doPosChangeMem = function (elem,startPos,endPos,steps,intervals,powr) {
	if (elem.posChangeMemInt) {window.clearInterval(elem.posChangeMemInt)};
	var actStep = 0;
	//alert(document.lcBanner.isSWF);
	if( (this.animateBanners == true) && (document.lcBanner.isSWF==false) ){ //LVP-37
		elem.posChangeMemInt = window.setInterval(
			function() {
				this.pos = easeInOut(startPos,endPos,steps,actStep,powr);
				elem.style.left = this.pos + "px";				
				actStep++;
				if (actStep > steps) window.clearInterval(elem.posChangeMemInt);
			}
			,intervals);
	}else{
		elem.style.left = endPos + "px";
	}
}

//Calculate the number of steps
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp);
} 

/*------------------------------------
 * banner utility
 *
 *------------------------------------ */
 

//Convenience method for banner synchronization
lcPlayer.prototype.addDisplayRegion = function(regionName, width, height, regionId, regionObj) {
  if(this.getRegions().indexOf(regionName) == -1){
	this.regions = (this.getRegions().length == 0 ? "" : this.regions + ",") + regionName;
  }

  LCDisplayRegion.addRegion(regionName, width, height, regionId, regionObj);
}

lcPlayer.prototype.getRegions = function() {
  if (this.regions != null) { return this.regions; }
  return LCDisplayRegion.getRegionNameCSV();
}


function LCBanner(regionName, url, clickthru, rollover, auditURL, width, height) {
  this.regionName = regionName;
  this.url = url;
  this.clickthru = clickthru;
  this.rollover = rollover;
  this.auditURL = auditURL;
  this.audited = false;
  this.width = width; 
  this.height = height;
}

LCBanner.prototype.audit = function() {
  if(this.audited){return;}
  try {
    var a = new Image();
    a.src = this.auditURL;
    this.audited = true;
  }catch(e){}
}

LCBanner.prototype.show = function() {
  if (this.regionName === null){return;}
  var region = LCDisplayRegion.getRegion(this.regionName);

  region.showBanner(this);
}
function lcDisplayBanner(regionName, bannerURL, clickthru, rollover, auditURL, width, height) {
	//alert(regionName +  " " + bannerURL +  " " + clickthru +  " " + rollover +  " " + auditURL);
  try {
    var banner = new LCBanner(regionName, bannerURL, clickthru, rollover, auditURL, width, height);
  	banner.show();
  }catch(e){ }
}

top.lcDisplayBanner = lcDisplayBanner;
function LCDisplayRegion(name, width, height, divId, divObj) {
	this.name = (name === undefined) ? "StandardBanner" : name;
	this.width = (typeof(width) == "string") ? parseInt(width) : ((width === undefined) ? 300 : width);
	this.height = (typeof(width) == "string") ? parseInt(height) : ((height === undefined) ? 250 : height);
	this.divId = (divId === undefined) ? this.name : divId;
	this.divObj = (divObj === undefined) ? null : divObj;
	this.currentBanner = null;
}
LCDisplayRegion.prototype.resetBanner = function() {
	this.currentBanner = null;
}
LCDisplayRegion.prototype.showBanner = function(banner) {
	
  if (banner === null) { return; }
  if (this.divObj === undefined || this.divObj === null) {
    this.divObj = document.getElementById(this.divId);
  }

  try {
	if (this.currentBanner !== null && this.currentBanner.url === banner.url) { return; }
	if(this.divObj != null){ 

		document.lcBanner.loadBanner(banner.url,banner.clickthru,this.divObj, this.width, this.height);
	}
	if (null != top.lcInitialBannerTimer) {
		window.clearTimeout(top.lcInitialBannerTimer);
		top.lcInitialBannerTimer = null;
	}
	this.currentBanner = banner;
  } catch (e) { }
}






// Array to contain all the Lightningcast Media Entries.
LCDisplayRegion.regions = new Array();

LCDisplayRegion.addRegion = function(name, width, height, divId, divObj) {
  var region = new LCDisplayRegion(name, width, height, divId, divObj);
  LCDisplayRegion.regions.push(region);
};

LCDisplayRegion.getRegion = function(name, divId) {
	if (divId === undefined) { divId = name; }
	for (var i = 0; LCDisplayRegion.regions.length > i; i++) {
		if (LCDisplayRegion.regions[i].name === name) {
			return LCDisplayRegion.regions[i];
		}
	}
	var divObj = document.getElementById(divId);
	var region = new LCDisplayRegion(name, 300, 250, divId, divObj);
	LCDisplayRegion.regions.push(region);
	return region;
};

function lcResetBanners() {
	for (var i = 0; LCDisplayRegion.regions.length > i; i++) {
		LCDisplayRegion.regions[i].resetBanner();
	}
};
top.lcResetBanners = lcResetBanners;

LCDisplayRegion.getRegionNameCSV = function() {
  var str = "";
  for (var i = 0; LCDisplayRegion.regions.length > i; i++) {
    str += LCDisplayRegion.regions[i].name;
    if ((i+1) < LCDisplayRegion.regions.length) { str += ","; }
  }
  return str;
};



/* ----------------------------------------------------
 * Include ActiveContent methods that we need to
 * override. Avoids collision with the default file
 *----------------------------------------------------- */
lcPlayer.prototype.AC_Generateobj = function(objAttrs, params, embedAttrs) { 
		var str = '';
		if (this.generator.isIE && this.generator.isWin && !this.generator.isOpera) {
			str += '<object ';
			for (var i in objAttrs) {
				str += i + '="' + objAttrs[i] + '" ';
			}
			str += '>';
			for (var i in params) {
				str += '<param name="' + i + '" value="' + params[i] + '" /> ';
			}
			str += '</object>';
		} else {
			str += '<embed ';
			for (var i in embedAttrs) {
				str += i + '="' + embedAttrs[i] + '" ';
			}
			str += '> </embed>';
		}
		return str; // Instead of document.write
}
lcPlayer.prototype.AC_FL_RunContent = function() {
		var ret = this.generator.AC_GetArgs(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
		return this.AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function  declareClickFunctions()
{
	if (!document.lcBanner) 
		document.lcBanner = {};

	var lcBannerNS = document.lcBanner;
	
	lcBannerNS.lastReplaceBanner = null;
	lcBannerNS.isSWF = false;

	lcBannerNS.getURLParam = function( name )
	{  
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
		var regexS = "[\\?&]"+name+"=([^&#]*)";  
		var regex = new RegExp( regexS );  
		var results = regex.exec( window.location.href );  
		if( results == null )    
			return "";  
		else    
			return results[1];
	}

	 lcBannerNS.loadBanner = function(banner,href,divObj, width, height){
	 	lcBannerNS.isSWF = false;
		var bannerIMG = banner;
		var clickThruHref = href;
	  	var bannerLower = bannerIMG.toLowerCase();	
		/*
		no cilckthru (clickTAG=null) means create an iframe and set src to the banner file name (URL)
		clickthru means create an image tag setting the src to the bannre filename wrapped with an anchor tag that is the click thru url
		*/
		var clickTAG = lcBannerNS.getURLParam("clickTAG");
		if( (clickTAG == null) || (clickTAG == "") ) {
			//alert("calling lcReplaceBanner  " + width + " " + height)
			lcBannerNS.lcReplaceBanner(banner,clickThruHref,divObj, width, height);
		}else{
			//alert("calling lcReplaceBanner  " + width + " " + height)
			lcBannerNS.lcReplaceBanner(banner,clickTAG,divObj, width, height);
		}
	}
	/**
	 * This is the really basic banner replacement routine.
	 */
	 lcBannerNS.lcReplaceBanner = function(bannerURL, clickThruHref, divObj, width, height)
	{
		
		var bannerDiv = ((typeof(divObj) == "undefined") ? document.getElementById("lcBannerDiv") : divObj);
		
	
		if ("undefined" == typeof(bannerDiv) || null == bannerDiv) {
			return;
		}
		lcBannerNS.lcLog("replacing banner.");
		
		if (null == lcBannerNS.lastReplaceBanner) {
			lcBannerNS.lcLog("adding replace banner timeout.\n");
			lcBannerNS.currentMedia = bannerURL;
			lcBannerNS.bannerDiv = bannerDiv;
			lcBannerNS.clickThruHref = clickThruHref;
			lcBannerNS.bannerHeight = height;
			lcBannerNS.bannerWidth = width;
			var me = this;
			//lcBannerNS.lastReplaceBanner = setTimeout("document.lcBanner.lcReplaceBanner(window.currentMedia, window.clickThruHref, window.bannerDiv, window.bannerWidth, window.bannerHeight)", 1000);
			lcBannerNS.lastReplaceBanner = setTimeout(
													   function(){
															  //alert("reached anon function! " + lcBannerNS.bannerWidth + " " +  lcBannerNS.bannerHeight);											   
																document.lcBanner.lcReplaceBanner(	lcBannerNS.currentMedia, 
																	lcBannerNS.clickThruHref, 
																	lcBannerNS.bannerDiv, 
																	lcBannerNS.bannerWidth,
																	lcBannerNS.bannerHeight ); 
														}, 1000); // */
		} else {
			lcBannerNS.lcLog("clearing replace banner timeout.");
			//window.currentMedia = null;
			window.bannerDiv = null;
			lcBannerNS.lastReplaceBanner = null;
		}
		
		if (typeof(bannerURL) == 'undefined' || bannerURL == null || bannerURL == "") {
			return;
		}
		
		var bannerHTML = bannerURL;
		//if (lcBannerNS.lastBanner == bannerURL) { return; }
		if ((lcBannerNS.lastBanner == bannerURL) && divObj.id != "StandardBanner") { return; }
		
		// begin SWF/ JPG checking
		
		
		if ("" == clickThruHref || "DHTML" == clickThruHref) {
			lcBannerNS.lcLog("creating IFRAME in " + divObj.id) ; 
		  	bannerHTML = lcBannerNS.createIframe(bannerHTML, clickThruHref, width, height); //'<IFRAME src="' + bannerURL + '" frameborder="0" scrolling="no" width="' + width + '" height="' + height + '" marginwidth="0" marginheight="0"/>';
		} else if (0 == bannerHTML.indexOf("http")) {
			if( (bannerHTML.toLowerCase().indexOf(".jpg") != -1) ||  (bannerHTML.toLowerCase().indexOf(".gif") != -1)  ){
				lcBannerNS.lcLog("creating AHREF/IMG  in " + divObj.id) ; 
		  		//bannerHTML = lcBannerNS.createEmbedCode(bannerHTML, clickThruHref, width, height);
				// LVP-47 fix
				var hrefOpen = "";
				var hrefClose = ""; 
				if(clickThruHref != null && clickThruHref != "null"){
					hrefOpen = '<A HREF="' + clickThruHref + '" target="_blank">'; 
					hrefClose = '</A>'; 	
				}
				bannerHTML = '<CENTER>' + hrefOpen + '<IMG SRC="' + bannerURL + '" border="0">' + hrefClose + '</CENTER>';	
			}else if(bannerHTML.toLowerCase().indexOf(".swf") != -1) {
				// place swf
				lcBannerNS.lcLog("creating iframe for SWF  in " + divObj.id) ; 
				lcBannerNS.isSWF = true;
				bannerHTML =  lcBannerNS.createIframe(bannerHTML, clickThruHref, width, height); //lcBannerNS.createEmbedCode(bannerHTML, clickThruHref);
				
				bannerDiv.innerHTML = bannerHTML;
				
				return;
			}
			else{ // attempt other detection methods if  ".swf" , ".jpg" or ".gif" were not in the url
				lcBannerNS.isImage(bannerHTML, clickThruHref, bannerDiv, width, height);
				bannerHTML = "";
			}
		}
		lcBannerNS.lastBanner = bannerURL;
		bannerDiv.innerHTML = bannerHTML;
	}
	
	lcBannerNS.createIframe = function(bannerURL, clickThruHref, width, height){
		var iframe = "";
		lcBannerNS.lcLog("in createIframe:  bannerURL = " + bannerURL + " clickThruHref = " + clickThruHref+ " width = " +  width + " height = " +  height )
		if( (clickThruHref != null) && (clickThruHref != undefined) && (clickThruHref != "") && (typeof(clickThruHref) != "undefined") ) {
			bannerURL +=  "?clickTAG=" + clickThruHref;
		}
	
		iframe = '<IFRAME src="' + bannerURL + '" frameborder="0" style="width:' + width + 'px;height:' + height + 'px;z-index:50;position:absolute;" scrolling="no" width="' + width + '" height="' + height + '" marginwidth="0" marginheight="0"/>';
		
		return iframe;
	}
	
	 // disabled until object/embed code no longer breaks in IE with getElement
	lcBannerNS.createEmbedCode = function(bannerURL, clickThruHref){
		var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="300" height="250" id="bannerSWF" align="middle">';
		str += '<param name="allowScriptAccess" value="always"/>';
		str += '  <param name="movie" value="' +  bannerURL +  "?clickTAG=" + clickThruHref + '"/>';
		str += '  <param name="quality" value="high" />';
		str += '  <param name="bgcolor" value="#ffffff" />';
		str += '  <param name="wmode" value="transparent" />';
		str += '  <embed src="' + bannerURL + "?clickTAG=" + clickThruHref +'" quality="high" bgcolor="#ffffff" width="300" height="250" name="bannerSWF" align="middle" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>';
		str += '</object>';		
		
		return str;
	}// */
	
	lcBannerNS.isImage = function(url, clickThruHref, bannerDiv, width, height) {
		//lcBannerNS.lcLog("enter is image")
		var img = document.createElement('img');
		img.onload = function() {
			//lcBannerNS.onImageSuccess(img);
			var bannerLink = document.createElement("a");
			bannerLink.href = clickThruHref;
			bannerLink.setAttribute("href", clickThruHref);
			bannerLink.setAttribute("target", "_new");
			img.setAttribute("border","0");
			bannerLink.appendChild(img);
			bannerDiv.appendChild(bannerLink);
		}
		img.onerror = function() {
			// here, we can assume that the banner is a SWF
			//lcBannerNS.lcLog(url + " is not an image");
			bannerDiv.innerHTML = lcBannerNS.createIframe(url, clickThruHref, width, height);// lcBannerNS.createEmbedCode(url, clickThruHref);
		}
		img.src = url;		
	}
	


	 lcBannerNS.lcLog = function(str){ 
		
		try{
			 //console.log(str);
		}catch(e) { }
		
		var lcLogger = document.getElementById("lcLoggerArea");
		if ("undefined" == typeof(lcLogger)) { 
			lcLogger = null; 
			return; 
		}
		if (null != lcLogger) { 
			lcLogger.value += str + "\n"; 
		}  
	}
	
	lcBannerNS.generateClickTag = function(getElementURL){
		var clickThruURL="http://click.lightningcast.net/servlets/clickThru?v=6.0";
  		var getElementVars = getElementURL.split('?');
  		getElementVars = getElementVars[1];
    	getElementVars = getElementVars.replace(/creativeid/, "cr");
    	getElementVars = getElementVars.replace(/bId/, "ct");
    	getElementVars = getElementVars.replace(/ioid/, "io");
    	getElementVars = getElementVars.replace(/streamid/, "st");
    	//and any other differences between getElement and clickThru variable names
  
  		clickThruURL += getElementVars;
		
		return clickThruURL;
	}
	 
}
declareClickFunctions();

var lcBanner = document.lcBanner;
// */