<!--

var lastObj = null;
var thisObj = null;
var timeout = null;

function findPosX(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 findPosY(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;
}

// Returns the value contained in el's style tag
function getStyle(el, style) {
   if(!document.getElementById) return;
   
     var value = el.style[toCamelCase(style)];
   
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
       
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     
     return value;
}

// Not used
function setStyle(obj, style, value) {
    obj.style[style] = value;
}

// Support function for getStyle
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)   
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ?
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

// Determine where to place the popup based on the calling object and the hidden object properties
function moveObject( obj, caller )
{

  // Set variables (note will have to adjust offset later based on parent window)
  var scrollX = 0;
  var scrollY = 0;
  var browserWidth = 0;
  var browserHeight = 0;
  var x = 0;
  var y = 0;
  var bubblepos = "";

  // Setup offset values
  var xOffset = 40;
  var yOffset = -40;
  var objWidth = parseInt(getStyle(obj, "width"));
  var objHeight = parseInt(getStyle(obj, "height"));
  var callerHeight = parseInt(getStyle(caller, "height"));
  var topSpace = 0;
  var bottomSpace = 0;
  var halfWidth = 0;
  var sideSpace = 0;

  var nextS = obj.childNodes[0];

  // Return position of the hovered (caller) element
	x = findPosX(caller);
	y =  findPosY(caller);

  // Get browser dimensions, scroll positions
  if (document.all) {
	// IE, Opera
    if (document.documentElement.clientHeight)
    {
	browserWidth =  document.documentElement.clientWidth;
	browserHeight = document.documentElement.clientHeight;
	}
	else
    {
		browserWidth =  document.body.clientWidth;
		browserHeight = document.body.clientHeight;
	}
	
	if (document.documentElement.scrollLeft)
    {
		// Old IE?
		scrollX = document.documentElement.scrollLeft;
	    scrollY = document.documentElement.scrollTop;
    }
	else
    {
		// IE 6, Opera
		scrollX = document.body.parentElement.scrollLeft;
		scrollY = document.body.parentElement.scrollTop;
	}

  } else {
	// Mozilla (Firefox, etc)
	scrollX =  window.pageXOffset;
	scrollY = window.pageYOffset;
    browserWidth = window.innerWidth;
    browserHeight = window.innerHeight;
  }

  // Decide where to pop box
  // If on left, pop right
  sideSpace = x - scrollX + 20;
  halfWidth = browserWidth/2;
//  alert('Browser: ' + browserWidth + ', Half: ' + halfWidth + ', xPos: ' + sideSpace);

  if (sideSpace <= halfWidth)
  {
	x = x + xOffset;
	bubblepos = "right";
  }
  else
  {
	// Else we have to set the left side of the box far left so it places right of calling object
	x = x + xOffset - objWidth;
	bubblepos = "left";
  }

  // Calculate space above/below the popup box
  topSpace = (y - scrollY);
  bottomSpace = browserHeight - (topSpace + objHeight);
  
  // If there's more room above, pop there
  if ((topSpace >= objHeight) || (bottomSpace < objHeight))
  {
	y = y - yOffset - objHeight-20;
	while(nextS.nodeType!=1)
	{
		nextS=nextS.nextSibling;
	}
	nextS.style.top = "0px";
	if (bubblepos == "left")
	{
		nextS.style.left = "-22px";
	}
	else
	{
		nextS.style.left = "0px";
    }


	// Now get the bubble pointer
	nextS=nextS.nextSibling;
	while(nextS.nodeType!=1)
	{
		nextS=nextS.nextSibling;
	}

	if (bubblepos == "left")
	{
		nextS.style.backgroundImage = "url('http://www.startco.ca/images/bubble-up-left.gif')";
		nextS.style.top = (objHeight-29) + 'px';
		nextS.style.left = (objWidth-21) + 'px'; 
	}
	else
	{
		nextS.style.backgroundImage = "url('http://www.startco.ca/images/bubble-up-right.gif')";
		nextS.style.top = (objHeight-29) + 'px';
		nextS.style.left = "0px"; 

	}
  }

  else
  {
	// Pop below
	y = y + callerHeight + yOffset;
	while(nextS.nodeType!=1)
	{
		nextS=nextS.nextSibling;
	}

	nextS.style.top = "49px";
	if (bubblepos == "left")
	{
		nextS.style.left = "-22px";
	}
	else
	{
		nextS.style.left = "0px";
    }

	// Now get the bubble pointer
	nextS=nextS.nextSibling;
	while(nextS.nodeType!=1)
	{
		nextS=nextS.nextSibling;
	}

	//Position bubble pointer to be on top of box
	if (bubblepos == "left")
	{
		nextS.style.backgroundImage = "url('http://www.startco.ca/images/bubble-down-left.gif')";
		nextS.style.left = (objWidth-21) + 'px'; 
		nextS.style.top = "0px";		
	}

	else
	{
		nextS.style.backgroundImage = "url('http://www.startco.ca/images/bubble-down-right.gif')";
		nextS.style.left = "0px"; 
		nextS.style.top = "0px";	
	}

  }

  // Check where we are relative to the window  
  if (x < 0){x = 0}
  if (y < 0){y = 0}

  // step 5
  obj.style.top  = (y) + 'px';
  obj.style.left = (x) + 'px';

}

