/*
 DirTag Class v0.3
 Created by: Valentin Schmidt
 Output (Active Content update) by: Tim Venison
	
 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, id, forceReloadFlag)
{
    this.src       = src;
    if (forceReloadFlag) this.src += '?'+Math.random();
    this.width     = width;
    this.height    = height;
    this.version   = '11,0,0,0';
	this.PlayerVersion = 11;
    this.id        = id;
    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. 

Example Content output

AC_SW_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,0','width','1024','height','768','src','3D_progbar','sw1','groovyViewer.dcr','sw2','118245359629','bgcolor','#ffffff','pluginspage','http://www.macromedia.com/shockwave/download/','swstretchstyle','fill');

 */
 

DirTag.prototype.toString = function()
{
    var DirTag = new String();

   		DirTag += "'codebase','http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version="+this.version+"',";
        if (this.id != null)
        {
            DirTag += "'id','"+this.id+"',";
        }
        DirTag += "'width','"+this.width+"',";
		DirTag += "'PlayerVersion','"+this.PlayerVersion+"',";
        DirTag += "'height','"+this.height+"',";
        DirTag += "'src','_assets/viewer/groovyViewer',";
//        DirTag += "'src','"+this.src+"',";
		if (this.dirVars != null){
        	var len = Math.min(this.dirVars.length, 8);
        	for (i=0;i<len;i++)
        		DirTag += "'sw"+(i+1)+"','"+this.dirVars[i]+"',";
        }
		DirTag += "'bgcolor','"+this.bgcolor+"',";
        
        DirTag += "'pluginspage','https://www.macromedia.com/shockwave/download/','swstretchstyle','fill'";
    
   
   return DirTag;
	
	
}

/**
 * Write the Director Shockwave tag out. Pass in a reference to the document to write to. 
 */
DirTag.prototype.write = function(doc)
{
  doc.write(this.toString());
}


