var requiredVersion = 8;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;


// JavaScript helper required to detect Flash Player PlugIn version information
//to fix issue with FF and new flash players - BMH [0090219]
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		//	alert("flashVer="+flashVer);
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

function CreateFlashTagsSWF(width, height, flashUrl)
{
	
	if (isIE) {
		 var flashVersion = getFlashVersion ();
	}else
	{
		 var flashVersion = GetSwfVer().substring(0,2); //to fix issue with FF and new flash players - BMH [0090219]
	}
   
	
    if (flashVersion >= requiredVersion) {
      AC_FL_RunContentNoCheck( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width',width,'wmode','opaque','height',height,'align','middle','src',flashUrl,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',flashUrl ); //end AC code
    }
    else
    {
        var textMessage = "";
        if (flashVersion > 0) {
        textMessage = "Your Flash Version: " + flashVersion;
        }
        else if (flashVersion == 0) {
        textMessage = "You don\'t have Flash installed on the current browser.";
        }
        else if (flashVersion == flashVersion_DONTKNOW || flashVersion == null) {
        textMessage = "This browser does not support Javascript-based Flash detection.";
        }

        document.write('<table style="width:' + width + ';height:' + height + ';border:1px solid #ffffff;background-color:#bbbbbb"><tr><td align="center" valign="middle"><div style="text-align:left;background-color:#ffffff;width:' + (parseInt(width) - 8) + ';height:' + (parseInt(height) - 8) + '" id=sectionText><p><big>The content you are attempting to view requires Macromedia Flash Player version ' + requiredVersion + ' or higher. Click on the icon below to download the free version of this player.<br><br><a href=http://www.macromedia.com/go/getflashplayer target=_blank><img src=/images/get_flash_player.gif border=0></a><br><br>' + textMessage + '</big></p></div></td></tr></table>');

    }

return;  
}

function AC_FL_RunContentNoCheck(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function CreateImageTag(width, height, imageUrl, addlStyle)
{
    document.write('<img src="' + imageUrl + '" width="' + width + '"' + ( addlStyle.length > 0 ? ' style="' + addlStyle + '"' : '') + '>');
}
function CreateObjectTags(maxWidth, maxHeight, width, height, objectUrl)
{
    if (maxWidth > -1)
    {
        // If the use "MaxWidth" flag is set to true, then adjust the image width and keep the ration for the height
        if (arguments.length > 6 && arguments[6])
        {
            height = height * (maxWidth/width);
            width = maxWidth;
        }

        // determine if the image will fit in the dimensions given, if not
        // then determine the ratio that is required to shrink the image to
        // the proper size
        if (width > maxWidth || height > maxHeight)
        {
            var ratio = 1;
            if (width > maxWidth)
            {
                ratio = maxWidth/width;
            }
            if (height * ratio > maxHeight && maxHeight > -1)
            {
               ratio = maxHeight/(height * ratio);
            }
            width = width * ratio;
            height = height * ratio;
        }
    }

    if (objectUrl.toLowerCase().indexOf(".swf") == -1)
    {
        var addlStyle = "";
        if (arguments.length > 5 && arguments[5] != null)
        {
        addlStyle = arguments[5];
        }
	    CreateImageTag(width, height, objectUrl, addlStyle);
    }
    else
    {
	    CreateFlashTagsSWF(width, height, objectUrl);
    }
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('.swf') > -1)
    return src;
  else if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';
  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );

	if (isIE) {
		 var flashVersion = getFlashVersion ();
	}else
	{
		 var flashVersion = GetSwfVer().substring(0,2); //to fix issue with FF and new flash players - BMH [0090219]
	}
	
    if (flashVersion >= requiredVersion) {
  	AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
    }
    else
    {
        var textMessage = "";
        if (flashVersion > 0) {
        textMessage = "Your Flash Version: " + flashVersion;
        }
        else if (flashVersion == 0) {
        textMessage = "You don\'t have Flash installed on the current browser.";
        }
        else if (flashVersion == flashVersion_DONTKNOW || flashVersion == null) {
        textMessage = "This browser does not support Javascript-based Flash detection.";
        }

        document.write('<table style="width:100%;height:100%;border:1px solid #ffffff;background-color:#bbbbbb"><tr><td align="center" valign="middle"><div style="text-align:left;background-color:#ffffff;width:99%;height:99%" id=sectionText><p><big>The content you are attempting to view requires Macromedia Flash Player version ' + requiredVersion + ' or higher. Click on the icon below to download the free version of this player.<br><br><a href=http://www.macromedia.com/go/getflashplayer target=_blank><img src=/images/get_flash_player.gif border=0></a><br><br>' + textMessage + '</big></p></div></td></tr></table>');

    }

}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)


function isDefined(property) {
  return (typeof property != 'undefined');
}

var flashVersion = 0;

function getFlashVersion() {
   var latestFlashVersion = 9;
   var agent = navigator.userAgent.toLowerCase(); 
   
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
   // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
   if (navigator.plugins != null && navigator.plugins.length > 0) {
      var flashPlugin = navigator.plugins['Shockwave Flash'];
      if (typeof flashPlugin == 'object') { 
         for (var i = latestFlashVersion; i >= 3; i--) {
            if (flashPlugin.description.indexOf(i + '.') != -1) {
               flashVersion = i;
               break;
            }
         }
      }
   }

   // IE4+ Win32:  attempt to create an ActiveX object using VBScript
   else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {

        var version = "";
        for (var i = latestFlashVersion; i >= 7; i--) {
	        try {
		        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
		        version = axo.GetVariable("$version");
		        var re = /WIN\s(\d+),.*/gi;
		        flashVersion = re.exec(version)[1];
		        break;
	        } catch (e) {
	        }
	    }

        // Old style of original WPP site
        if (flashVersion == 0)
        {
            var doc = '<scr' + 'ipt language="VBScript"\> \n';
            doc += 'On Error Resume Next \n';
            doc += 'Dim obFlash \n';
            doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
            doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
            doc += '   If IsObject(obFlash) Then \n';
            doc += '      flashVersion = i \n';
            doc += '      Exit For \n';
            doc += '   End If \n';
            doc += 'Next \n';
            doc += '</scr' + 'ipt\> \n';
            document.write(doc);
        }
   }
      
   // WebTV 2.5 supports flash 3
   else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

   // older WebTV supports flash 2
   else if (agent.indexOf("webtv") != -1) flashVersion = 2;

   // Can't detect in all other cases
   else {
      flashVersion = flashVersion_DONTKNOW;
   }
   return flashVersion;
}

flashVersion_DONTKNOW = -1;


