/* /library/javascript/minimum.js -	

   DATE           AUTHOR    CHANGE
   28.07.2005  AgMcC       minimum script required throughout site

*/

// GLOBAL VARIABLES ---------------------------------------------------------------------------------------
var blnMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1) ? true : false;
var blnNs4 = (document.layers) ? true : false;
var blnIe4 = (document.all && !document.getElementById) ? true : false;
var blnIe5 = (document.all && document.getElementById) ? true : false;
var blnIe6 = (document.all && document.getElementById) ? true : false;
var blnIe7 = (document.all && document.getElementById) ? true : false;
var blnNs6 = (!document.all && document.getElementById) ? true : false;
var blnOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1) ? true : false;

// create unique name for local connection.
var flashVars = "lc=MainFlashFile" + Math.floor(Math.random()*99999);
var flashURL, strCodebase, strEmbedSource;
var xmlVar = "XML TEST VARS";

strEmbedSource = 'http://www.macromedia.com/go/getflashplayer';
strCodebase =  'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
//flashURL = 'flash/variable_output.swf';


// FLASH - By putting these here the nasty IE grey border no longer appears around the Flash player
function getFlashMovieObject(movieName) {
    // Ensure that the correct tag is returned for the objext IE == OBJECT, Moz/FF == EMBED
    if (window.document[movieName]) {
        return window.document[movieName];
    }
        if (navigator.appName.indexOf("Microsoft Internet")==-1) {
            if (document.embeds && document.embeds[movieName]) {
                return document.embeds[movieName];
            }
            else {
                return document.getElementById(movieName);
            }
        }
    }
      
    function SendXMLtoFlash() {
      var objFlash = getFlashMovieObject('MainFlashFile');
      objFlash.SetVariable('name', xmlVar);
      return true;
    }

    function writeFlash() {
        if (flashURL) {
            var flashOutput = '';
            
            if ((blnIe4) || (blnIe5) || (blnIe6) || (blnIe7)) {
                flashOutput = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + strCodebase + '" width="746" height="340" id="MainFlashFile">';
                flashOutput += '<param name="movie" value="'+ flashURL +'" />';
                flashOutput += '<param name="quality" value="high" />';
                flashOutput += '<param name="bgcolor" value="#000000" />';
                flashOutput += '<param name="loop" value="false" />';
                flashOutput += '<param name="menu" value="false" />';
                flashOutput += '<param name="flashVars" value="' + flashVars + '" />';
                flashOutput += '<param name="wmode" value="transparent" />';
                flashOutput += '</OBJECT>';
            } else {
                flashOutput = '<EMBED src="'+ flashURL +'" flashVars="' + flashVars + '" quality="high" bgcolor="#FFFFFF" width="746" height="340" type="application/x-shockwave-flash" pluginspace="' + strEmbedSource + '" name="MainFlashFile" swliveconnect="true" wmode="transparent"></EMBED>';
            }
            
            ftnGetObject("flashHero").innerHTML=flashOutput;
        }

        if ((blnIe4) || (blnIe5) || (blnIe6) || (blnIe7)) {
            var boolSuccess = SendXMLtoFlash();
        }
        else {
            setFlashVariables(flashVars)
        }
    }
    
    function setFlashVariables(XML){ 
        // RAF
        // Re-writes gateway movie to pass XML via flash's internal local connection (fix for Firefox).       
        // gatewaycontainer hidden for ie (see global.xslt) 
        /*document.getElementById("gatewaycontainer").style.display = 'block';
        document.getElementById("gatewaycontainer").innerHTML = "";*/
        
        var noxml = true;
        if(XML != null){
            flashVars += "&myText=" + escape(XML);
            noxml = false;
        }
    }
    

// BROWSER DEPENDENCE CORE FUNCTIONS -----------------------------------------------------------------------

    function ftnGetObjectString(strObjectId) {
    /*Purpose	:	Used to return a string that represents the path to an object in the DOM
				        dependent on the browser being used.
	    Effects	:	None
	    Inputs	:	strObjectId - String - the id of an object
	    Returns	:	String - the path to the object in the DOM
    */
	    if(blnNs4) return "document." + strObjectId;
	    if(blnIe4) return "document.all." + strObjectId;
	    if(blnIe5 || blnNs6 || blnOpera){
		    if (blnMac && blnIe5)
			    return "document.all['" + strObjectId + "']";
		    else
			    return "document.getElementById('" + strObjectId + "')";
	    }
    }

    function ftnGetObject(strObjectId) {
    /*Purpose	:	Used to return an object in the DOM.
	    Effects	:	None
	    Inputs	:	strObjectId - String - the id of an object
	    Returns	:	Object - the object in the DOM
    */
	    var strEval = ftnGetObjectString(strObjectId);
	    return eval(strEval);
    }

function ftnGetObjLoc(objIn) {
    /*
	    Purpose	:	Finds the position of the specified object relative to screen 0, 0.
	    Effects	:	None.
	    Inputs	:	objIn - Object - the object to find the position of.
	    Returns	:	Object - an object containing .left and .top.
    */
	var objOut = new Object();
	objOut.left = objIn.offsetLeft;
	objOut.top = objIn.offsetTop;
	var objNewPos = objIn.offsetParent;
	
	while(objNewPos != null) {
		if (objNewPos.style)
		    if (objNewPos.style.position=='absolute')
		        break; 
		objOut.left += objNewPos.offsetLeft;
		objOut.top += objNewPos.offsetTop;
		objNewPos = objNewPos.offsetParent;
	}
	return objOut;
}