////////////////////////////////////////////////
// mechanism for doing multiple things at onload
////////////////////////////////////////////////

var timerID = "";
var initString = new Array();

// the final initialization for a page
function finalInit()
{
  var temp = 0;
  temp = initString.length;
  if (temp)
  {
    for (i = 0; i < temp; i++)
    {
      eval(popInit());
    }
  }
}

// remember statements to be executed at final initialization
function pushInit(what)
{
  initString[initString.length] = what;
}

// read statements to be executed
function popInit()
{
  temp = initString[initString.length-1];
  initString.length--;
  return temp;
}

////////////////////////////////////
// functions for manipulating layers
////////////////////////////////////

// a function that does nothing
function doNothing() {}

// a browser check object
function lib_bwcheck()
{
  this.ver=navigator.appVersion;
  this.agent=navigator.userAgent;
  this.dom=document.getElementById?1:0;
  this.opera5=this.agent.indexOf("Opera 5")>-1;
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6;
  this.mac=this.agent.indexOf("Mac")>-1;
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
  return this;
}
var bw=new lib_bwcheck();

// function to initialize the bookmark marquee
function initBookmark()
{
  // initializes the position and the clipping of the marquee
  if (bw.ie || bw.dom)
  {
    cross_marquee = document.getElementById ? document.getElementById("iemarquee") : document.all.iemarquee;
    cross_marquee.style.top = "0px";
    cross_marquee.innerHTML = marqueecontent;
    actualheight = cross_marquee.offsetHeight;
  }
  else if (bw.ns4)
  {
    ns_marquee = document.ns_marquee.document.ns_marquee2;
    ns_marquee.top = 0;
    ns_marquee.document.write(marqueecontent);
    ns_marquee.document.close();
    actualheight = ns_marquee.document.height;
  }
}

// scroll the bookmark marquee
function scrollmarquee(dir)
{
  if (bw.ie || bw.dom)
  {
    if (dir > 0 && (parseInt(cross_marquee.style.top) > (actualheight * (-1) + 120)))
      cross_marquee.style.top = parseInt(cross_marquee.style.top) - (dir) * marqueespeed + "px";
    else if (dir < 0 && (parseInt(cross_marquee.style.top) <= 0))
      cross_marquee.style.top = parseInt(cross_marquee.style.top) - (dir) * marqueespeed + "px";
    gTimer = setTimeout('scrollmarquee(' + dir + ')',50);
  }
  else if (bw.ns4)
  {
    if (dir > 0 && (ns_marquee.top > (actualheight * (-1) + 120)))
      ns_marquee.top -= (dir) * marqueespeed;
    else if (dir < 0 && (ns_marquee.top <= 0))
      ns_marquee.top -= (dir) * marqueespeed;
    gTimer = setTimeout('scrollmarquee(' + dir + ')',50)
  }
}

// function for moving layers
px = bw.ns4 || window.opera ? "" : "px";
function b_moveIt(x,y)
{
  this.x = x;
  this.y = y;
  this.css.left = this.x+px;
  this.css.top = this.y+px;
}

// start scrolling the requested scroll
function scroll(dir)
{
  gIsScrollLooping = true;
  if (gIsScrollLooping) gTimer = setTimeout('scrollmarquee(' + dir + ')',50)
}

// stop scrolling
function noScroll()
{
  clearTimeout(gTimer);
  gIsScrollLooping = false;
}

//////////////////////////////////
// site section-specific functions
//////////////////////////////////

// function for the catalogue search to switch to other result page
function turnToPage(page)
{
  document.theForm.cp.value = page;
  document.theForm.submit();
}

/////////////////////////
// flash detection script
/////////////////////////

var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var maxVersion = 6;             // highest version we can actually detect
version = 0;                    // actual version we have, start from zero, detection will make number go up

if (navigator.plugins)
{
  // ...then check for flash 2 or flash 3+.
  if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])
  {
    var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
    var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
    var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
    flash2Installed = flashVersion == 2;
    flash3Installed = flashVersion == 3;
    flash4Installed = flashVersion == 4;
    flash5Installed = flashVersion == 5;
    flash6Installed = flashVersion >= 6;
  }
}

var isNS4 = (document.layers) ? true : false;
var isNS6 = (document.getElementById) ? true : false;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if (isIE && isWin)
{
  document.write('<SCR' + 'IPT LANGUAGE="VBScript"\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

for (var i = 2; i <= maxVersion; i++)
{
  if (eval("flash" + i + "Installed") == true) version = i;
}

////////////////
// popup windows
////////////////

// generic for popup windows
function popupWin(url,w,h,wname,x,y) {
	w = w || 640
	h = h || 400
	x = x || (window.screen.width - w) / 2
	y = y || (window.screen.height - h) / 2
	__win=window.open(url,wname,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,screenX='+x+',screenY='+y+',top='+y+',left='+x+',resizable=1,width='+w+',height='+h)
	setTimeout('__win.focus()', 500)
}

function popupWinScroll(url,w,h,scrollbar,wname,x,y) {
	w = w || 640
	h = h || 400
	x = x || (window.screen.width - w) / 2
	y = y || (window.screen.height - h) / 2
	scrollbar= scrollbar || 0
	__win=window.open(url,wname,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scrollbar+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',resizable=1,width='+w+',height='+h)
	setTimeout('__win.focus()', 500)
}

function popupWinPPDiscussion(url,w,h,wname,x,y) {
	w = w || 640
	h = h || 400
	x = x || (window.screen.width - w) / 2
	y = y || (window.screen.height - h) / 2
	return window.open(url,wname,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,screenX='+x+',screenY='+y+',top='+y+',left='+x+',resizable=1,width='+w+',height='+h)
}

function sage_ev() {} // workaround after not using SAGE
