// 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 = 8;
   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 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;
flashVersion = getFlashVersion();



// if Flash plug-in version is greater or same as required version, display Flash page title
function showPageTitle (requiredVer) {
	if (document.getElementById && flashVersion >= requiredVer) {
		if (document.getElementById("content_flash")) {
			toggleFlash (true);
		}
		if (document.getElementById("title_flash")) document.getElementById("title_flash").style.display = "block";
		if (document.getElementById("title_noflash")) document.getElementById("title_noflash").style.display = "none";
	}
}



function toggleFlash (bool) {
	var blnToggle = bool;
	if (document.getElementById) {
		if (String(blnToggle) == "undefined") {
			blnToggle = (document.getElementById("content_flash") && document.getElementById("content_flash").style.display == "none") ? true : false;
		}

		if (document.getElementById("pageTitle")) document.getElementById("pageTitle").style.display = (blnToggle) ? "none" : "block";
		if (document.getElementById("content_flash")) document.getElementById("content_flash").style.display = (blnToggle) ? "block" : "none";
		if (document.getElementById("content_noflash")) document.getElementById("content_noflash").style.display = (blnToggle) ? "none" : "block";

	}
	return false;
}



// function to call on page load...
function init() {
	showPageTitle (6);
}


// function called by page title Flash movie to dynamically resize itself
function setTitleSize(requiredVer, w, h) {
	if (document.getElementById && flashVersion >= requiredVer) {
		if (document.getElementById("title_object")) {
			document.getElementById("title_object").style.width = String(w) + "px";
			document.getElementById("title_object").style.height = String(h) + "px";
		}
		if (document.getElementById("title_embed")) {
			document.getElementById("title_embed").style.width = String(w) + "px";
			document.getElementById("title_embed").style.height = String(h) + "px";
		}
	}
	
	if (document.getElementById && document.getElementById("rowMiddle") && document.getElementById("colCenter") && document.getElementById("pageTitle")) {
		document.getElementById("colCenter").style.height = (document.getElementById("rowMiddle").offsetHeight - document.getElementById("pageTitle").offsetHeight) + "px";
	}
}


// opens pop-up windows
function windowOpen (url, name, w, h) {
	var newwindow;
	if((w == 0 || String(w) == "undefined") || (h == 0 || String(h) == "undefined")) {
		newwindow = window.open(url, name);
	} else {
		newwindow = window.open(url, name, "width=" + w + ",height=" + h + ",toolbar=no,resizable=no");
	}

	if (window.focus) {newwindow.focus()}
	return false;
}
