//א
if (document.images){
	preload_image_object = new Image();
	image_urls = new Array();
	image_urls['orig'] = "http://www.brianmoylan.info/media/brianmoylanheader.gif";
	image_urls['blue'] = "http://www.brianmoylan.info/media/brianmoylanheaderblue.gif";
	image_urls['green1'] = "http://www.brianmoylan.info/media/brianmoylanheadergreen1.gif";
	image_urls['green2'] = "http://www.brianmoylan.info/media/brianmoylanheadergreen2.gif";
	image_urls['yellow'] = "http://www.brianmoylan.info/media/brianmoylanheaderyellow.gif";
	var i = 0;
	for(i=0; i<=image_urls.length; i++) preload_image_object.src = image_urls[i];
}
function drawTC(){
	//window.open('themechanger.php','themechanger','height=200,width=176,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	tc = document.getElementById("themec");
	tc.innerHTML = '<div style="position: relative; width: 144px; z-index: 2; height: 200px; border: #808080 1px solid; background-color: #ffffff;"><div style="border-bottom: #808080 1px solid; padding: 6px; margin-bottom: 10px; background-color: #b0b0b0; color: #ffffff; font-weight: bold;">theme changer</div><table border="0" cellspacing="0" cellpadding="0" class="holder" align="center" style="position: relative; float: left; width: 144px;"><tr><td class="holder" align="center"><input type="button" value="green theme 1" class="buttongreen1" style="width: 118px; margin-bottom: 10px; height: 22px;" onclick="changeStyle(\'green1\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'" /><br /><input type="button" value="green theme 2" class="buttongreen2" style="width: 121px; margin-bottom: 10px; height: 22px;" onclick="changeStyle(\'green2\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'" /><br /><input type="button" value="yellow theme" class="buttonyellow" style="width: 110px; margin-bottom: 10px; height: 22px;" onclick="changeStyle(\'yellow\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'" /><br /><input type="button" value="blue theme" class="buttonblue" style="width: 96px; margin-bottom: 10px; height: 22px;" onclick="changeStyle(\'blue\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'" /><br /><input type="button" value="original theme" class="buttonorig" style="width: 118px; margin-bottom: 10px; height: 22px;" onclick="changeStyle(\'\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'" /></td></tr></table>\n';
	tc.innerHTML = tc.innerHTML+'<div id="tcclose" onclick="document.getElementById(\'themec\').innerHTML = \'&nbsp;\';displayTC(\'off\');" onmouseover="this.style.cursor=\'hand\';this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\'">x</div>\n';
	tc.innerHTML = tc.innerHTML+'</div>\n';
}
function displayTC(onofffadein){
	stretchShade();
	var overlay = document.getElementById('overlay');
	if (onofffadein == 'on'){
		overlay.style.opacity = 0.2;
		overlay.style.zIndex = 1;
		overlay.style.filter = 'alpha(opacity=20)';
		overlay.style.display = 'inline';
		if (document.getElementById("menusholder") != null){
			document.getElementById("menusholder").style.zIndex = -1;
		}
	}
	else if (onofffadein == 'fadein'){
		//code to blacken screen
		overlay.style.opacity = 1;
		overlay.style.filter = 'alpha(opacity=100)';
		//
		fadeoutOverlay();
	}
	else{
		overlay.style.display = 'none';
		if (document.getElementById("menusholder") != null){
			document.getElementById("menusholder").style.zIndex = 2;
		}
	}
}
var fadeinrate = 0;
function fadeoutOverlay(){
	fadeinrate = 8;
	var overlay = document.getElementById('overlay');
	if ((overlay.style.opacity != 0) || (overlay.style.filter != 'alpha(opacity=0)')){
		//setTimeout('fadeinPage()',100);
		fadeinPage();
	}
}
function fadeinPage(){
	var overlay = document.getElementById('overlay');
	var thisFilterOpac = "";
	thisFilterOpac = overlay.style.opacity * 100;
	thisFilterOpac = parseInt(thisFilterOpac - fadeinrate);
	if (document.getElementById("navholder") != null){
		document.getElementById("navholder").style.zIndex = -1;
	}
	overlay.style.opacity = '0.'+thisFilterOpac;
	overlay.style.filter = 'alpha(opacity='+thisFilterOpac+')';
	if (thisFilterOpac < 60){
		fadeinrate = fadeinrate + 1;
	}
	if (thisFilterOpac < 18){
		overlay.style.display = 'none';
		overlay.style.opacity = 0;
		overlay.style.filter = 'alpha(opacity=0)';
		if (document.getElementById("menusholder") != null){
			document.getElementById("menusholder").style.zIndex = 2;
		}
		if (document.getElementById("navholder") != null){
			document.getElementById("navholder").style.zIndex = 1;
		}
	}
	else{
		setTimeout('fadeinPage()',50);
	}
}
function doHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
function stretchShade(){
	var overlay = document.getElementById("overlay");
	overlay.style.width = "100%";
	overlay.style.height = doHeight()+'px';
}
function changeStyle(wantedStyle){
	displayTC('fadein');
	getTheme(wantedStyle);
}
function changePage(wantedStyle){
	document.getElementById("themec").innerHTML = '&nbsp;';
	document.getElementById('pagestyles').href="style/brianmoylan"+wantedStyle+".css";
	//change validation gfx icons if blue
	if (wantedStyle=="blue"){
		document.getElementById("w3clogo").src = 'media/valid-xhtml10-blue.png';
		document.getElementById("w3ccss").src = 'media/valid-css-blue.png';
	}
	else{
		document.getElementById("w3clogo").src = 'media/valid-xhtml10.png';
		document.getElementById("w3ccss").src = 'media/valid-css.png';
	}
}
function sendXmlReq(args){
	var httpRequest;
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
    	}
	}
	else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (!httpRequest) {
		return false;
	}
	var url = "ajaxthemechanger.php";
	var method = "POST";
	httpRequest.open(method, url, true);
	httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//httpRequest.setRequestHeader("Content-length", args.length);
	//httpRequest.setRequestHeader("Connection", "close");
	httpRequest.onreadystatechange = function() {//Call a function when the state changes.
		if(httpRequest.readyState == 4 && httpRequest.status == 200) {
			var rt = httpRequest.responseText;
			changePage(getXmlContent(rt));
		}
	}
	httpRequest.send(args);
}
function getXmlContent(str){
	var contentStart = '<![CDATA[';
	var contentEnd = ']]';
	return str.substring(str.indexOf(contentStart)+contentStart.length,str.indexOf(contentEnd))
}
function getTheme(theme){
	var targ = 'ajaxthemechanger.php';
	var args = 'newtheme='+theme;
	sendXmlReq(args);
}
