// JavaScript Document

function BrowserInfo()
{
	this.name = navigator.appName;
	this.codename = navigator.appCodeName;
	this.version = navigator.appVersion.substring(0,4);
	this.platform = navigator.platform;
	this.javaEnabled = navigator.javaEnabled();
	this.cookie = navigator.cookieEnabled
	this.screenWidth = screen.width;
	this.screenHeight = screen.height;
	
}

addthis_pub             = 'joeLouis.in'; 
//addthis_logo            = 'http://me.juzliketat.com/_images/sjl_h-text-24.png';
addthis_logo_background = 'EFEFFF';
addthis_logo_color      = '666699';
addthis_brand           = 'juzliketat.com';
addthis_options         = 'favorites, email, digg, delicious, myspace, facebook, google, live, stumbleupon, technorati, newsvine, reddit, more';
/*delicious, digg, email, favorites, facebook, fark, furl, google, live, myweb, myspace, newsvine, reddit, slashdot, stumbleupon, technorati, twitter, more
(the default is currently 'favorites, digg, delicious, google, myspace, facebook, reddit, newsvine, live, more', in that order).*/

function getHeight()
{	var a = new BrowserInfo();
	var scrollH;
	var screenH, windowH, pageMinH, myHeight = 0;
	
/*  	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{	myHeight = window.innerHeight;
  	} else if( document.documentElement && document.documentElement.clientHeight ) //IE 6+ in 'standards compliant mode'
	{	myHeight = document.documentElement.clientHeight;
  	} else if( document.body && document.body.clientHeight )    //IE 4 compatible
	{	myHeight = document.body.clientHeight;
  	}
*/
//	pageMinH = 800;
	screenH = a.screenHeight;
	scrollH = document.body.scrollHeight;
	windowH = myHeight;
//	document.write("a.screenHeight: " + screenH + "<br> document.body.scrollHeight:" + scrollH + "<br> myHeight:" + windowH);
/*	if(scrollH < windowH)
	{ return windowH;
	} else if(scrollH > windowH)
	{ return scrollH;
	} 
*/
	if((a.name == 'Microsoft Internet Explorer') || (a.name == 'Opera'))
	{ return scrollH;
	} else if(a.name == 'Netscape')
	{ return (scrollH-14);}
	
/*	if((scrollH < windowH) && (scrollH < screenH))
		{ return windowH;
		} else if((scrollH > windowH) && (scrollH < screenH))
		{ return screenH;
		} else if((scrollH > windowH) && (scrollH > screenH))
		{ return scrollH;
		}
	}
*/}

function adjustHeight(h,i)
{	var b = new BrowserInfo();

	if((b.name == 'Microsoft Internet Explorer') || (b.name == 'Opera'))
	{ 	document.write("#v-grey-bar-pix{height:" + (h) + "px;}");
		document.write("#v-color-bar{height:" + h + "px;}");
	}/* else if(b.name == 'Netscape')
	{	document.write("#v-grey-bar-pix{height:" + (h+14) + "px;}");
		document.write("#v-color-bar{height:" + (h+14) + "px;}");
	}*/ else if((b.name == 'Netscape') && (i == null))
	{	document.write("#v-grey-bar-pix{height:" + (h+14) + "px;}");
		document.write("#v-color-bar{height:" + (h+14) + "px;}");
	} else if((b.name == 'Netscape') && (i == "f"))
	{	document.write("#v-grey-bar-pix{height:" + (h+14+14) + "px;}");
		document.write("#v-color-bar{height:" + (h+14+14) + "px;}");
	}

	document.write("#v-grey-bar{height:" + h + "px;}");
	document.write("#header-side-left{height:" + h + "px;}");
}

function getWidth()
{	var a = new BrowserInfo();
	var scrollW, screenW, pageMinW, windowW, myWidth = 0;
		
  	if( typeof( window.innerWidth ) == 'number' )//Non-IE
	{	myWidth = window.innerWidth;
  	} else if( document.documentElement &&  document.documentElement.clientWidth )//IE 6+ in 'standards compliant mode'
	{	myWidth = document.documentElement.clientWidth;
  	} else if( document.body && document.body.clientWidth )//IE 4 compatible
	{	myWidth = document.body.clientWidth;
  	}
	
	pageMinW = 1000;
	screenW = a.screenWidth;
	scrollW = document.body.scrollWidth;
	windowW = myWidth;
	
	if ((pageMinW > screenW) && (pageMinW > windowW)) //screens less than 1000px width + browser window width less than 1000px
	{	return pageMinW;
	}else if ((pageMinW < screenW) && (pageMinW < windowW)) //screens wider than 1000px width + browser window width more than 1000px
	{	return windowW;
	}else if ((pageMinW < screenW) && (pageMinW > windowW)) //screens wider than 1000px width + browser window width less than 1000px
	{	return pageMinW;
	}/*else
	{	return pageMinW;
	}*/
}

function style(s)
{	if (s == 0)
	{	document.write("<style type='text/css' media='screen'>");
	}if (s == 1)
	{	document.write("</style>");
	}
}

