/**
 * Generates a browser-specific Flash tag. Create a new instance, set whatever
 * properties you need, then call either toString() to get the tag as a string, or
 * call write() to write the tag out.
 */
/**
 * Creates a new instance of the FlashTagConfig.
 * swfLocation: url to swf file.
 * location: hosting document of the FlashTag
 * swfId: HTML DOM id of object/embed tag
 * layoutType: standard,landscape
 * assetType: text,image,clip,video,eclip,etext,evideo
 * assetId: vmp asset id
 * serverPrefix: mash server location
 * mashId: id of mash code at a particular location
 * masherId: id for agreement to terms by email address
 * mashProvider: id of provider of content
 * cabVersion: version string for player cab
 * bgColor: bgColor for object/embed tag
 * requiredMajorVersion: flash player version
 * requiredMinorVersion: flash player minor version
 * requiredRevision: flash player revision
 * layout: cube layout type
 * font: cube font type
 * fontSize: cube font size
 * skin: cube skin name
 * showAds: whether or not to display ads with content
 */

function FlashTagConfig(swfLocation, location, id, assetId, serverPrefix, mashId, bgColor, autoMash, version) {
 //   function FlashTagConfig(swfLocation, id, assetId,  mashId, autoMash, version) {
    this.contentPlayer = true;
    this.swfLocation = swfLocation;

   this.browserLocation = location;
   this.swfId = id;
 //   this.layoutType = layoutType;
//    this.assetType = assetType;
    this.assetId = assetId;

    this.serverPrefix = serverPrefix;
    this.mashId = mashId;
 //   this.masherId = masherId;
 //   this.mashProviderId = mashProviderId;
    this.cabVersion = '9,0,0,0';
    this.bgColor = bgColor;
    this.requiredMajorVersion = 9;
    this.requiredMinorVersion = 0;
    this.requiredRevision = 16;
 //   this.layout = layout;
 //   this.font = font;
 //   this.fontSize = fontSize;
 //   this.skin = skin;
 //   this.showAds = showAds;
 //   this.slideShowFlag = (slideShowFlag != undefined)?slideShowFlag:false;
    this.autoMash = autoMash;
    this.version = version;
}

function FlashConfig(swfLocation, width, height) {
    this.contentPlayer = false;
    this.swfLocation = swfLocation;
    this.layoutWidth = width;
    this.layoutHeight = height;
    this.cabVersion = '9,0,0,0';
    this.requiredMajorVersion = 9;
    this.requiredMinorVersion = 0;
    this.requiredRevision = 16;
    this.bgColor = 'ffffff';
}
/**
 * Creates a new instance of the FlashTag.
 * src: The path to the SWF file.
 * width: The width of your Flash content.
 * height: the height of your Flash content.
 */
/*
function FlashTag(src, width, height,adTop,adLeft)
*/
function FlashTag(config, width, height)
{
    this.flashVars = null;
    this.src = config.swfLocation;
    this.version = config.cabVersion;
    this.requiredMajorVersion = config.requiredMajorVersion;
    this.requiredMinorVersion = config.requiredMinorVersion;
    this.requiredRevision = config.requiredRevision;
    this.bgcolor = config.bgColor;
    this.flashVarOverride=new Array();

    if (config.contentPlayer == true) {
        this.id = config.swfId;
        this.location = config.browserLocation;

        this.assetId = config.assetId;
      //  this.layoutType = config.layoutType;
     //   this.assetType = config.assetType;
        this.serverPrefix = config.serverPrefix;
        this.mashId = config.mashId;
    //    this.masherId = config.masherId;
    //    this.mashProviderId = config.mashProviderId;
        this.cabVersion = config.cabVersion
    //    this.layout = config.layout;
     //   this.font = config.font;
     //   this.fontSize = config.fontSize;
     //   this.skin = config.skin;
     //   this.showAds = config.showAds;
     //   this.slideShowFlag = config.slideShowFlag;
        this.autoMash = config.autoMash;
        this.version = config.version;
        if (width != undefined && height != undefined) {
          this.width = width;
          this.height = height;
        }
        
    } else {
      if (width != undefined && height != undefined) {
          this.width = width;
          this.height = height;
      } else {
        this.width = config.layoutWidth;
        this.height = config.layoutHeight;
      }
      this.bgColor = 'ffffff';
    }
}
FlashTag.prototype.addFlashVarOverride=function(key,val)
{
    this.flashVarOverride.push({key: key, value: val});
}

FlashTag.prototype.getFlashVarOverrides=function(){
    var retVal='';
    if (this.flashVarOverride&&(this.flashVarOverride.length>0)) {
        for (var x in this.flashVarOverride){
            retVal+='&'+this.flashVarOverride[x].key+'='+this.flashVarOverride[x].value;
        }
    }
    return retVal;
}

FlashTag.prototype.clearFlashVarOverrides=function(){
    this.flashVarOverride.length=0;
}

/**
 * Sets the Flash version used in the Flash tag.
 */
FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

/**
 * Sets the ID used in the Flash tag.
 */
FlashTag.prototype.setId = function(id)
{
    this.id = id;
}

/**
 * Sets the asset ID used in the Flash tag.
 */
FlashTag.prototype.setAssetId = function(assetId)
{
    this.assetId = assetId;
}

