// JavaScript Document
document.onmousemove = getMouseXY;
//var xmlhttp = false;

var tooltip = {
	x:0,
	y:0,
	id:false,
	lastq:null,
	coverid:false,
	timer:null,
	swfurl:"/tips/tooltip.swf",
	http:false,
	
	padding:"7px",
	
	start: function(){
		var node = document.createElement("DIV");
		
		node.id = "tooltipdiv";
		this.id = node.id;
		node.style.position = "absolute";
		node.style.zIndex = "99";
		node.style.top = "0px";
		node.style.left = "0px";
		node.style.display = "none";
		node.style.visiblity = "hidden";
		node.style.width = "auto";
		node.style.overflow = "visible";
		node.style.padding = this.padding;
		node.style.backgroundColor = "#cEd7e6";
		node.style.border = "2px solid #000066";
		node.style.fontFamily = "Verdana, Arial, Sans-serif";
		node.style.fontSize = "11px";
		node.setAttribute("onMouseOver","tooltip.saveme()");
		//node.setAttribute("onMouseOut","tooltip.hide()")
		
		var coverup = document.createElement("A");
		coverup.id = "coverupid";
		this.coverid = coverup.id;
		coverup.style.position = "absolute";
		coverup.style.zIndex = "69";
		coverup.style.textDecoration = "none";
		coverup.style.backgroundColor = "#333333";
		
		coverup.style.display = "block";
		coverup.style.top = "0px";
		coverup.style.left = "0px";
		coverup.style.width = "100%";
		coverup.style.height = "100%";
		coverup.style.display = "none";
		
		if(IE){
			coverup.style.filter ="alpha(opacity=50)";
		}else {
			coverup.style.opacity = ".5";
		}
		
		coverup.href= "javascript:tooltip.hidenow()";
		coverup.innerHTML = "&nbsp;";
		
		document.getElementsByTagName("body")[0].appendChild(node);
		document.getElementsByTagName("body")[0].appendChild(coverup);
		
		this.write_swf();
		
	},
	
	saveme: function() {
		clearTimeout(this.timer);
	},
	
	toggle: function(code){
		$(this.id).style.visibility = "hidden";
		if($(this.id).style.display == "none") {
			$(this.id).style.display = "block";
			$(this.coverid).style.display = "block";
			eval(code);
		} else {
			$(this.id).style.display = "none";
			$(this.coverid).style.display = "none";
			$(this.id).style.visibility = "hidden";
		}
	},
	
	setWidthAuto: function() {
		$(this.id).style.width = "auto";
	},
	
	toggleX: function(id) {
		var imageurl = $(id).style.backgroundImage;
		
		if( this.lastq == null) {
			this.lastq = id;
			imageurl = imageurl.split("_q_").join("_x_");
			
		} else {
			imageurl = imageurl.split("_x_").join("_q_");
			this.lastq = null;
		}
		$(id).style.backgroundImage =  imageurl;
		
	},
	
	text: function(str) {
		$(this.id).style.borderWidth = "1px"
		$(this.id).style.padding = this.padding;
		$(this.id).style.display = "block";	
		if(str.length > 25) $(this.id).style.width = "200px";
		else $(this.id).style.width = "auto";
		$(this.id).style.height = "auto";
		
		this.setPos();
		$(this.id).style.visibility = "visible";
		
		$(this.id).innerHTML = str;
		
	},
	
	tip: function(str) {
		clearTimeout(this.timer);
		this.timer = setTimeout("tooltip.text(\""+str+"\")",500);
	},
	
	setPos: function(w,h) {
		
		var width = document.body.clientWidth;
		if( width == undefined ) width = window.innerWidth;
		var height = document.body.scrollHeight;
		
		if( height == undefined) height = window.innerHeight;
		else height +=  document.body.scrollTop;
		
		$(this.coverid).style.height = height + "px";
	
		if(!w) {//no stuff
			
			if( this.x > width/2) { //right 
				
				$(this.id).style.left = "";
				$(this.id).style.right = (width-(this.x-20))+"px";
				
			} else {
				
				$(this.id).style.left = this.x+10+"px";
				$(this.id).style.right = "";
				
			}
			if( this.y > 270) {
				$(this.id).style.top = (this.y-200)+"px";
				
			} else {
				$(this.id).style.top = (this.y-20)+"px";
				$(this.id).style.bottom = "";
			}
		} else {//left and right specified
			if( this.x > width/2) { //right 
				$(this.id).style.top = (h)+"px";
				$(this.id).style.left = "";
				$(this.id).style.right = (w)+"px";
				
			} else {
				$(this.id).style.top = h+"px";
				$(this.id).style.left = w+"px";
				$(this.id).style.right = "";
			}
		}
		
	},
	
	write_swf: function(url){
		if( flashversion < 8 ) {
			$(this.id).style.width = "200px";
			
			$(this.id).innerHTML = "<h1>Please Upgrade Your Flash Player</h1>";
			$(this.id).innerHTML += "<p>This feature requires Flash Player 8. To make the most of this site, update your player at the <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW'>Adobe.com</a>.</p>";
			
		} else {
			
			if(!url) url = "";
			
			$(this.id).style.visibility = "hidden";
			$(this.id).style.padding = "0";
			$(this.id).style.width = "200px";
			$(this.id).style.height = "200px";
			
			
			$(this.id).innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='100%' height='100%'";
			$(this.id).innerHTML +=  "<param name='movie' value='"+this.swfurl+"' />";
			$(this.id).innerHTML +=  "<param name='quality' value='high' />";
			$(this.id).innerHTML +=  "<param name='FlashVars' value='loadurl="+url+"' />";
			$(this.id).innerHTML +=  "<embed src='"+this.swfurl+"' FlashVars='loadurl="+url+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='100%' height='100%'></embed>";
			$(this.id).innerHTML +=  "</object>";
		}
	},
	
	swf: function(url,w,h) {
		if(url){
			url = "/tips"+"/" + url;
		}
		
		this.write_swf(url);
		if(w) this.setPos(w,h);
		else this.setPos();
		//set in resize
		$(this.id).style.display = "block";	
		$(this.id).style.visibility = "visible";
		
	},
	
	file: function(url,w,h) {
		$(tooltip.id).style.borderWidth = "2px";
		$(tooltip.id).style.height = "auto";
		if(url){
			url = "/tips"+"/" + url;
		}
		if( w ) tooltip.setPos(w,h);
		else tooltip.setPos();
		
		//ajax start
		//xmlhttp = false;
		if( window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); //mozilla
		else if( window.ActiveXObject ) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//windows
		if( xmlhttp ) {
			xmlhttp.onreadystatechange = tooltip.writeFile;
			tooltip.http = xmlhttp;
			tooltip.http.open("GET", url, true);
			tooltip.http.send(null);
		}
	},
	
	writeFile: function() {
		if( tooltip.http.readyState==4 && tooltip.http.status==200) {
			
			var txt = tooltip.http.responseText;
			var start = txt.indexOf("<!--TooltipSize:");
			if( start != -1) start += ("<!--TooltipSize:").length;
			
			var end = txt.indexOf("TooltipSizeEnd-->");
			var size = txt.slice(start,end).split(",");
		
			
			$(tooltip.id).style.padding = tooltip.padding;
			$(tooltip.id).innerHTML = txt;
			if( start != -1 ) tooltip.resize(size[0]);
			else tooltip.resize(200);
			
		}
	},
	
	setwidth: function(w) {
		$(this.id).style.width = w+"px";
	},
	
	resize: function(w,h) {
		clearTimeout(this.timer);
		$(this.id).style.display = "block";
		
		if(w) {
			$(this.id).style.width = w+"px";
		}
		if(h) {
			$(this.id).style.height = h+"px";
		}
		$(this.id).style.visibility = "visible";
		
	},
	
	hide: function(){
		clearTimeout(this.timer);
		this.timer = setTimeout("$(\""+this.id+"\").style.display = 'none';$(\""+this.coverid+"\").style.display = 'none';$(\""+this.id+"\").style.visibility = 'hidden';",750);
	}, 
	
	hidenow: function(){
		$(this.id).style.display = "none";
		$(this.coverid).style.display = "none";
		$(this.id).style.visibility = "hidden";
		if(this.lastq != null) this.toggleX(this.lastq);
		this.lastq = null;
	}
	
}

function getMouseXY(e) {
	if(IE) {
		tooltip.x = event.clientX + document.documentElement.scrollLeft;
		tooltip.y = event.clientY + document.documentElement.scrollTop;
		
	} else {
		tooltip.x = e.x;
		tooltip.y = e.y;	
	}
}