function myColor(x)
{	var dColor=new Array()
	dColor[0]="D16B81"	//Sunday Color - Pink-ish
	dColor[1]="C0CD35"	//Monday Color - Light Green
	dColor[2]="54ACB8"	//Tuesday Color - Blue
	dColor[3]="ECB800"	//Wednesday Color - Yellow
	dColor[4]="9B79A8"	//Thursday Color - Pinkish Violet
	dColor[5]="FAA75E"	//Friday Color - Light Orange
	dColor[6]="CDA491"	//Saturday Color - Light Brown
	dColor[7]="D16B81"	//Sunday Color - Pink-ish
	dColor[8]="C0CD35"	//Monday Color - Light Green
	dColor[9]="54ACB8"	//Tuesday Color - Blue
	dColor[10]="ECB800"	//Wednesday Color - Yellow
	dColor[11]="9B79A8"	//Thursday Color - Pinkish Violet
	dColor[12]="FAA75E"	//Friday Color - Light Orange
	dColor[13]="CDA491"	//Saturday Color - Light Brown
	dColor[14]="D16B81"	//Sunday Color - Pink-ish
	dColor[15]="C0CD35"	//Monday Color - Light Green
	dColor[16]="54ACB8"	//Tuesday Color - Blue
	dColor[17]="ECB800"	//Wednesday Color - Yellow
	dColor[18]="9B79A8"	//Thursday Color - Pinkish Violet
	dColor[19]="FAA75E"	//Friday Color - Light Orange
	dColor[20]="CDA491"	//Saturday Color - Light Brown
	dColor[21]="D16B81"	//Sunday Color - Pink-ish
	dColor[22]="C0CD35"	//Monday Color - Light Green
	dColor[23]="54ACB8"	//Tuesday Color - Blue

	var dColorTime=new Date();
	var colorToday=dColorTime.getDay();
	var colorHour=dColorTime.getHours();
	
	if ((x == "H") || (x == "h"))
	{	return dColor[colorHour];
	} else if ((x == "D") || (x == "d"))
	{	return dColor[colorToday];
	}

}

function readCookie(name)
{	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{	offset = document.cookie.indexOf(search);
		if (offset != -1)
    	{ 	offset += search.length;
      		end = document.cookie.indexOf(";", offset);
      		if (end == -1) end = document.cookie.length;
      		cookieValue = unescape(document.cookie.substring(offset, end))
	    }
	}
	return cookieValue;
}

function writeCookie(name, value, hours)
{	var expire = "";
	if(hours != null)
	{	expire = new Date((new Date()).getTime() + hours * 3600000);
    	expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

function setMyColor(x)
{	ccode=readCookie('ccode');
	if ((ccode != null) && (ccode != ""))
  	{	return ccode;
	}else 
	{	return myColor(x);
	}
}

function initXmlAjax(containerID,xmlFile,fn)
{	var req = null; 
	//document.getElementById(divID).innerHTML = "Started...";
	try
	{	req = new XMLHttpRequest();
	}catch (e)
	{	try
		{	req = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e)
		{	try
			{	req = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e)
			{	alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
/*  if(window.XMLHttpRequest)
		req = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
		req  = new ActiveXObject("Microsoft.XMLHTTP"); 
	else if (window.ActiveXObject)
		req  = new ActiveXObject("Msxml2.XMLHTTP");
*/
		req.onreadystatechange = function()
		{	document.getElementById(containerID).innerHTML = "<span class=\"text_10\">Loading...</span>";
			if(req.readyState == 4)
			{	if(req.status == 200)
				{	var XmlNode = req.responseXML
				  	switch (fn)
					{	case "quote4u":
							quote4u(containerID,XmlNode);//document.getElementById("quoteNo").innerHTML  = "Received:" + req.responseXML;
							break;	
						case "drawMyWorksXML":
							drawMyWorksXML(containerID,XmlNode);
							break;		
					}
				}else	
				{	document.getElementById(containerID).innerHTML="Error: returned status code " + req.status + " " + req.statusText;
				}	
			} 
		}; 
		
	req.open("GET", xmlFile, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}

function quote4u(containerID, Xnode)
{	var totalNodes = Xnode.getElementsByTagName("quoteNo").length;
	var i = randomNumber(totalNodes);	
	document.getElementById(containerID).innerHTML = "<table border=\"0\" align=\"center\">" +
	  "<tr><td rowspan=\"3\" width=\"75\" class=\"toLeft\" valign=\"top\"><img src=\"_images/blockquote.gif\" width=\"46\" height=\"28\"/></td>" +
	  "<td class=\"text_10 toLeft text_CAPS\">Quote:</td></tr>" +
	  "<tr><td class=\"toCenter text_18\">" + Xnode.getElementsByTagName("quote")[i].firstChild.data + "</td></tr>" +
	  "<tr><td class=\"toRight text_I text_12\">- " + Xnode.getElementsByTagName("author")[i].firstChild.data + "</td></tr></table>";
}

function drawMyWorksXML(containerID, Xnode)
{	var totalNodes = Xnode.getElementsByTagName("projNo").length;
	document.getElementById(containerID).innerHTML = "";
	for (i=1;i<=(totalNodes+1);i++)
	{	document.getElementById(containerID).innerHTML += "<div class=\"myWorks_website\">" +
		"<img src='" + Xnode.getElementsByTagName("projPreviewImg")[i].firstChild.data + "'/>" +
		"<p>Client: <a href='" + Xnode.getElementsByTagName("projLink")[i].firstChild.data + "' target=\"_blank\">" + Xnode.getElementsByTagName("forClient")[i].firstChild.data + "</a><br />" +
		"Project Type: " + Xnode.getElementsByTagName("projType")[i].firstChild.data + "<br />" +
		"Used: " + Xnode.getElementsByTagName("techUsed")[i].firstChild.data + "</p></div>";
	}
}

function randomNumber(limit)
{	return Math.floor(Math.random()*limit);
}

//var quote = get_element (doc_el, "quote", 0);
//var author = get_element (doc_el, "author", 0);
function get_element (doc_el, name, idx) {
    var element = doc_el.getElementsByTagName (name);
    return element[idx].firstChild.data;
}

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}
