﻿// JScript File

//this function shows or hides the Flavor Finder layer
		//strTargetID = ID of div that calls the toggle
		//strDivID = ID of div to toggle
		function toggleDiv(strTargetID,strDivID) {
		    var objTarget = document.getElementById(strTargetID);
		    var objLayer = document.getElementById(strDivID);

		    if (objLayer.style.visibility == "hidden") {
		    	objLayer.style.visibility = "visible";
		    } else {
		    	objLayer.style.visibility = "hidden";
		    }

		    setLyr(objTarget,strDivID);
	    }
	    
//these functions find the current position of the Flavor Finder graphic and move the popup div relative to it

		function setLyr(obj,lyr) {
			var newX = findPosX(obj);
			var newY = findPosY(obj);
			newX -= 14;
			newY += 60;
			var x = new getObj(lyr);
			x.style.top = newY + 'px';
			x.style.left = newX + 'px'
		}

		function findPosX(obj) {
			var curleft = 0;
			if (obj.offsetParent) {
				while (obj.offsetParent)
				{
					curleft += obj.offsetLeft;
					obj = obj.offsetParent;
				}
			}
			else if (obj.x) {
				curleft += obj.x
			}
			return curleft
		}

		function findPosY(obj) {
			var curtop = 0;
			if (obj.offsetParent) {
				while (obj.offsetParent) {
					curtop += obj.offsetTop;
					obj = obj.offsetParent
				}
			}
			else if (obj.y) {
				curtop += obj.y
			}
			return curtop
		}


		function getObj(name) {
			 if (document.getElementById) {
				   this.obj = document.getElementById(name);
				   this.style = document.getElementById(name).style
			 }
			 else if (document.all) {
				   this.obj = document.all[name];
				   this.style = document.all[name].style
			 }
			 else if (document.layers) {
				   if (document.layers[name]) {
						this.obj = document.layers[name];
						this.style = document.layers[name]
				   }
				   else {
						this.obj = document.layers.testP.layers[name];
						this.style = document.layers.testP.layers[name]
				   }
			 }
		}