//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1,'features']

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes
if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontainer{display: none;}\n</style>')

//Set CSS to hide the tabs - sets items with a class of 'tabcontent' to display: none
var hidetabs=1 //0 for no (default), 1 for yes
if (hidetabs==1)
document.write('<style type="text/css">\n.tabcontent{display: none;}\n</style>')

var cookiename = 'tabnav';

var previoustab=""

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function expandcontent(cid, aobject)
{
    if (document.getElementById){
        createCookie(cookiename, cid, 1);
        highlighttab(aobject);
        if (turntosingle==0){
            if (previoustab!="")
            document.getElementById(previoustab).style.display="none"
            document.getElementById(cid).style.display="block"
            previoustab=cid
        }
    }
}

function highlighttab(aobject){
	//alert(aobject);
    if (typeof tabobjlinks=="undefined")
    {
        collecttablinks()
    }
    for (i=0; i<tabobjlinks.length; i++) {
        tabobjlinks[i].className=""
    }
    aobject.className="current"
}

function collecttablinks(){
var tabobj=document.getElementById("tabs")
tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
    collecttablinks()
    // This gets the first element
    // in the subnavcontainer
    var content=document.getElementById("tabcontainer");
    cdiv=content.getElementsByTagName("div");

    var cookievalue = readCookie(cookiename);
    var tablink = document.getElementById(cookievalue+'-link');
    if(cookievalue && tablink) {
        var tablink = document.getElementById(cookievalue+'-link');
        expandcontent(cookievalue, tablink);
    } else {
        expandcontent(cdiv[0].id, tabobjlinks[initialtab[0]-1]);
    }
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload
