/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.3
*/
var FlashDetect = new function(){
	var self = this;
	self.installed = false;
	self.raw = "";
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	var activeXDetectRules = [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	};
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	};
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");//replace with regex
		return {
			"raw":str,
			"major":parseInt(versionArray[0].split(" ")[1], 10),
			"minor":parseInt(versionArray[1], 10),
			"revision":parseInt(versionArray[2], 10),
			"revisionStr":versionArray[2]
		};
	};
	var parseStandardVersion = function(str){
		var descParts = str.split(/ +/);
		var majorMinor = descParts[2].split(/\./);
		var revisionStr = descParts[3];
		return {
			"raw":str,
			"major":parseInt(majorMinor[0], 10),
			"minor":parseInt(majorMinor[1], 10), 
			"revisionStr":revisionStr,
			"revision":parseRevisionStrToInt(revisionStr)
		};
	};
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
	};
	self.majorAtLeast = function(version){
		return self.major >= version;
	};
	self.FlashDetect = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var version = mimeTypes[type].enabledPlugin.description;
				var versionObj = parseStandardVersion(version);
				self.raw = versionObj.raw;
				self.major = versionObj.major;
				self.minor = versionObj.minor; 
				self.revisionStr = versionObj.revisionStr;
				self.revision = versionObj.revision;
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var versionObj = parseActiveXVersion(version);
						self.raw = versionObj.raw;
						self.major = versionObj.major;
						self.minor = versionObj.minor; 
						self.revision = versionObj.revision;
						self.revisionStr = versionObj.revisionStr;
					}
				}
			}
		}
	}();
};
FlashDetect.release = "1.0.3";

// IMM 011108: Clears input field, if contents is "search" or "enter email address"
// IMM 031408: Added "search videos"
function clearText(oFld)
{
	if ((oFld.value == "search") || (oFld.value == "enter email address") || (oFld.value == "search videos") || (oFld.value == "Search DEMO.com") || (oFld.value == "Search News"))
		oFld.value = "";
}

// IMM 011108: Forces field's contents to lower case
function lowerCase(oFld)
{
	oFld.value = oFld.value.toLowerCase();
}

// TJK 011808:  browser detection variables
var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var firefox = (agt.indexOf("firefox") != -1);
var safari = (agt.indexOf("safari") != -1);

var author = "";
var keywords = "";
var publisher = "";

// TJK 011808:  hitbox utility function.
function hbxStrip(a)
{
	 a = a.split("\n").join("");
	 a = a.split("\r").join("");
     a = a.split("|").join("");
     a = a.split("&").join("");
     a = a.split("'").join("");
	 a = a.split("\"").join("");
     a = a.split("#").join("");
     a = a.split("$").join("");
     a = a.split("%").join("");
     a = a.split("^").join("");
     a = a.split("*").join("");
     a = a.split(":").join("");
     a = a.split("!").join("");
     a = a.split("<").join("");
     a = a.split(">").join("");
     a = a.split("~").join("");
     a = a.split(";").join("");
     a = a.split(" ").join("+");
     return a;
}

if (document.getElementsByName) {
  var metaArray = document.getElementsByName('author');
  if(metaArray[0]) author = hbxStrip(metaArray[0].content);
  var metaArray = document.getElementsByName('keywords');
  if(metaArray[0]) keywords = hbxStrip(metaArray[0].content);
  var metaArray = document.getElementsByName('publisher');
  if(metaArray[0]) publisher = hbxStrip(metaArray[0].content);  
}

// TJK 011808:  process click events to open external windows
function register(e)
{
	if (!e) e = window.event;
	var element = e.srcElement;
	if(firefox) element = e.target;
	if(safari) element = e.target.parentNode;
	var ref = element.href;
	myref = ref;
   	if(ref && ref.slice(0,ref.indexOf("://")) == "http" && element.target != "_blank") {
      ref = ref.substr(7);
      ref = ref.slice(0,ref.indexOf("/"));
      var idgnet_check = new RegExp ("(nww.com$)|(demo.com$)","i");
      if (!idgnet_check.test(ref) && (is_ie || firefox || safari)) {
         element.target = "_blank";
      }
   	}
	if (typeof customOnclick== "function") customOnclick();
	return true;
}

// TJK 011808: register and event for all clicks
$(document).ready(function(){
	if (safari) document.addEventListener("click", register, false);
	else document.onclick = register;
});

