/* ********************************************************************************
* Source Code Copyright (c) 2008 Congruent Media, LLC.  All rights reserved.
* 
* This source code is the intellectual property of Congruent Media, LLC., 
* except where otherwise noted, and may not be copied in whole or in part, 
* except for backup purposes. You may not resell or otherwise distribute 
* this source code, or any code derived from this source code, without 
* express written permission from Congruent Media, LLC.
* 
* This source code is sold "as is" and WITHOUT ANY WARRANTY; without even 
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*  
* http://www.CongruentMedia.com | info@CongruentMedia.com | +1 410-534-6800
*  
** ********************************************************************************/

var FLASH_DEBUG = false;

Flash = function(swf, quality, width, height, version)
{
    this.swf = swf || "";
	this.quality = quality || "high";
    this.width = width || "100%";
    this.height = height || "100%";
    this.requiredVersion = version || 6;
    this.id = "";
    this.params = new Object();
    this.variables = new Object();
};
Flash.hasVersion = function(requiredVersion)
{
    var hasVersion = false;
    if (navigator.plugins.length > 0 && navigator.plugins["Shockwave Flash"]) { // NS/Mozilla
        var description = navigator.plugins["Shockwave Flash"].description;
        var version = description.match(/\d{1,2}/);
        hasVersion = (version >= requiredVersion);
    }
    else if (window.ActiveXObject && window.execScript && navigator.userAgent.indexOf('Mac') == -1) { // Win IE
        Flash.hasActiveX = false;
        window.execScript("On error resume next: Flash.hasActiveX = IsObject(CreateObject('ShockwaveFlash.ShockwaveFlash." + requiredVersion + "'))", "VBScript");
        hasVersion = Flash.hasActiveX;
        delete Flash.hasActiveX;
    }
    return hasVersion;
};
Flash.resizeTo = function(id, w, h) { 
    var movie = document.getElementById(id); 
	movie.width = w; 
	movie.height = h;
};
Flash.prototype.getSWF = function() { return this.swf; };
Flash.prototype.setSWF = function(swf) { this.swf = swf; };
Flash.prototype.getQuality = function() { return this.quality };
Flash.prototype.setQuality = function(q) { this.quality = q };
Flash.prototype.getWidth = function() { return this.width; };
Flash.prototype.setWidth = function(w) { this.width = w; };
Flash.prototype.getHeight = function() { return this.height; };
Flash.prototype.setHeight = function(h) { this.height = h; };
Flash.prototype.getRequiredVersion = function() { return this.requiredVersion; };
Flash.prototype.setRequiredVersion = function(v) { this.requiredVersion = v; };
Flash.prototype.getId = function() { return this.id; };
Flash.prototype.setId = function(id) { this.id = id; };
Flash.prototype.getParam = function(name) { return this.params[name]; };
Flash.prototype.getParams = function() { return this.params; };
Flash.prototype.setParam = function(name, value) { this.params[name] = value; };
Flash.prototype.getVariable = function(name) { return this.variables[name];	};
Flash.prototype.getVariables = function() { return this.variables; };
Flash.prototype.setVariable = function(name, value) { this.variables[name] = value;	};

Flash.prototype.getVariablePairs = function()
{
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
};
Flash.prototype.getParamTags = function()
{
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
};
Flash.prototype.getHTML = function()
{
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getWidth() + '" height="' + this.getHeight() + '" id="' + this.getId() + '">';
        flashHTML += '<param name="movie" value="' + this.getSWF() + '" />';
		flashHTML += '<param name="quality" value="' + this.getQuality() + '" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '<' + '/object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.getSWF() + '" quality="' + this.getQuality() + '" width="' + this.getWidth() + '" height="' + this.getHeight() + '" id="' + this.getId() + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '><' + '/embed>';
    }
	
	if (FLASH_DEBUG)
	{
		flashHTML = flashHTML.replace(/</g, '&lt;');
		flashHTML = flashHTML.replace(/>/g, '&gt;');
	}
    
    return flashHTML;
};
Flash.prototype.render = function(elementId)
{
    if(Flash.hasVersion(this.getRequiredVersion())) {
        if (elementId) {
            document.getElementById(elementId).innerHTML = this.getHTML();
        }
        else {
            document.write(this.getHTML());
        }
    }
	else
	{
		document.write('<div class="no_flash"><p>This portion of the site requires the latest version of the Flash Player Browser Plug-in. You may download this plug-in via Macromedia\'s website. Flash Player lets your web browser play video and animations made with Flash.</p>');
		document.write('<p align="center"><a href="http://www.macromedia.com/go/getflashplayer/" target="blank"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" border="0" /></a></p>');
		document.write('<p>&nbsp;</p><p align="center">After you have installed the latest Flash Player, you may <a href="javascript:document.location.reload(true);">reload this page</a>.</p></div>');
	}
};
function flashMe(id, path, quality, width, height, version, flashvars, wmode)
{
	document.write('<div id="fflashcontainer_' + id + '"><' + '/div><script language="javascript" type="text/javascript">var fform_' + id + ' = new Flash("' + path + '", "' + quality + '", "' + width + '", "' + height + '", "' + version + '");');
	document.write('fform_' + id + '.setId("' + id + '");');
	if (flashvars && flashvars != '') document.write('fform_' + id + '.setParam("FlashVars", "' + flashvars + '");');
	if (wmode && wmode != '') document.write('fform_' + id + '.setParam("wmode", "' + wmode + '");');
	document.write('fform_' + id + '.render("fflashcontainer_' + id + '");</' + 'script>');
}