/**
 * Sets the background color used in the Flash tag.
 */
FlashTag.prototype.setBgcolor = function(bgc)
{
    this.bgcolor = bgc;
}

/**
 * Sets any variables to be passed into the Flash content.
 */
FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

//FlashTag.prototype.renderAd = function() {
//    return checkValue(tag.showAds);
//}

/**
 * Get the Flash tag as a string.
 */
FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
    var flashTag = new String();
//    if (this.renderAd()) {
//        flashTag = '<div id="cubeDiv" style="position:relative;">';
//        flashTag += '<span id="voxAd' + this.assetId + '" style="position:absolute;z-index:2;"></span>';
//    }
    if (ie)
    {
        flashTag+=this.getObjectTag(false,false);
    }
    else
    {
        flashTag+=this.getEmbedTag(false,false);
    }
//    if (this.renderAd())
//        flashTag += '</div>';
    return flashTag;
}

FlashTag.prototype.getEmbedTag=function(minimalFlashVars){
    var flashTag=new String();
    if (this.getFlashVars(minimalFlashVars) != null)
    {
        flashTag += '<embed src="' + this.src + '?' + this.getFlashVars(minimalFlashVars) + '" ';
    } else {
        flashTag += '<embed src="' + this.src + '" ';
    }

    flashTag += 'base="." ';
    if (this.width != undefined) {
        flashTag += 'width="' + this.width + '" ';
    }

    if (this.height != undefined) {
        flashTag += 'height="' + this.height + '" ';
    }

    flashTag += 'type="application/x-shockwave-flash" ';
    flashTag += 'AllowScriptAccess="always" ';
    if (this.id != null)
    {
        flashTag += 'name="' + this.id + '" ';
    }
    flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
    flashTag += '</embed>';
    return flashTag;
}

FlashTag.prototype.getObjectTag=function(doEmbed,minimalFlashVars){
    var flashTag = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
    if (this.id != null)
    {
        flashTag += 'id="' + this.id + '" ';
    }

    if (this.width != undefined) {
        flashTag += 'width="' + this.width + '" ';
    }

    if (this.height != undefined) {
        flashTag += 'height="' + this.height + '" ';
    }

    flashTag += '>';
    if (this.getFlashVars(minimalFlashVars) != null)
    {
        flashTag += '<param name="movie" value="' + this.src + '?' + this.getFlashVars(minimalFlashVars) + '"/>';
    } else {
        flashTag += '<param name="movie" value="' + this.src + '"/>';
    }
    flashTag += '<param name="base" value="."/>';
    flashTag += '<param name="allowScriptAccess" value="always"/>';
    if (doEmbed)
      flashTag += this.getEmbedTag(minimalFlashVars);
    flashTag += '</object>';
    return flashTag;
}

FlashTag.prototype.getMashableString=function(mashableShowAds){
    var retVal='';
    if (mashableShowAds)
        retVal='<div id="cubeDiv" style="position:relative;"><span style="position:relative; z-index:2;">';

    retVal=retVal+this.getObjectTag(true,true);

    if (mashableShowAds)
        retVal=retVal+'</span><span id="voxAd'+this.assetId+'" style="position:absolute;z-index:2;"></span></div>';

    return retVal;
}

FlashTag.prototype.getFlashVars=function(minimalFlashVars){
    var flashVars='';
    if (this.id != undefined) {
        flashVars = flashVars + '&' + 'a=' + checkValue(tag.assetId);
        flashVars = flashVars + '&' + 'm=' + checkValue(tag.mashId);
        flashVars = flashVars + '&' + 'v=' + checkValue(tag.version);
        if (!minimalFlashVars){
            flashVars = flashVars + '&swfID=' + tag.id;
            flashVars = flashVars + '&' + 'Server_Prefix=' + checkValue(tag.serverPrefix);
            flashVars = flashVars + '&' + 'swfLocation=' + checkValue(tag.location);
            flashVars = flashVars + '&' + 'autoMash=' + checkValue(tag.autoMash);
            if (tag.slideShowFlag == true)
                flashVars = flashVars + '&slideShow=true';
        }

        flashVars += this.getFlashVarOverrides();
    }
    return flashVars;
}
/**
 * Write the Flash tag out. Pass in a reference to the document to write to.
 */
FlashTag.prototype.write = function(doc)
{
    var tmp = this.toString();
  //  alert(tmp);
    doc.write(tmp);
}
function checkValue(val) {
    if (val == null)
        return undefined;
    else
        return val;
}
function renderFlashTag(tag) {

    var requiredMajorVersion = tag.requiredMajorVersion;
    var requiredMinorVersion = tag.requiredMinorVersion;
    var requiredRevision = tag.requiredRevision;
    var jsVersion = 1.0;
    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
    jsVersion = 1.1;
//    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision, isIE, isWin, isOpera);

//    if (hasRightVersion) {  // if we've detected an acceptable version
        var flashVars = null;
        tag.write(document);
//    } else {  // flash is too old or we can't detect the plugin
//        var alternateContent = 'Visit Macromedia\'s web site to <a href=http://www.macromedia.com/go/getflash/>Get Flash</a>';
//        document.write(alternateContent);
        // insert non-flash content
//    }
}