// IMM 012008: Code to handle auto-activating Flash objects
// -  sID : id
// - sSrc : Source for Flash SWF, with arguments if any
// - iWdt : Width
// - iHgt : Height
// - sCID : classid			  (leave blank if undefined)
// - sAln : Alignment		  (leave blank if undefined)
// - sQul : Quality			  (leave blank if undefined)
// - sASA : allowScriptAccess (leave blank if undefined)
// - sWMd : wmode			  (leave blank if undefined)
// - sBGC : bgcolor			  (leave blank if undefined)
// - bAlt : Alternate mode - used for custom Flash objects (Podcasts)
//          If true, then:
//			1. Includes "data" attribute, with sSrc
//			2. does not use "embed" tag
//          3. Includes: ie_update=\"NWW_NO_IE_OBJECT_UPDATE\"
//			4. Excludes: codebase attribute
//			5. Includes: type="application/x-shockwave-flash"
// -------------------------------------------------------------------------
// IMM 071108: Optional Flash/Firefox MP3 player bug fix
// - If this argument is not an empty string, will proceed to check browser 
//   and Flash player version. If they match the version which has the bug
//   that prevents MP3 players from playing when there are too many players
//   on a page (more than 15), then it will render just a link to the argument
//   instead of the Flash player.
function autoactivateFlash( sID, sSrc, iWdt, iHgt, sCID, sAln, sQul, sASA, sWMd, sBGC, bAlt, sFLA )
{
	var bFLA = true;
	if (sFLA != undefined)
	{
		var sExt = sFLA.substr( sFLA.length - 3, 3 ).toLowerCase();

		if ((navigator.appName != "Microsoft Internet Explorer") && (sExt == "mp3"))
		{
			if ((FlashDetect.major == 9) && (FlashDetect.minor == 0) && ((FlashDetect.revision == 115) || (FlashDetect.revision == 124)))
				bFLA = false;

/*			sDBG = "Flash: " + FlashDetect.major + "." + FlashDetect.minor + "." + FlashDetect.revision + "\n";
			sDBG+= "Browser: " + navigator.appName + " - " + navigator.appVersion + "\n";
			sDBG+= "URL: " + sFLA + "\n";
			sDBG+= "Extension: " + sExt + "\n";
			sDBG+= "bFLA=[" + bFLA + "]";
			alert(sDBG);
*/		}
	}

	if (bFLA)
	{
		var sSwf = "<object " + 
				   (bAlt != true ? "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" " : "") + 
				   (bAlt == true ? "type=\"application/x-shockwave-flash\" " : "") + 
				   (sID != "" ? "id=\"" + sID + "\" " : "") + 
				   (bAlt == true ? "data=\"" + sSrc + "\" " : "") + 
				   "width=\"" + iWdt + "\"  " + 
				   "height=\"" + iHgt + "\" " + 
				   (bAlt == true ? "ie_update=\"NWW_NO_IE_OBJECT_UPDATE\" " : "") + 
				   (sCID != "" ? "classid=\"clsid:" + sCID + "\" " : "") + 
				   (sAln != "" ? "align=\"" + sAln + "\" " : "") + 
				   ">\n" + 
				   "<param name=\"movie\" value=\"" + sSrc + "\"/>\n" +
				   (sQul != "" ? "<param name=\"quality\" value=\"" + sQul + "\"/>\n" : "") + 
				   (sASA != "" ? "<param name=\"allowScriptAccess\" value=\"" + sASA + "\"/>\n" : "") + 
				   (sWMd != "" ? "<param name=\"wmode\" value=\"" + sWMd + "\"/>\n" : "") + 
				   (sBGC != "" ? "<param name=\"bgcolor\" value=\"" + sBGC + "\"/>\n" : "");
		if (bAlt != true)
		{
			sSwf += "<embed " + 
					(sID != "" ? "name=\"" + sID + "\" " : "") + 
					"width=\"" + iWdt + "\"  " + 
					"height=\"" + iHgt + "\" " + 
					(sAln != "" ? "align=\"" + sAln + "\" " : "") + 
					"src=\"" + sSrc + "\" " + 
					(sQul != "" ? "quality=\"" + sQul + "\" " : "") + 
					(sASA != "" ? "allowscriptaccess=\"" + sASA + "\" " : "") + 
					(sWMd != "" ? "wmode=\"" + sWMd + "\" " : "") + 
					(sBGC != "" ? "bgcolor=\"" + sBGC + "\" " : "") + 
					"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" " +  
					"type=\"application/x-shockwave-flash\"/></embed>\n";
		}
		sSwf += "</object>\n";
		document.write(sSwf);
	}
	else
		document.write("<a href=\"" + sFLA + "\" target=\"_blank\">Click to download this podcast</a><br/>(will open in a new browser window)");
}

// IMM 012108: Get top offset of passed element
function getPageOffsetTop( oEle ) 
{
	var iOffTop = oEle.offsetTop;
	while((oEle = oEle.offsetParent) != null) 
	{ 
		iOffTop += oEle.offsetTop; 
	}
	return iOffTop;
}

// IMM 012108: Returns Y position of passed anchor
function getAnchorYPos(sAnchor) 
{
	var yPos = 0;
	
	// Logic to find position
 	if (document.getElementById && document.all) 
		yPos = getPageOffsetTop(document.all[sAnchor]);
	else if (document.getElementById) 
		yPos = getPageOffsetTop(document.getElementById(sAnchor));
 	else if (document.all) 
		yPos = getPageOffsetTop(document.all[sAnchor]);
	else if (document.layers) 
	{
		var bFnd = 0;
		for (var i = 0; i < document.anchors.length; i++) 
		{
			if (document.anchors[i].name == sAnchor) 
			{ 
				bFnd = 1; 
				break; 
			}
		}

		if (bFnd == 0) 
			return yPos;
		
		yPos = document.anchors[i].yPos;
	}

	return yPos;
}

// IMM 012408: Function to popup a window
function popPage( sSrc, iWdt, iHgt, iTop, iLft )
{
	window.open( sSrc, "_Media", "status=0,toolbar=0,location=0,menubar=0,resizeable=0,scrollbars=0,top=" + iTop + ",left=" + iLft + ",height=" + iHgt + ",width=" + iWdt );
}
