// ------------------------------------------ Executed code ------------------------------------------

// Execute Browser detection script

if (is.nav4) {
	parentdoc = "parent.document.";
	parentsty = "";
	doc = "document.";
	sty = "";
	htm = ".document"
	nav4 = 1
} else if(is.ie4up) {
	parentdoc = "document.all.";
	parentsty = ".style";
	doc = "document.all.";
	sty = ".style";
	htm = ""
	nav4 = 0
} else if(is.nav5up) {
	parentdoc = "document.all.";
	parentsty = ".style";
	doc = "document.all.";
	sty = ".style";
	htm = ""
	nav4 = 0
}

// Define timeout to overcome PC Navigator 4 - 4.08 reload/resize loop
var beenopen = 0;
setTimeout('beenopen = 1', 15000);


// Capture window resize events to handle Navigator
window.onresize = BZ_handleResize;

// ---------------------------------------- Generic Functions ----------------------------------------

// Two functions to fix navigator redraw problem
function BZ_handleResize() {
	if (is.nav4) {
		if ((!((this.minor>=3.9) && (this.minor<=4.1))) || (beenopen==1)){
			location.reload()
		} 
	} else {
		BZC_OnLoadResize();
	}
}


//function to load new content into an IFRAME in explorer or ILAYER in netscape
function BZ_switchFrame(name,url){
	eval(parentdoc + name).src=url;
	}
	

function BZ_stealMM_swapImgArray() { // Call this when you want to steal or add stolen elements from document.MM_sr
  if (document.BZ_stolen_MM_sr) {
    document.BZ_stolen_MM_sr=document.MM_sr.concat(document.BZ_stolen_MM_sr);
  } else {
    document.BZ_stolen_MM_sr=document.MM_sr;
  }
  document.MM_sr=new Array;
}

function BZ_returnMM_swapImgArray() { // Call this when you want to return the contents of the stolen arrays and throw away any contents of document.MM_sr DANGEROUS!
  if (document.BZ_stolen_MM_sr) {
    document.MM_sr=document.BZ_stolen_MM_sr;
    document.BZ_stolen_MM_sr=new Array;
  }
}

function BZ_switchMM_swapImgArray() { // Call this when you want to switch the contents of the two arrays.
  if (document.BZ_stolen_MM_sr) {
    temp = document.BZ_stolen_MM_sr;
    document.BZ_stolen_MM_sr=document.MM_sr;
    document.MM_sr = temp;
  } else {
    BZ_stealMM_swapImgArray();
  }
}

// Functions to get X & Y positions of images
function BZ_getAbsImageX(imgObj) {
  if (is.nav4) {
    return eval(imgObj).x;
  } else {
	xPos = eval(imgObj).offsetLeft;
	temp = eval(imgObj).offsetParent;
  	while (temp != null) {
  		xPos += temp.offsetLeft;
  		temp = temp.offsetParent;
  	}
    return xPos;
  }
}

function BZ_getAbsImageY(imgObj) {
  if (is.nav4) {
    return eval(imgObj).y;
  } else {
	yPos = eval(imgObj).offsetTop;
	temp = eval(imgObj).offsetParent;
	while (temp != null) {
  		yPos += temp.offsetTop;
  		temp = temp.offsetParent;
  	}
    return yPos;
  }
}

function BZ_layerVisibility() { // Call this to change the visibility of a layer
  for (var i=0; i<BZ_layerVisibility.arguments.length; i+=2) {
    if (document.getElementById) { // DOM1 Test
      document.getElementById(BZ_layerVisibility.arguments[i]).style.visibility=BZ_layerVisibility.arguments[i+1];
    } else {
      eval(parentdoc+BZ_layerVisibility.arguments[i]+parentsty).visibility = BZ_layerVisibility.arguments[i+1];
    }
  }
}

// Move an object horizontally based on Main Layer
function BZ_setLayerPosition(layername, x, y) {
  if(document.getElementById) {
    var obj = document.getElementById(layername).style;
    var contentObj = document.getElementById(layername);
  } else {
    var obj = eval(parentdoc+layername+parentsty);
    var contentObj = eval(doc+layername);
  }
  BZ_shiftTo(obj, x, y);
}

// Position and element at specific location
function BZ_shiftTo(obj, x, y) {
	if (is.nav4) {
		obj.moveTo(x,y)
	} else if (document.getElementById) {
		obj.left = x + 'px';
		obj.top = y + 'px';
	} else {
		obj.pixelLeft = x
		obj.pixelTop = y
	}
}

function BZ_setLayerOffImage(imageName, layerName, offX, offY, visibility) { // visible or hidden
  var imgObj = document.images[imageName];
  BZ_setLayerPosition(layerName, BZ_getAbsImageX(imgObj)+offX, BZ_getAbsImageY(imgObj)+offY);
  BZ_layerVisibility(layerName, visibility);
}

// ---------------------------------------- Custom Functions -----------------------------------------

function BZC_MenusOff() {
  BZ_layerVisibility('corporatemenu','hidden','productsservicesmenu','hidden','divisionsmenu','hidden','technologiesmenu','hidden','triggermenu','hidden');
}

