
// preload the image for the tip for firefox
preload1= new Image(7,5); 
preload1.src="tooltip.gif"; 

function CreateImageToolTip(img,tiptext) {

	//alert("Div offsetTop: " + img.offsetTop + " div offsetLeft: " + img.offsetLeft + " div width: " + img.width + " "  + tiptext);
	
	
	if (!document.getElementById("tip")) { // only one tip should be active at a time
		// create div for text
		var divtip = document.createElement("div")
		divtip.setAttribute('id',"tip")
		document.body.appendChild(divtip)

		// create the tip image
		var tipimg = document.createElement("img")
		tipimg.setAttribute('id',"tipimg")
		tipimg.setAttribute('src',"tooltip.gif")
		document.body.appendChild(tipimg)
		document.getElementById("tipimg").style.position = "absolute"


		var elm_div = document.getElementById("tip") // lets grab the elements we just created
		var elm_img = document.getElementById("tipimg") // grab the pointer image

		// set styles on the tip box	
		elm_div.style.border = "solid 1px black"
		elm_div.innerHTML =  tiptext
		elm_div.style.position = "absolute";
		elm_div.style.background = "white"

		// position the top of the tool tip			
		elm_img.style.top = img.offsetTop - elm_img.height 
		elm_div.style.top = img.offsetTop - elm_img.height - elm_div.offsetHeight +1 ;
		// position the left side of the tool tip
		if (elm_div.offsetWidth > img.width ) { // image is smaller than the div
			elm_div.style.left = img.offsetLeft - ((elm_div.offsetWidth - img.width) / 2)
			elm_img.style.left = img.offsetLeft - ((elm_img.width - img.width) / 2)
		}
		else if (elm_div.style.width < img.width) { // div is smaller than the image
			elm_div.style.left = img.offsetLeft + ((img.width - elm_div.offsetWidth)  / 2) 
			elm_img.style.left = img.offsetLeft - ((elm_img.width - img.width) / 2) 
		}
		else  // image and tip are same size
		{
			elm_div.style.left = img.offsetLeft;
			elm_img.style.left = img.offsetLeft - ((elm_img.width - img.width) / 2) 
		}
	}
	
	
}

function CreateToolTip(div,tiptext) {

	//this is same as CreateImageToolTip except div's style handled differently
	//alert("Div offsetTop: " + div.offsetTop + " div offsetLeft: " + div.offsetLeft + " div width: " + div.style.width + " div Height: " + div.style.height + " top: " + div.style.top + " left: " + div.style.left);
	
	
	if (!document.getElementById("tip")) { // only one tip should be active at a time
		// create div for text
		var divtip = document.createElement("div")
		divtip.setAttribute('id',"tip")
		document.body.appendChild(divtip)

		// create the tip image
		var tipimg = document.createElement("img")
		tipimg.setAttribute('id',"tipimg")
		tipimg.setAttribute('src',"tooltip.gif")
		document.body.appendChild(tipimg)
		document.getElementById("tipimg").style.position = "absolute"

		

		var elm_div = document.getElementById("tip") // lets grab the elements we just created
		var elm_img = document.getElementById("tipimg") // grab the pointer image

		// set styles on the tip box	
		elm_div.style.border = "solid 1px black"
		elm_div.innerHTML =  tiptext
		elm_div.style.position = "absolute";
		elm_div.style.background = "white"

		// position the top of the tool tip			
		elm_img.style.top = div.offsetTop - elm_img.height 
		elm_div.style.top = div.offsetTop - elm_img.height - elm_div.offsetHeight +1 ;
		// position the left side of the tool tip
		if (elm_div.offsetWidth > div.style.width ) { // image is smaller than the div
			elm_div.style.left =div.offsetLeft  - ((elm_div.offsetWidth - div.style.width) / 2)
			elm_img.style.left =div.offsetLeft  - ((elm_img.width - div.style.width) / 2)
		}
		else if (elm_div.style.width < div.style.width) { // div is smaller than the image
			elm_div.style.left = div.offsetLeft  + ((div.style.width - elm_div.offsetWidth)  / 2) 
			elm_img.style.left = div.offsetLeft  - ((elm_img.width - div.style.width) / 2) 
		}
		else  // image and tip are same size
		{
			elm_div.style.left = div.offsetLeft ;
			elm_img.style.left = div.offsetLeft  - ((elm_img.width - div.style.width) / 2) 
		}
	}
	
	
}


function RemoveToolTip() {
	// remove the tool tip div and the image associated with it
	if (document.getElementById("tip")) {
		elm = document.getElementById("tip")
		document.body.removeChild(elm)
	}
	if (document.getElementById("tipimg")) {
		elm = document.getElementById("tipimg")
		document.body.removeChild(elm)
	}			
}
