var divs= new Array();
var show_flag = 0;
var timerID = 0;

 function startClock(){ 
 	x = x-y ;
	 timerID = setTimeout("startClock()", 1000) ;
	if(x==0){ 
		hideAd();
		x=2;
		}
	}


function stopClock(){
 	x = 2;
	y = 1; 
	//alert("stop clock");
	clearTimeout(timerID);
}

//captureMousePosition(e), makePositionedCoords(element,x,y), and the below if-else
//statement controls the location of where the ads should be displayed.
if (document.layers)
{
	// Netscape
	document.captureEvents (Event.MOUSEMOVE);
	document.onmousemove = captureMousePosition;
	document.captureEvents (Event.MOUSEUP);
} else if (document.all)
{
	// Internet Explorer
	document.onmousemove = captureMousePosition;
} else if (document.getElementById)
{
	// Netcsape 6
	document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0;
// Horizontal position of the mouse on the screen
yMousePos = 0;
// Vertical position of the mouse on the screen
xMousePosMax = 0;
// Width of the page
yMousePosMax = 0;
// Height of the page

//move the element to a specified location
function makePositionedCoords(element,x,y) {
    element = $(element);
    var pos = Element.getStyle(element, 'position');
    if (pos == 'static' || !pos) {
      element._madePositioned = true;
      element.style.position = 'absolute';
	  
      if (window.opera) {
        element.style.top = 0;
        element.style.left = 0;
      }
    }
	element.style.top = -x;
	element.style.left = y;
  }
  
//capture the mouse position
function captureMousePosition (e)
{
	if (document.layers)
	{
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth + window.pageXOffset;
		yMousePosMax = window.innerHeight + window.pageYOffset;
	} else if (document.all)
	{
		xMousePos = window.event.x + document.body.scrollLeft;
		yMousePos = window.event.y + document.body.scrollTop;
		xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight + document.body.scrollTop;
	} else if (document.getElementById)
	{
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth + window.pageXOffset;
		yMousePosMax = window.innerHeight + window.pageYOffset;
	}
}

//show the specified ad
function showAd(element,id)
{
	divs.push(element);
	if (show_flag != id){
	hideAd();
	show_flag=id;
	makePositionedCoords(element,-yMousePos+(.2*yMousePos),xMousePos-20);

	Element.show(element);
	//startClock();
	}

}

//show the specified ad
function showNutritionAd(element,id)
{
	divs.push(element);
	if (show_flag != id){
	hideAd();
	show_flag=id;
	makePositionedCoords(element,-20,300);

	Element.show(element);
	scrollTo(0,0);
	//startClock();
	}

}


//hide all ads
function hideAd()
{
	show_flag=0;
	stopClock();
	for (var loop = 0; loop < divs.length; loop++)
		{
			Element.hide(divs[loop]);	
		}	
}