function BZ_scrollBox(nextElement, setOffImg, OffsetX, OffsetY, frequency, counter, scrollheight, pause) {
// caffeine induced hack
// but it works... nasty browser switching code. spaghetti...
// grabbing the obj references every iteration, but it doesn't seem slow at all.
  var imgObj = document.images[setOffImg];
  // IE 4.0+ & All DOM Capable Browsers
  if (document.getElementById || document.all) {
    if (counter == 0) {
      if (document.getElementById) {
        var topObj = document.getElementById('newsElementOne').style;
        var topTextObj = document.getElementById('newsHeadlineOne');
        var botObj = document.getElementById('newsElementTwo').style;
        var botTextObj = document.getElementById('newsHeadlineTwo');
      } else {
        // for IE 4.0 < 5.0
        var topObj = document.all.newsElementOne.style;
        var topTextObj = document.all.newsHeadlineOne;
        var botObj = document.all.newsElementTwo.style;
        var botTextObj = document.all.newsHeadlineTwo;
      }
    } else {
      if (document.getElementById) {
        var topObj = document.getElementById('newsElementTwo').style;
        var topTextObj = document.getElementById('newsHeadlineTwo');
        var botObj = document.getElementById('newsElementOne').style;
        var botTextObj = document.getElementById('newsHeadlineOne');
      } else {
        // for IE 4.0 < 5.0
        var topObj = document.all.newsElementTwo.style;
        var topTextObj = document.all.newsHeadlineTwo;
        var botObj = document.all.newsElementOne.style;
        var botTextObj = document.all.newsHeadlineOne;
      }
    }
    // spaghetti copy and paste - identical code is used in NS branch
    if (nextElement != 0) { 
      topTextObj.innerHTML = paneDataArr[nextElement-1]; 
    } else { 
      topTextObj.innerHTML = paneDataArr[paneDataArr.length-1];
    }
    botTextObj.innerHTML = paneDataArr[nextElement];
    // end spaghetti
    topObj.clip = "rect(" + counter + "px " + parseInt(topObj.width) + "px " + scrollheight + "px 0px)";
    topObj.left = (BZ_getAbsImageX(imgObj) + OffsetX) + 'px';
    topObj.top = (BZ_getAbsImageY(imgObj) + OffsetY) - counter + 'px';
    botObj.clip = "rect( 0px " + parseInt(botObj.width) + "px " + (counter) + "px 0px)";
    botObj.left = (BZ_getAbsImageX(imgObj) + OffsetX) + 'px';
    botObj.top = ((BZ_getAbsImageY(imgObj) + OffsetY) - counter + scrollheight) + 'px';
  }
  // Netscape 4.0 to 4.7x Specific Code
  else if (document.layers) {
/*
    if (counter == 0) {
      topObj = document.newsElementOne;
      botObj = document.newsElementTwo;
      topTextObj = 'newsHeadlineOne';
      botTextObj = 'newsHeadlineTwo';
    } else {
      botObj = document.newsElementOne;
      topObj = document.newsElementTwo;
      botTextObj = 'newsHeadlineOne';
      topTextObj = 'newsHeadlineTwo';
    }
	alert(document.newsElementOne.document.newsHeadlineOne);
    if (nextElement != 0) { 
      with (document[topTextObj].document) {
        open();
        write(paneDataArr[nextElement-1]);
        close();
      }
    } else { 
      with (document[topTextObj].document) {
        open();
        write(paneDataArr[paneDataArr.length-1]);
        close();
      }
    }
    with (document[botTextObj].document) {
        open();
        write(paneDataArr[nextElement]);
        close();
    }
*/
    if (counter == 0) {
      topObj = document.newsElementOne;
      botObj = document.newsElementTwo;
//      topTextObj = document.newsElementOne.document.newsHeadlineOne;
//      botTextObj = document.newsElementTwo.document.newsHeadlineTwo;
    } else {
      botObj = document.newsElementOne;
      topObj = document.newsElementTwo;
//      botTextObj = document.newsElementOne.document.newsHeadlineOne;
//      topTextObj = document.newsElementTwo.document.newsHeadlineTwo;
    }
    if (nextElement != 0) { 
      with (topObj.document) {
        open();
        write('<span class="newsline">'+paneDataArr[nextElement-1]+'</span>');
        close();
      }
    } else { 
      with (topObj.document) {
        open();
        write('<span class="newsline">'+paneDataArr[paneDataArr.length-1]+'</span>');
        close();
      }
    }
    with (botObj.document) {
        open();
        write('<span class="newsline">'+paneDataArr[nextElement]+'</span>');
        close();
    }
/*
    if (nextElement != 0) { 
      topObj.innerText = paneDataArr[paneDataArr.length-1];
    } else { 
      topObj.innerText = paneDataArr[paneDataArr.length-1];
    }
      botObj.innerText = paneDataArr[nextElement];
*/
    topObj.clip.top = counter;
    topObj.clip.right = 130;
    topObj.clip.bottom = scrollheight;
    topObj.clip.left = 0;
    topObj.left = (BZ_getAbsImageX(imgObj) + OffsetX);
    topObj.top = (BZ_getAbsImageY(imgObj) + OffsetY) - counter;
    botObj.clip.top = 0;
    botObj.clip.right = 130;
    botObj.clip.bottom = counter;
    botObj.clip.left = 0;
    botObj.left = (BZ_getAbsImageX(imgObj) + OffsetX);
    botObj.top = ((BZ_getAbsImageY(imgObj) + OffsetY) - counter + scrollheight);
  }
// used by all branches
  // only fires on the last iteration, when counter has reached the scrollheight
  if (counter == scrollheight) { 
    // reduces calls to visible style setting, not much help for blink by calling it here.
    topObj.visibility = 'visible';
    botObj.visibility = 'visible';
    // reset the loop parameters
    thisfrequency = frequency+pause;
    counter = 0;
    (nextElement+1 < paneDataArr.length) ? nextElement++ : nextElement = 0;
// all iterations but the final before pausing
  } else { 
    thisfrequency = frequency; 
    counter = counter + 2; 
  }
  // call the next iteration with a delay
  setTimeout("BZ_scrollBox(" + nextElement +",'" + setOffImg + "'," + OffsetX + "," + OffsetY + "," + frequency + "," + counter + "," + scrollheight + "," + pause + ")", thisfrequency);
}

