/* ObjectSwap - Bypasses the new ActiveX Activation requirement in Internet Explorer by swapping existing ActiveX objects on the page with the same objects. Can also be used for Flash version detection by adding the param:
<param name="flashVersion" value="6" /> to the object tag.

Author: Karina Steffens, www.neo-archaic.net
Created: April 2006
*/

//Check if the browser is InternetExplorer
var ie = (navigator.appName.indexOf("Microsoft") != -1);

//Hide the object to prevent it from loading twice
if (ie){
	document.write ("<style id='hideObject'> object{display:none;} </style>");
}

/*Replace all flash objects on the page with the same flash object, 
by rewriting the outerHTML values
This bypasses the new IE ActiveX object activation issue*/
objectSwap = function(){
	//Get a list of all ActiveX objects
	var objects = document.getElementsByTagName('object');	
	for (var i=0; i<objects.length; i++){		
		var o = objects[i];	
		var h = o.outerHTML;
		//The outer html omits the param tags, so we must retrieve and insert these separately
		var paramList = o.getElementsByTagName('param');
		var params = "";
		for (var j = 0; j<=paramList.length; j++) {
			var p = paramList[j];
			if (p != null){
				//Check for version first - applies to all browsers
				//For this to work, a new param needs to be included in the object with the name "flashVersion" eg:
				//<param name="flashVersion" value="7" />
				if (p.name == "flashVersion"){
					if (!detectFlash(p.value)){
						stripFlash(o, paramList);
						break;
					}
				}
				params += p.outerHTML;		       
			}
		}		
		//Only target internet explorer
		if (!ie){
			continue;
		} 
		//Avoid specified objects, marked with a "noswap" classname
		if (o.className.toLowerCase().indexOf ("noswap") != -1){
			continue;
		}		
		//Get the tag and attributes part of the outer html of the object
		var tag = h.split(">")[0] + ">";			
		//Add up the various bits that comprise the object:
		//The tag with the attributes, the params and it's inner html
		var newObject = tag + params + o.innerHTML + " </OBJECT>";		
		//And rewrite the outer html of the tag 
		o.outerHTML = newObject;
	}
	//Make the object visible again
	if (ie){
		document.getElementById("hideObject").disabled = true;
	}
}

detectFlash = function(version){
	if(navigator.plugins.length){
		//Non-IE flash detection.
		var plugin = navigator.plugins["Shockwave Flash"];
		if (plugin == undefined){
			return false;
		}
		var ver = navigator.plugins["Shockwave Flash"].description.split(" ")[2];
		return (Number(ver) >= Number(version))
	} else if (ie){
	//IE flash detection.
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);
			return true;
		}
		catch(e){
			return false;
		}
	}
	//Catchall - skip detection
	return true;
}

//Replace the object by a div tag containing the same innerHTML.
//To display a message for the user and a link to the flash installation page, place it inside the object tag.
stripFlash = function (o, paramList){
	var newHTML = o.innerHTML;
	newHTML = newHTML.replace (/embed/i, "span");	
	var d = document.createElement("div");
	d.innerHTML = newHTML;
	d.className = o.className;
	d.id = o.id;
	o.parentNode.replaceChild(d, o);
}


//Initiate the function without conflicting with the window.onload event of any preceding scripts
if (window.onload)
{
	window.onload = function(){
		window.onload;
		objectSwap();
	}
} else {
	window.onload = objectSwap;
}





















