//sets the position of a layer relitive to an object
function setPosition(object, refObj)
{
  ofsetX = ((object.clientWidth/2)-(refObj.clientWidth/2)) -15;
  ofsetY = (refObj.clientHeight/3)*-2;

  if(refObj.offsetParent)
  {
    curleft= refObj.offsetLeft;
    curtop = refObj.offsetTop;

    while(refObj = refObj.offsetParent)
    {
      curleft += refObj.offsetLeft;
      curtop += refObj.offsetTop;
    }
  }

  if(navigator.userAgent.search("Firefox")>-1)
    object.style.left = (curleft-ofsetX)+"px";
  else
    object.style.left = (curleft-ofsetX-3)+"px";

  object.style.top = (curtop-ofsetY)+"px";
} //end setPosition


//sets the background to a png or gif if an old version of ie
ua = navigator.userAgent.toLowerCase()
isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
version = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
function setBackground(setObj, bkgFile)
{
  if (setObj != null && setObj != "")
  {
    //if on IE
    if (bkgFile.search(/.png$/i)>0 && isIE )
    {
      //if an older version of IE
      if (version >= 5.5)
      {
        setObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ bkgFile +"');"
        setObj.style.background = "none";
      }
      else
        setObj.style.backgroundImage = "url("+ bkgFile.substr(0,bkgFile.length-3) +"gif)";
    }
    else
    {
      setObj.style.backgroundImage = "url("+ bkgFile +")";
    }
  }
}

//fixes bad characters in text
function fixText(text)
{
  //fixes MS word characters
  text = text.replace(/â€™/g,"&rsquo;");
  text = text.replace(/â€”/g,'&mdash;');
  text = text.replace(/â€¦/g,'...');
  text = text.replace(/â€œ/g,'&ldquo;');
  text = text.replace(/â€/g,'&rdquo;');

  return text;
}

//when a face is moused over
function faceOver(ovEle)
{
  //set the display
  document.getElementById(ovEle.id).className += " hover";
  //gets the data object
  dataEle = meter.getById(ovEle.id);
    
  //set the bubble text properties
  dialogBox.display(dataEle,ovEle);
  hidePause = 1;
}

//when a face is moused out
function faceOut(otEle)
{
  orgClass = document.getElementById(otEle.id).className.split(" ");
  document.getElementById(otEle.id).className = orgClass[0];
  hidePause = 0;
}

//when a face is clicked
function faceClick(clEle)
{
  //gets the data object
  dataEle = meter.getById(clEle.id);
  dataEle.select();
  dialogBox.hide();
}

//hides the text popup
function hidePopup()
{
  dialogBox.hideCheck();
  setTimeout("hidePopup()",100);
}

//writes out the ratings
function printRatings(candName)
{
  document.write(getCurrentRating(candName));
  document.write(getPreviousRating(candName));
}

//gets the previous rating for use in the entries on the page
function getPreviousRating(candName)
{
  reading = meter.getById(candName).getNextRating();
  
  if (reading != "")
    return "<b>Previous Reading: "+ reading +"</b><br />";
  else return "";
}

//gets the current rating inthe que
function getCurrentRating(candName)
{
  return "<b>Current Reading: "+ meter.getById(candName).Rating[meter.getById(candName).RatingIndex] +"</b><br />";
}


//initializes everything
meter = new meterControl();
dialogBox = "";
function startUp()
{
  dialogBox = new textBox();
  hidePopup();
}

//for testing purpopses
function dsp(txt)
{
  document.getElementById("tst").innerHTML += txt +" ";
}