/************************************************************************************************************************
st_menu.js || controls the study guide Menu || used with the cCap.js (custom caption)
------------------------------------------------------------------------------------------------------------------------
Developed By Cory Caines || Kreated Nine Web Development
************************************************************************************************************************/
var img_lst = [];
var to_lst = [];
window.onload = function(){
	initCaption();	
}
function preload(loc){
	var nImg = new Image();
	nImg.src = loc;
	return nImg;
}
function initCaption(){
	var imgs = tag("img")
	for(i=0;i<=imgs.length-1;i++){		
		id = imgs[i].id;
		cId = id.split("_");
		isImg = cId[cId.length-1];
		if(isImg == "img"){
			var img = $(id);
			nid = id.replace(/_img/,"");
			img_lst[nid] = new Object();
			img_lst[nid].up = preload(img.src);
			if(img.src.indexOf("_ovr.gif") > -1){
				img_lst[nid].ovr = preload(img.src);
			}else{
				img_lst[nid].ovr = preload(img.src.replace(/.gif/, "_ovr.gif"));
			}
			
		}
	}
}
function icon_over(id,title){
	var img = $(id+"_img");
	if(img_lst[id]){
		img.src = img_lst[id].ovr.src;
	}
	var caption = $("caption");
	var caption_text = $("caption_text");
	caption_text.innerHTML = title;
	oWidth = caption_text.offsetWidth;
	caption.style.width = (oWidth+8)+"px";
	imgPos = getPosXY(img);
	var left = ((imgPos['x'] - (oWidth/2)) + (11))+"px";
	var top = (imgPos['y'] - 28)+"px";
	to_lst[id] = window.setTimeout("showCaption('"+left+"','"+top+"')",200);
}
function showCaption(left,top){
	var caption = $("caption");
	caption.style.left = left;
	caption.style.top = top;
}
function icon_out(id){
	window.clearTimeout(to_lst[id]);
	var img = $(id+"_img");
	if(img_lst[id]){
		img.src = img_lst[id].up.src;
	}
	
	$("caption_text").innerHTML= "";
	var caption = $("caption");
	caption.style.left = -5000+"px";
}

function getPosXY(obj){
	var pp= [];
	pp["x"] = this.getPosX(obj);
	pp["y"] = this.getPosY(obj);
	return pp;
}
function getPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function getPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}