var menuLocked=0;
var itemLocked=0;
var index,ii,jj;
var mainPath='gifs/';
var first=true;

scrollHeight=new Array(3);
scrollHeight['pmgDesc']=0;
scrollHeight['pdsDesc']=0;
scrollHeight['pwsDesc']=0;
scrollHeight['announcement']=0;

menuList=new Array(3);
menuList[0]="pds";
menuList[1]="pmg";
menuList[2]="pws";

var announcement=null;
/*  instantiate javascript tools  */
var tools=new jsTools('tools');

function init(){
  announcement=new announce();
	setTimeout('showTab()',4000);
	// need this BS to reanimate the gif on reload in Safari...
  if (tools.browser=='Safari') {
		var obj=document.getElementById('pmgLogo');
		obj.src='gifs/splash/PMGAnimation.gif';
	}
}

function showTab() {
  if (!first) return;
	first=false;
	objTab=document.getElementById('tab');
	objTab.style.display="block";
	clearAllMenus();
	announcement.show();
}

function mouseOver(img) {
  var xPos='-' +img.offsetWidth +'px';
  // Firefox, Safari, IE 9+
  if (window.getComputedStyle) {
    yPos=window.getComputedStyle(img).backgroundPosition;
    yPos=yPos.substr(yPos.indexOf(' '));
    img.style.backgroundPosition=xPos + yPos;
  }
  // IE<9 supports backgrounPositionX and Y separately...
  if (img.currentStyle) img.style.backgroundPositionX=xPos;
  return;
}

function mouseOut(img) {
  // Firefox, Safari, IE 9+
  if (window.getComputedStyle) {
    yPos=window.getComputedStyle(img).backgroundPosition;
    yPos=yPos.substr(yPos.indexOf(' '));
    img.style.backgroundPosition='0px' +yPos;
  }
  // IE<9 supprts backgrounPositionX and Y separately...
  if (img.currentStyle) img.style.backgroundPositionX='0px';
  return;
}

function setMenuBar(barID) {
  if (menuLocked==barID) return;
  if (announcement.active) return;
  menuLocked=barID;
	clearAllMenus();
	var site=menuList[barID-1];
  var	obj=document.getElementById(site);
	obj.style.display="block";
	obj=document.getElementById(site+'Desc');
	setDesc(obj);
}

function clearAllMenus() {
	for (var ii=0; ii<3; ii++) {
		var site=menuList[ii];
		var obj=document.getElementById(site);
		obj.style.display="none";
		obj=document.getElementById(site+'Desc');
		obj.style.display="none";
	}
}

function setDesc(obj) {

	obj.style.visibility="hidden";
	obj.style.display="block";
	if (scrollHeight[obj.id]==0) scrollHeight[obj.id]=obj.offsetHeight;
  var xHeight=scrollHeight[obj.id];
  var xDuration=300;													// total duration [ms]
  var nSteps=10;															// number of steps
  var xRate=Math.floor(xDuration/nSteps);			// rate [ms/step]
  var xIncrement=Math.floor(xHeight/nSteps);	// increment [px/step]
  obj.style.height='0px';
	obj.style.visibility="visible";
  scrollDown(obj.id,xHeight,0,xRate,xIncrement);
}

function scrollDown(id,height,start,rate,increment) {
  var obj=document.getElementById(id);
  var style=obj.style;
	var xHeight=start + increment;
	if (xHeight>height) xHeight=height;
	style.height=xHeight+'px';
	style.padding='0px';
	if (xHeight<height) {
	  var fn='scrollDown("' + id +'",' + height + ',' +xHeight + ',' + rate + ',' + increment + ')';
    setTimeout(fn,rate);
	}
}

function announce(announceID){
  this.id=announceID;
  if (!this.id) this.id="announcement";
  this.obj=document.getElementById(this.id);
  if (!this.obj) return;
  this.active=false;

  this.show = function(){
    if (!this.obj) return;
    this.active=true;
    setDesc(this.obj);
  }
  this.hide = function(){
    if (!this.obj) return;
    this.obj.style.display="none";
    this.active=false;
  }
}

