/*************************************************
  20060606 : Created RDA
  
  include flash2.js in your webpage :
  <script language=javascript src="flash2.js" type=text/javascript></script>
  
  - Not as flexible as flash.js
  - Created for Ad support and ecard solution
  - Uses duplicate code from flash.js but is optimized for this job
  - Blame javeascript for the bad OOP support.
  
 *************************************************/


/*************************************************
 * CFlashObjCommon                               *
 *************************************************/

CFlashObjCommon = function(Movie, FlashName) 
{
  // For testing
  this.bForceNoFlashDetected = false;  
  
  this.bInit = false;
  this.bFlashInstalled = false;
  this.bOldBrowserDetected = false;
  this.bWriteError = false;
  
  this.DetectedFlashVersion = 0;
  this.RequiredFlashVersion = 3;
  
  this.FlashName = FlashName;
  this.Align = "";
  this.Movie = Movie;
  
  this.aParam = new Array();
  this.aParam[0] = new Array();
  this.aParam[0][0] = "quality";
  this.aParam[0][1] = "high";
  
  this.aParam[1] = new Array();
  this.aParam[1][0] = "menu";
  this.aParam[1][1] = "false";
  
  this.aParam[2] = new Array();
  this.aParam[2][0] = "scale";
  this.aParam[2][1] = "noscale";
  
  this.aParam[3] = new Array();
  this.aParam[3][0] = "wmode";
  this.aParam[3][1] = "transparent";
  
  this.aParam[4] = new Array();
  this.aParam[4][0] = "allowScriptAccess";
  this.aParam[4][1] = "sameDomain";
}

CFlashObjCommon.prototype.IsInternetExplorer = function()
{
  if (navigator.appVersion.indexOf("MSIE") != -1) {
    return true;
  }
  return false;
}

CFlashObjCommon.prototype.IsInterExplorerVersion = function(MinimalVersion)
{
  if (navigator.appVersion.indexOf("MSIE") != -1) {
		Version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		if (Version >= MinimalVersion) {
		  return true;
		}
	}
	return false; 
}

CFlashObjCommon.prototype.Check = function()
{
  this.bInit = true;
  if (navigator.mimeTypes) {
    if (navigator.mimeTypes["application/x-shockwave-flash"]) {
      Plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
      if (Plugin) {
        words = navigator.plugins["Shockwave Flash"].description.split(" ");
        for (var i = 0; i < words.length; ++i) {
          if (!isNaN(parseInt(words[i]))) {
            this.DetectedFlashVersion = words[i];
            this.bFlashInstalled = true;
            break;
          }
        }
      }
    }
  } 

  if (!this.bFlashInstalled) {
    if (navigator.appVersion.indexOf("MSIE") != -1) {
      if (navigator.appVersion.indexOf("Win") != -1) {
        FlashCanPlay = false;
        if (navigator.appVersion.indexOf("Win") != -1) {
          document.write('<scr' + 'ipt LANGUAGE=VBScript\> \n');
          document.write('on error resume next \n');
          document.write('FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + this.RequiredFlashVersion + '")))\n');
          document.write('</scr' + 'ipt\> \n');
        }
        if (FlashCanPlay) {
          this.bFlashInstalled = true;
          this.DetectedFlashVersion = this.RequiredFlashVersion;
        }
      }
    }
  }
  
  if (this.bCheckForRecentIeVersion) {
    if (this.IsInternetExplorer()) {
      if (!IsInterExplorerVersion(5.5)) {
        this.bOldBrowserDetected = true;
      }
    }
  }
}

CFlashObjCommon.prototype.AddParam = function(Key, Value)
{
  var bFound = false;
  for (var i=0; i < this.aParam.length; i++) {
    if (this.aParam[i][0] == Key) {
      this.aParam[i][1] = Value;
      bFound = true;
    }
  }
  
  if (!bFound) {
    this.aParam[this.aParam.length-1] = new Array();
    this.aParam[this.aParam.length-1][0] = Key;
    this.aParam[this.aParam.length-1][1] = Value;
  }
}

CFlashObjCommon.prototype.Write = function()
{
  if (!this.bInit) {
    this.Check();
  }
  
  var Out;
  
  if (!this.bOldBrowserDetected && this.bFlashInstalled && (this.DetectedFlashVersion >= this.RequiredFlashVersion) && !this.bForceNoFlashDetected) {
  	
    Out = "<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=\"100%\" height=\"100%\"";
  	
  	if (this.Align != "") {
  	 Out += " align=\"" + this.Align + "\"";
  	}
  	
  	Out += ">";
		Out += "<param name=\"movie\" value=\"" +  this.Movie + "\" />";
		
		var EmbedParams = "";
		
    for (var i=0; i < this.aParam.length; i++) {
      Out += "<param name=\"" + this.aParam[i][0] + "\" value=\"" +  this.aParam[i][1] + "\" />";
      EmbedParams += " " + this.aParam[i][0] + "=\"" + this.aParam[i][1] + "\""; 
    }
    
		Out += "<embed src=\"" + this.Movie + "\"" + EmbedParams + " width=\"100%\" height=\"100%\"";
		Out += " name=\"" + this.FlashName + "_swfdiv\"";
		
		if (this.Align != "") {
			Out += " align=\"" + this.Align + "\"";
		}
		
		Out += " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
    
    Out += "</object>";
    return Out;
  } else {
    this.bWriteError = true;
    return "<!-- FlashObject returned false : old browser or no flash detected -->";
  }
}

/*************************************************
 * CFlashObjReplaceDiv                           *
 *************************************************/
 
CFlashObjReplaceDiv = function(ReplaceDivId, Movie)
{
  this.ReplaceDivId = ReplaceDivId;
  this.Flash = new CFlashObjCommon(Movie, "name_" + ReplaceDivId);
  
} 

CFlashObjReplaceDiv.prototype.AddParam = function(Key, Value)
{
  // no javascript inheritance :-(
  this.Flash.AddParam(Key, Value);
}

CFlashObjReplaceDiv.prototype.Write = function()
{
  var Div = document.getElementById(this.ReplaceDivId).innerHTML = this.Flash.Write();
}

/*************************************************
 * FlashObjFloatingDiv                           *
 *************************************************/
 
FlashObjFloatingDiv = function(DivId, zIndex, x, y, w, h, Movie)
{
  this.Flash = new CFlashObjCommon(Movie, "name_" + DivId);  
  this.div = document.createElement("div");
	this.div.setAttribute("id", DivId);
	this.div.style.zIndex = zIndex;
	this.div.style.position = "absolute";
	this.div.style.left = x;
  this.div.style.top = y;
  this.div.style.width = w;
  this.div.style.height = h;
}

FlashObjFloatingDiv.prototype.AddParam = function(Key, Value)
{
  // no javascript inheritance :-(
  this.Flash.AddParam(Key, Value);
}

FlashObjFloatingDiv.prototype.Write = function()
{
  var Out = this.Flash.Write();
  if (!this.Flash.bWriteError) {
    this.div.innerHTML = Out;
    document.body.appendChild(this.div);
  }
}

/**************************************************
 * Helper functions some for flash internal usage *
 **************************************************/

function RemoveDivById(Id) 
{
	var div = document.getElementById(Id);
	if (div) {
	  document.body.removeChild(div);
	}
}

function PopUpNewWindow(Url)
{
  newWindow = window.open();
  newWindow.location.href = Url;
  newWindow.focus();
}
  
function ResizeDiv(oDiv, size) 
{
  oDiv.style.width = size + "px";
}

function VarValueEncode(Value)
{
  // Used for flashvars
  return escape(Value).replace(/[+]/g, '%2B');
}