/* Multiline Inman Flash Replacement 04.09.22 */
var hasFlash = function(){
	var nRequiredVersion = 6;	
	if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		document.write('<script language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n');  
		document.write('<'+'/script\> \n');
		/*	If executed, the VBScript above checks for Flash and sets the hasFlash variable. 
			If VBScript is not supported it's value will still be undefined, so we'll run it though another test
			This will make sure even Opera identified as IE will be tested */
		if(window.hasFlash != null){
			return window.hasFlash;
			};
		};
	
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		return flashVersion >= nRequiredVersion;
		};
	return false;
	}();

String.prototype.normalize = function(){
	return this.replace(/\s+/gi, " ");
	};

/* IE 5.0 does not support the push method, so here goes * /
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
		};
	};
/**/
function SI_forceRedraw() {
	// Corrects a margin-bottom sum bug in Mozilla
	var d = document;
	if (d.body && d.body.style) {
		d.body.style.height = "1px";
		d.body.style.height = "auto";
		}
	}
var getElementsBySelector = function(){
	var reParseSelector = /^([^#\.>\`]*)(#|\.|\>|\`)(.+)$/;
	function getElementsBySelector(sSelector, oParentNode, sMode){
		sSelector = sSelector.replace(" ", "`");
		var selector = sSelector.match(reParseSelector);
		var node, listNodes, listSubNodes, subselector;
		var listReturn = [];

		if(selector == null){ selector = [sSelector, sSelector]	};
		if(selector[1] == ""){ selector[1] = "*" };
		if(sMode == null){ sMode = "`" };
		
		switch(selector[2]){
			case "#":
				subselector = selector[3].match(reParseSelector);
				if(subselector == null){ subselector = [null, selector[3]] };
				node = 	document.getElementById(subselector[1]);
				if(node == null || (selector[1] != "*" && node.nodeName.toLowerCase() != selector[1].toLowerCase())){
					return listReturn;
					};
				if(subselector.length == 2){
					//listReturn.push(node);
					listReturn[listReturn.length] = node;
					return listReturn;	
					};
				return getElementsBySelector(subselector[3], node, "#");
			case ".":
				if(sMode == "`"){
					listNodes = getElementsByTagName(oParentNode, selector[1]);
					}
				else {
					listNodes = oParentNode.childNodes;
					};
				
				for(var i = 0; i < listNodes.length; i++){
					node = listNodes[i];
					if(node.nodeType != 1){
						continue;	
						};

					subselector = selector[3].match(reParseSelector);
					if(subselector != null){
						if(node.className.match("\\b" + subselector[1] + "\\b") == null){
							continue;
							};
						listSubNodes = getElementsBySelector(subselector[3], node, subselector[2]);
						listReturn = listReturn.concat(listSubNodes);	
						} 
					else if(node.className.match("\\b" + selector[3] + "\\b") != null){
						//listReturn.push(node);
						listReturn[listReturn.length] = node;
						};
					};
				return listReturn;
			case ">":
				if(sMode == "`"){
					listNodes = getElementsByTagName(oParentNode, selector[1]);
					} 
				else {
					listNodes = oParentNode.childNodes;
					};
				for(var i = 0; i < listNodes.length; i++){
					node = listNodes[i];
					if(node.nodeType != 1){
						continue;	
						};
					if(node.nodeName.toLowerCase() != selector[1].toLowerCase()){
						continue;
						};
					listSubNodes = getElementsBySelector(selector[3], node, ">");
					listReturn = listReturn.concat(listSubNodes);	
					};
				return listReturn;
			case "`":
				listNodes = getElementsByTagName(oParentNode, selector[1]);
				for(var i = 0; i < listNodes.length; i++){
					node = listNodes[i];
					listSubNodes = getElementsBySelector(selector[3], node, "`");
					listReturn = listReturn.concat(listSubNodes);	
					};
				return listReturn;
			default:
				listNodes = getElementsByTagName(oParentNode, selector[0]);
				for(var i = 0; i < listNodes.length; i++){
					//listReturn.push(listNodes[i]);
					listReturn[listReturn.length] = listNodes[i];
					};
				return listReturn;
			};
		};
	
	function getElementsByTagName(oParentNode, sTagName){
		if(sTagName == "*" && oParentNode.all != null){
			return oParentNode.all;
			};
		return oParentNode.getElementsByTagName(sTagName);
		};
	
	return getElementsBySelector;
	}();


var SI_uniqueReplaced = 0;
function SI_replaceElement(selector,swf,size,lineheight,color,textshadow,bgcolor,uppercase,padding) {
	var d = document;
	
	if (!window.hasFlash || !d.getElementsByTagName) return;
	
	var elems = getElementsBySelector(selector);
	for (var i=0; i<elems.length; i++) {
		e = elems[i];
		
		// Silverpoint implementation-specific filter
		if(e.nodeName.toLowerCase()=='h1' && e.parentNode.className.search(/(news-detail|news|calendar-detail|team-detail|gallery|calendar-block)/) != -1 || 
			e.className.indexOf('replaced')>=0) continue;
		
		var txt;
		txt = e.innerHTML.normalize();
		var c = d.createElement('div');
		
		var nw = nh = 0;
		if (padding.length==1) {
			nw = nh = padding[0] * 2;
			}
		else if (padding.length==2) {
			nh = padding[0] * 2;
			nw = padding[1] * 2;
			}
		else if (padding.length==3) {
			nh = padding[0] + padding[2];
			nw = padding[1] * 2;
			}
		else if (padding.length==4) {
			nh = padding[0] + padding[2];
			nw = padding[1] + padding[3];
			}
		
		w = e.offsetWidth-nw;
		h = e.offsetHeight-nh;
		c.className = 'replaced-'+e.nodeName.toLowerCase();
		c.id = 'SI_replaced'+SI_uniqueReplaced++;
		e.parentNode.replaceChild(c,e);
		var fv	= 'txt='+escape(txt)+'&w='+w+'&h='+h+'&id='+c.id+'&s='+size+'&l='+lineheight+'&c='+color+'&ts='+textshadow+'&uc='+uppercase;
		
		var swfHTML;
		swfHTML  = '<object class="mlIFRobject" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'">\n';
		swfHTML += '	<param name="movie" value="'+swf+'" />\n';
		swfHTML += '	<param name="flashvars" value="'+fv+'" />\n';
		swfHTML += '	<param name="bgcolor" value="'+bgcolor+'" />\n';
		swfHTML += '	<param name="wmode" value="opaque" />\n';
		swfHTML += '	<embed class="mlIFRobject" src="'+swf+'" flashvars="'+fv+'" width="'+w+'" height="'+h+'" bgcolor="'+bgcolor+'" wmode="opaque" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />\n';
		swfHTML += '<'+'/object>\n';
		swfHTML += '<'+e.nodeName.toLowerCase()+((e.id)?' id="'+e.id+'"':'')+' class="'+((e.className)?e.className+' ':'')+'replaced">'+txt+'<'+'/'+e.nodeName.toLowerCase()+'>\n';
		c.innerHTML = swfHTML;
		txt='';
		}
	}
function SI_resizeReplacedElement(id,h) {document.getElementById(id).style.height=h+'px';}

function mlIFR() {
	/* Providing a hook for you to hide certain elements if Flash has been detected */
	if(document.documentElement && window.hasFlash){
		document.documentElement.className = "hasFlash";
		var h1p = [34,12,5,16]; // padding for replaced h1s
		if (SI_dir.search(/(aboutchoate|sitemap|calendars|home)/)!=-1) {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','5D5F6A','666873',false,h1p);
			}
		else if (SI_dir=='admission') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','880000','9E0000',false,h1p);
			}
		else if (SI_dir.search(/(academics|students)/)!=-1) {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','829A74','97B285',false,h1p);
			}
		else if (SI_dir=='athletics') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','C3A426','E2BE2C',false,h1p);
			}
		else if (SI_dir=='artscenter') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','6D1B69','7E1F79',false,h1p);
			}
		else if (SI_dir=='summerprograms') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','C68733','E69C3B',false,h1p);
			}
		else if (SI_dir.search(/(supportchoate|parents)/)!=-1) {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','668F91','77A6A7',false,h1p);
			}
		else if (SI_dir=='alumni') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','607D97','6F91AE',false,h1p);
			}
		else if (SI_dir=='facultyampstaff') {
			SI_replaceElement('#primary-content h1','/swf/caslon-regular-html.swf','22','22','FFFFFF','1D2C58','223365',false,h1p);
			}
		//SI_replaceElement('#admission #primary-content .intro h2','/swf/avenir-55-roman-html.swf','10','10','52535C','EFECE0','EFECE0',true,[0,18,4,0]);
		//SI_replaceElement('#primary-content h2','/swf/avenir-55-roman-html.swf','10','10','52535C','FFFFFF','FFFFFF',true,[0,18,4,0]);
		//SI_replaceElement('#primary-content h3','/swf/friz-quadrata-medium-html.swf','14','15','3F5A7E','FFFFFF','FFFFFF',false,[0]);
		};
	}