// JavaScript Document

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function openWindow(theURL,winName,features)
{
    window.open(theURL,winName,features);
}

// the <div> containers

// - "mainnav" (nav itself)

// - "DivBottom" (bottom of the "mainnav", to calculate nav height)

// - "footer"

// must be declared as position:relative/absolute, so that findPos() can calculate

// their absolute position.

// The minimum pos is declared hard-coded (feel free to change that).



function findPos(objId) {

    var obj     = findObj(objId);

	var curleft = curtop = 0;

	if (!obj) {

	   throw "object with id " + objId + " does not exist in this document";

	}

	if (obj.offsetParent) {

		do {

			curleft += obj.offsetLeft;

			curtop  += obj.offsetTop;

		} while (obj = obj.offsetParent);

	}

	return [curleft, curtop];

}



function findObj(objId) {

    return document.getElementById(objId);

}



function findScrollY() {

    var sp = document.body.parentNode.scrollTop;

    if (sp == 0) sp = document.body.scrollTop;

    return sp;

}



function autoscroll() {

    var mainnav     = findPos("mainnav");

    var divbottom   = findPos("DivBottom");

    var footer      = findPos("footer");

    var navHeight   = divbottom[1] - mainnav[1];

    //alert(navHeight);

    var minPosY     = 156; // top banner height

    var maxPosY     = footer[1] - navHeight;

    var scrollY     = findScrollY();

    //alert(scrollY + "\n" + contentwrap);

    var navObj      = findObj("mainnav");

    if (scrollY > minPosY) {

	    var newPosY     = Math.min(maxPosY, scrollY - minPosY) + "px";

	    //alert(navObj + "\n" + newPosY);

	    navObj.style.top = newPosY;

    } else {

        findObj("mainnav").style.top = 0 + "px";

    }

}



function autoscrollInit() {

    window.onscroll = autoscroll;

}

var interval = 0;

function docId(id) { return document.getElementById(id); }
function docStyle(id) { return docId(id).style; }

var categories = [];
function toggleCategory(id) {
  if(categories.length == 0) {
    var divs = document.getElementsByTagName("div");
    for (i = 0; i < divs.length; i++)
      if (divs[i].className == "section2") categories.push(divs[i].id);
  }
  for (i = 0; i < categories.length; i++) {
    if (categories[i] != id) { 
      if (docStyle(categories[i] + "subcategory").display == "inline") {
        docStyle(categories[i]).background = "url(../img/btn_plus.gif) no-repeat";
        // docStyle(newscategories[i] + "link").color = "";
        docStyle(categories[i] + "subcategory").display = "none";
      }
    }  
  }
  if (docStyle(id + "subcategory").display != "inline") {
    docStyle(id + "subcategory").display = "inline";
    // docStyle(id + "link").color = "#0019a8";
    docStyle(id).background = "url(../img/btn_minus.gif) no-repeat";
  } else {
    docStyle(id + "subcategory").display = "none";
    // docStyle(id + "link").color = "";
    docStyle(id).background = "url(../img/btn_plus.gif) no-repeat";
  }
}
