/************************************************************************************************************************
whatsthis.js || load help information from database
------------------------------------------------------------------------------------------------------------------------
Developed By Cory Caines || Kreated Nine Web Development
************************************************************************************************************************/

var wiClose = null;

function addWI(){
	document.write("<div align=\"center\" id=\"whats_this\" style=\"left:-500px; top:-500px; z-index:2; background-color:#FFFFFF; border: 1px solid #CCCCCC; color: #000000; padding-top:10px; padding-bottom:10px; padding-left:10px; padding-right:10px; position: absolute;\"></div>");	
}

browser = new browser();
function browser() {
	this.IE    = false;
	this.NS    = false
	agent = navigator.userAgent;
	if ((i = agent.indexOf("MSIE")) >= 0) {
		this.IE = true;
		return;
	}
	if ((i = agent.indexOf("Gecko")) >= 0) {
		this.NS = true;
		return;
	}
	if ((i = agent.indexOf("Netscape6/")) >= 0) {
		this.NS = true;
		return;
	}
}

var fWidth = 300;
var fHeight = 200;
var ypos;
var xpos;

//whatis over
function wi_over(event,width,height){
	//move the what is box and set to loading 
	var wiBox = $("whats_this");
	
	if(browser.IE){
		pre_obj = window.event.srcElement;	
	}
	if(browser.NS){
		pre_obj = event.target;
	}
	
	if(width != null || width != ''){
		fWidth = width;	
	}
	if(height != null || height != ''){
		fHeight = height;	
	}
	
	var src;
	src = "<div class=\"featuredCont\">";
	src += "<img src=\"i/loading.gif\" width=\"50\" height=\"50\" />";
	src += "  Loading ... ";
	src += "</div>";
	wiBox.innerHTML = src;
	
	// Setting the height of the box
	wiBox.style.width = '100px';
	wiBox.style.height = '100px';
	
	// Setting hte position of the box on the page.
	var tbody = (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	ypos = (tbody.scrollTop + event.clientY);
	xpos = event.clientX;

	
	wiBox.style.left = (xpos+100)+"px";
	wiBox.style.top = (ypos-100)+"px";
	
	wiBox.onmousemove = function(){
		if(wiClose != null){
			window.clearTimeout(wiClose);	
		}
	}
	
	// Setting the time out for the mouse out
	wiBox.onmouseout = function(){
		wiClose = window.setTimeout("wi_reset()",3000);
	}
	
	// Resets the page and removes the box.
	wiBox.ondblclick = function(){
		wi_reset();	
	}
		
	// The request varibale, thats the location where you get your data from.
	var rel = pre_obj.getAttribute('rel');
	wi_load(rel,pre_obj.y,pre_obj.x);
}


function wi_out(){
	//reset the box
	wiClose = window.setTimeout("wi_reset()",2000);
}

function wi_reset(){
	var wiBox = $("whats_this");
	wiBox.innerHTML = "";
	wiBox.style.left = "-500px";
	wiBox.style.top = "-500px";
	wiBox.style.overflow = "hidden";
}

function wi_load(rel){
	req=makeRequest();
	if (req==null){
		msg("Browser does not support HTTP Request")
		return
	} 

	req.onreadystatechange=wi_read;
	url = rel;
	req.open("GET",url,true)
	req.send(null)	
}
function wi_read(){
	switch (req.readyState) {
		case 1 : 
		break;
		case 4 :
			if (req.status == 200) {
				//then the information has come in
				wiBox = $("whats_this");
				data = req.responseText;
				
				
				wiBox.style.width = fWidth+"px";
				wiBox.style.height = fHeight+"px";
				wiBox.style.overflow = "auto";
				//change the x and y positions
				ypos -= fHeight;
				xpos += 60;
				wiBox.style.top = ypos+"px";
				wiBox.style.left = xpos+"px";
				
				wiBox.innerHTML = data;
	
			}
		break;
	}
			
}

function makeRequest(){ 
	var objXMLHttp=null;
	
	if (window.XMLHttpRequest){
	  objXMLHttp=new XMLHttpRequest()
	}else if(window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
