/******************************************************************************
 This is the flash detection script.
 ******************************************************************************/
var required = 7;
var hasFlash = false;
if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") != -1) {
	document.write('<SCR'+'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	// AFAIK creating an instance of an older version of the Flash object 
	// will return succeed even if the actual installed version is newer.
	document.write('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & required))) \n');
	document.write('<'+'/scr'+'ipt\> \n');
} else {
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (plugin) {
		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash"+isVersion2].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".")-1));
		hasFlash = flashVersion>=required;
	}
}


/******************************************************************************
 This classes the <html> element as `hasFlash` if flash is found. This style
 hook can be used to hide our to-be-replaced content before it even comes down
 the datapipe and eliminate the FOPSC ("Flash of Partially Styled Content")
 ******************************************************************************/
if (hasFlash && document.getElementsByTagName && document.getElementsByTagName('html')[0]) {
	document.getElementsByTagName('html')[0].className += (document.getElementsByTagName('html')[0].className == '') ? 'hasFlash' : ' hasFlash';
}

/******************************************************************************
 Some utility functions. Look at them--aren't they useful?
 ******************************************************************************/
function SI_normalizeWhiteSpace(txt) {
	var rE = /\s+/gi;
	return txt.replace(rE, ' ');
}

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";
	}
}

/******************************************************************************/
function SI_replaceElement(elem, swf, w, h, afv, cName) {
	var d = document;
	var newParentNode = document;
	if (!hasFlash || !d.getElementsByTagName) {
		return;
	}
	var r = new Object();
	r.p = new Object();
	r.e = new Object();
	// Checking if element is exist
	if (elem.indexOf(' ') != -1) {
		// alert('Reference to parent found...');
		elemArray = elem.split(' ');
		elem = elemArray[1];
		if (elemArray[0].indexOf('#') != -1) {
			// alert('Reference to parent's id found...');
			parentArray = elemArray[0].split('#');
			r.p.id = parentArray[1];
			r.p.tagName = parentArray[0];
			r.p.className = false;
			newParentNode = document.getElementById(r.p.id);
		} else if (elemArray[0].indexOf('.') != -1) {
			// alert('Reference to parent's className found...');
			parentArray = elemArray[0].split('.');
			r.p.id = false;
			r.p.tagName = parentArray[0];
			r.p.className = parentArray[1];
		} else {
			r.p.id = false;
			r.p.tagName = elemArray[0];
			r.p.className = false;
		}
	} else {
		// alert('No reference to parent found...');
		r.p.id = false;
		r.p.tagName = false;
		r.p.className = false;
	}
	// Checking if element has ID
	if (elem.indexOf('#') != -1) { //Not have an ID
		//alert('Reference to element\'s id found...');
		elemArray = elem.split('#');
		r.e.id = elemArray[1];
		r.e.tagName = elemArray[0];
		r.e.className = false;
	} else if (elem.indexOf('.') != -1) { //Not have a classname
		//alert('Reference to element\'s className found...');
		elemArray = elem.split('.');
		r.e.id = false;
		r.e.tagName = elemArray[0];
		r.e.className = elemArray[1];
	} else {
		r.e.id = false;
		r.e.tagName = elem;
		r.e.className = false;
	}
	//
	if (afv != '') {
		afv = SI_normalizeWhiteSpace(afv);
		afv = '&'+afv;
	}

	if (!newParentNode){
		var elems = d.getElementsByTagName(r.e.tagName);
	}else{
		var elems = newParentNode.getElementsByTagName(r.e.tagName);
	}
	
	var count = elems.length;
	
	for (var i = 0; i<count; i++) {
		e = elems[i];
		pnn = "";
		pni = "";
		pnc = "";
		pn = e;
		while (pn.parentNode) {
			pnn += pn.parentNode.nodeName.toUpperCase()+"|";
			pni += pn.parentNode.id+"|";
			pnc += pn.parentNode.className+"|";
			pn = pn.parentNode;
		}
		if (!r.p.tagName || (((r.p.tagName && !r.p.id && !r.p.className && pnn.indexOf(r.p.tagName.toUpperCase())!=-1) || ((r.p.id && pni.indexOf(r.p.id)!=-1) || (r.p.className && pnc.indexOf(r.p.className)!=-1))))) {
			if ((r.e.tagName && !r.e.id && !r.e.className) || (r.e.id && e.id == r.e.id) || (r.e.className && e.className == r.e.className)) {
				// alert('Make replacement');
				var txt;
				txt = SI_normalizeWhiteSpace(e.innerHTML);
				var c = d.createElement('div');
				c.className = 'replaced-'+r.e.tagName;
				c.style.padding = cName;
				e.parentNode.replaceChild(c, e);
				// The replaceChild acts like shift() on the
				// array that holds all of our elems. Meaning it
				// removes the first index and the remaining indexes
				// move up one.
				// The length or our elems array decreases by one
				count--;
				// Override the increment on loop index too.
				// We could just use e = elems[0]; above if we knew that
				// every instance of this particular element was going 
				// to be replaced--but there's no way of knowing that's
				// how it will play out.
				i--;
				var fv = 'txt='+txt+afv;
				//document.write(fv);
				var swfHTML;
				swfHTML = '<object 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+'">';
				swfHTML += '	<param name="movie" value="'+swf+'" />';
				swfHTML += '	<param name="flashvars" value="'+fv+'" />';
				swfHTML += '	<param name="wmode" value="transparent" />';
				swfHTML += '	<embed src="'+swf+'" flashvars="'+fv+'" wmode="transparent" width="'+w+'" height="'+h+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />';
				swfHTML += '<'+'/object>';
				c.innerHTML = swfHTML;
				txt = '';
			}
		}
	}
}


/******************************************************************************
 This is where the magic happens. This should really be the only part of this
 script you need to modify. Just add the necessary SI_replaceElement() calls 
 and make sure this sucker is called onload.
 ******************************************************************************/
function SI_flashReplacement() {
	SI_replaceElement('div#content h2.special', 'head.swf', "100%", 40, 'txtSize=&txtColor=0xF1AC02','');
	SI_replaceElement('div#sitemap h2.special', 'head.swf', "100%", 40, 'txtSize=&txtColor=0xF1AC02','');
	SI_replaceElement('div.wholeBlocktitle h2', 'head.swf', "100%", 40, 'txtSize=&txtColor=0xF1AC02','');
	SI_replaceElement('div#content h2', 'head2.swf', "100%", 25, 'txtSize=&txtColor=0xF1AC02','');
	SI_replaceElement('div#RightCont h2', 'head.swf', "100%", 40, 'txtSize=&txtColor=0x5D5D5D','');
	SI_replaceElement('div#LeftCont h2', 'head.swf', "100%", 40, 'txtSize=&txtColor=0x154A40','');
	SI_forceRedraw();
}
/******************************************************************************
 This sets the entire thing in motion. Place any other scripts that need to run
 onload in the SI_onload() function or add SI_flashReplacement to your own 
 onload handler.
 ******************************************************************************/
function SI_onload() {
	SI_flashReplacement();
}
//window.onload = SI_onload;
