var tab_order = ['catalogue','google_scholar'];
var tab_text = ["Search Catalogue","Google Scholar"];

var tabList = [];
tabList.push(new tab('catalogue','li_cat','a_cat'));
tabList.push(new tab('google_scholar','li_gs','a_gs'));

function tab(divName, liName, aName){
	this.theDiv = divName;
	this.theLI  = liName;
	this.theA   = aName;

	this.div_name = function(){
		return this.theDiv;
	}
	this.li_name = function(){	
		return this.theLI;
	}
	this.a_name = function(){
		return this.theA;
	}
}
    
function switch2(which){
  var tabs = $('tabs').getElementsByTagName('li');
  if (tabs != null){
    for (var x=0; x< tabs.length; x++){
      var y = x-1;
      do {
        y++;
        var tOrder = tab_order[y];
        var tText = tab_text[y];
        var tmp = $(tab_order[y]);
      } while (tmp   == null && y < tab_order.length);
      if (tabs[x].className != 'inactive'){
        var tmpA = new Element('a');        
				if (tOrder == which){
          tabs[x].className = 'selected';
        } else {
          if (document.all){
            tmpA.href = 'javascript://';
            tmpA.id = 'ctl_' + tOrder;
            tmpA.onclick = function(){ var tmpID = this.id.replace('ctl_','');  switch2(tmpID);}
          } else {
            tmpA.setAttribute('href','javascript://');
            tmpA.setAttribute('onclick','switch2(\'' + tOrder + '\');');
          }
          tabs[x].className = '';
        }
        tmpA.appendChild(document.createTextNode(tText));
        tabs[x].innerHTML = '';
        tabs[x].appendChild(tmpA);
      }
    }
  }
  for (x=0;x<tab_order.length;x++){
    var blockStyle;
    if (tab_order[x] == which)
        blockStyle = 'block';
    else
        blockStyle = 'none';

    var tmpDiv = $(tab_order[x]);

    if (tmpDiv != null)
        $(tmpDiv).setStyle({'display' : blockStyle});

  }
  //adjustHeight();
  fixUnderflow();
  setLogoPos();
}

function switchTab(theEvent){
	var which = theEvent.id;

	for (var foo=0; foo<tabList.length; foo++){
		if (tabList[foo].a_name() == which){
			$(tabList[foo].div_name()).setStyle({'display':'block'});
			(document.all) ? $(tabList[foo].li_name()).className = 'selected' : $(tabList[foo].li_name()).setAttribute('class','selected');
			$(tabList[foo].a_name()).stopObserving('click');
		} else {
			$(tabList[foo].div_name()).setStyle({'display':'none'});
			(document.all) ? $(tabList[foo].li_name()).className = '' : $(tabList[foo].li_name()).removeAttribute('class');
      $(tabList[foo].a_name()).observe('click',function(event) { switchTab(this);});
    }
	}
}	
	

function selectMenu(theA){
	if (theA.parentNode != null)
		$(theA.parentNode).addClassName('hover');
}

function unselectMenu(theA){
	if (theA.parentNode != null)
		$(theA.parentNode).removeClassName('hover');
}

function doMenu(){
	if ($('myLeftNav') != null){
		var currLoc = location.href;
		if (!document.all)
			currLoc = currLoc.replace(/^http:\/\/[a-z\.]+\//,'/');
		var theLI = $('myLeftNav').getElementsByTagName('LI');
		if (theLI != null){
			for (var foo=0;foo<theLI.length;foo++){
				var theA = theLI[foo].getElementsByTagName('A');
				if (theA[0] != null){
					theA = theA[0];
					var tempLoc = theA.getAttribute('href');
					if (document.all)
						tempLoc = theA.href;
					if (currLoc == tempLoc){
							$(theLI[foo]).addClassName('selected');
							theA.onmouseover = null;
							theA.onmouseout = null;
					} else {
							$(theLI[foo]).removeClassName('selected');
							theA.onmouseover = function(){ selectMenu(this);}
							theA.onmouseout = function(){ unselectMenu(this);}
					}
				}
			}
		}
	} // if leftNav
}

function fixPHPLive(){
	var theDiv = $('#phpLive');
	if (theDiv != null){
		var theImg = theDiv.getElementsByTagName('IMG')[0];
		if (theImg != null)
			$(theImg).setStyle({'height': '91px', 'width':'150px'});
	}
}
		