// Start the timers to show the box or if shown, clear the timer to hide it
// Also decides where the box should be drawn. If there is room above the 
// hovered item, it will appear there, otherwise, below. Likewise, if on the 
// left side of the screen, it will be offset to the right and if on the right
// offset to the left.
function showBox(id, e)
{

	// Old browser compatibility (new DOM uses getElement)
	if (document.getElementById) 
		thisObj = document.getElementById(id);
	else if (document.layers) 
		thisObj = document.layers[id];
	else if (document.all) 
		thisObj = document.all[id];
    else
		return;

	// New object being hovered?
	if (thisObj != lastObj)
	{
		if (lastObj == null)
			lastObj = thisObj;
		
		// Set co-ordinates of new div here
		moveObject(thisObj, e);

		// If already showing a popup, no time delay
		if (lastObj.style.display == "block")
		{
			thisObj.style.display = "block";
			lastObj.style.display = "none";
			window.clearTimeout(timeout);
		}
		else
		{
			timeout = window.setTimeout("thisObj.style.display='block';", 500);
		}

	}

	//Regaining focus on same object
	else
	{
		if (thisObj.style.display == "block")
			window.clearTimeout(timeout);
		else
			timeout = window.setTimeout("thisObj.style.display='block';", 500);	
	}
}

function showBoxNow(id, e)
{

	// Old browser compatibility (new DOM uses getElement)
	if (document.getElementById) 
		thisObj = document.getElementById(id);
	else if (document.layers) 
		thisObj = document.layers[id];
	else if (document.all) 
		thisObj = document.all[id];
    else
		return;

	// New object being hovered?
	if (thisObj != lastObj)
	{
		if (lastObj == null)
			lastObj = thisObj;
		
		// Set co-ordinates of new div here
		moveObject(thisObj, e);

		// If already showing a popup, no time delay
		if (lastObj.style.display == "block")
		{
			thisObj.style.display = "block";
			lastObj.style.display = "none";
			window.clearTimeout(timeout);
		}
		else
		{
			timeout = window.setTimeout("thisObj.style.display='block';", 0);
		}

	}

	//Regaining focus on same object
	else
	{
		if (thisObj.style.display == "block")
			window.clearTimeout(timeout);
		else
			timeout = window.setTimeout("thisObj.style.display='block';", 0);	
	}
}


// Start the timers to hide the box or if hidden already, to clear the show timer
function hideBox(id)
{
	// Old browser compatibility (new DOM uses getElement)
	if (document.layers) 
		thisObj = document.layers[id];
	else if (document.all) 
		thisObj = document.all[id];
	else if (document.getElementById) 
		thisObj = document.getElementById(id);

	if (thisObj.style.display == "none")
		window.clearTimeout(timeout);
	else
		timeout = window.setTimeout("doHide(thisObj);", 800);	

	lastObj = thisObj;
	
}

// This function just hides the popup and also clears the last object so that
// if the same popup is reopened, the position is recaculated.
function doHide(obj)
{
	obj.style.display='none';
	lastObj = null;
}

//-->