/*
 DirTag Class v0.3.1
 Created by: Valentin Schmidt
	
 Clone of FlashTag Class by Mike Chambers and Christian Cantrell
	
 Generates a browser-specific Director Shockwave 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 DirTag.
 * src: The path to the DCR file.
 * width: The width of your movie.
 * height: the height of your Fmovie.
 */
function DirTag(src, width, height, forceReloadFlag)
{
    this.src       = src;
    if (forceReloadFlag) this.src += '?'+Math.random();
    this.width     = width;
    this.height    = height;
    this.version   = '11,0,0,0';
    this.id        = null;
    this.bgcolor   = 'ffffff';
    this.dirVars = null;
}

/**
 * Sets the Director Shockwave version used in the Director Shockwave tag.
 */
DirTag.prototype.setVersion = function(v)
{
    this.version = v;
}

/**
 * Sets the ID used in the Director Shockwave tag.
 */
DirTag.prototype.setId = function(id)
{
    this.id = id;
}

/**
 * Sets the background color used in the Director Shockwave tag.
 */
DirTag.prototype.setBgcolor = function(bgc)
{
    this.bgcolor = bgc;
}

/**
 * Sets any variables to be passed into the Director Shockwave content, as externalParamValue("sw1")..("sw9").
   maximum 9 args supported
 */
DirTag.prototype.setDirvars = _setDirvars;
function _setDirvars(){
    this.dirVars = _setDirvars.arguments;
}
	
/**
 * Get the Director Shockwave tag as a string. 
 */
DirTag.prototype.toString = function()
{
    var ieWin = (/Win/.test(navigator.userAgent) && navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var DirTag = new String();
    if (ieWin)
    {
        DirTag += '<object classid="clsid:233C1507-6A77-46A4-9443-F871F945D258" ';
        if (this.id != null)
        {
            DirTag += 'id="'+this.id+'" ';
        }
        DirTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version='+this.version+'" ';
        DirTag += 'width="'+this.width+'" ';
        DirTag += 'height="'+this.height+'">';
        DirTag += '<param name="PlayerVersion" value="11"/>';
        DirTag += '<param name="src" value="'+this.src+'"/>';
        DirTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
        
        DirTag += ('<PARAM NAME=swRemote VALUE="');
	      DirTag += ("swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='false' ");
	      DirTag += ('">\n');
        
        if (this.dirVars != null){
        	var len = Math.min(this.dirVars.length, 9);
        	for (i=0;i<len;i++)
        		DirTag += '<param name="sw'+(i+1)+'" value="'+this.dirVars[i]+'"/>';
        }
        DirTag += '</object>';
    }
    else
    {
        DirTag += '<embed src="'+this.src+'" ';
        DirTag += 'PlayerVersion="11" ';
        DirTag += 'bgcolor="#'+this.bgcolor+'" ';
        DirTag += 'width="'+this.width+'" ';
        DirTag += 'height="'+this.height+'" ';
        DirTag += 'type="application/x-director" ';
        DirTag += ('swRemote="');
	      DirTag += ("swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='false' ");
	      DirTag += ('" ');
	
        if (this.dirVars != null){
        	var len = Math.min(this.dirVars.length, 9);
        	for (i=0;i<len;i++)
            DirTag += 'sw'+(i+1)+'="'+this.dirVars[i]+'" ';
        }
        if (this.id != null)
        {
            DirTag += 'name="'+this.id+'" ';
        }
        DirTag += 'pluginspage="http://www.macromedia.com/shockwave/download/">';
        DirTag += '</embed>';
    }
    return DirTag;
}

/**
 * Write the Director Shockwave tag out. Pass in a reference to the document to write to. 
 */
DirTag.prototype.write = function(doc)
{
  var str=this.toString();
  doc.write(str);
}

