// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

var MM_FlashCanPlay = checkFlash();
var checkFlashCookieDomain='.example.com'

function menuHandler(mnu){
  if(document.getElementById){
    window.location = mnu.options[mnu.options.selectedIndex].value;
  }
}


function checkFlash(){
  var MM_contentVersion = 6;
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if (plugin) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i)
    {
      if (isNaN(parseInt(words[i])))
      continue;
      var MM_PluginVersion = words[i]; 
    }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
  }
  else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
    && (navigator.appVersion.indexOf("Win") != -1)) {
    oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + MM_contentVersion + "');");
    if(oFlash) { MM_FlashCanPlay = true; }
  }

  expires = new Date();
  expires.setFullYear(expires.getFullYear()+1);
  if(window.location.search == "?noflash=1"){ 
  	MM_FlashCanPlay = 0; 
  	// set no flash cookie
  	document.cookie="flash=0; expires="+ expires.toGMTString() +"; domain="+ checkFlashCookieDomain
  }
  else if(window.location.search == "?noflash=0" || window.location.search == "?flash=1"){
  	document.cookie="flash=1; expires="+ expires.toGMTString() +"; domain="+ checkFlashCookieDomain
  }
  else {
  	var c 	= document.cookie;
  	var pos = c.indexOf("flash=");
  	if(pos != -1){
  		var start = pos + 6;
  		var end   = c.indexOf(";",start);
  		if (end == -1){ end = c.length; }
  		var val = c.substring(start,end);
  		
  		if(val == "0"){
  			MM_FlashCanPlay = 0;
  		}
  	}
  }
  return MM_FlashCanPlay;
}

function addEventToElement(elem,func,event){
  if(typeof elem != "object"){ return false; }
  if(typeof func != "function"){ return false; }
  
  if(typeof event == "object"){
    for(var i=0;i<event.length;i++){ addEventToElem(elem,func,event[i]); }
  }
  else if(typeof event == "string") {
    var elemEvent = eval("elem."+ event);
    var old = elemEvent;
    if (typeof elemEvent != 'function') { elemEvent = func; } 
    else {
      elemEvent = function() {
        old();
        func();
      }
    }

    switch(event){
    case "onload":
      elem.onload=elemEvent;
      break;
    case "onchange":
      elem.onchange=elemEvent;
      break;
    case "onfocus":
      elem.onfocus=elemEvent;
      break;
    case "onblur":
      elem.onblur=elemEvent;
      break;
    case "onclick":
      elem.onclick=elemEvent;
      break;
    case "onmouseover":
      elem.onmouseover=elemEvent;
      break;
    case "onmouseout":
      elem.onmouseout=elemEvent;
      break;
    }
  }
}

var PNMGFlash=new Array();
function Flash(file,width,height,div,image,flashCanPlay){
  this.file = file;
  this.width = width;
  this.height = height;
  this.div = div;
  this.image = image;
  this.flashCanPlay = flashCanPlay;
  
  if(this.flashCanPlay){ this.register(); }
}
Flash.prototype.getObject = function(){
  return '<object type="application/x-shockwave-flash" data="'+ this.file +'" width="'+ this.width +'" height="'+ this.height +'">'+
    '<param name="movie" value="'+ this.file +'" /></object>';
}
Flash.prototype.register = function(){
  if(addLoadEvent){
    PNMGFlash[PNMGFlash.length]=this;
  }
  else { alert("PNMGFlash error: Could not show the flash because the function addLoadEvent() does not exist."); }
}
Flash.prototype.show = function(){
  if(document.getElementById){
    var e = document.getElementById(this.div);
    if(e){
      if(document.getElementById(this.image)){
        document.getElementById(this.image).className='printOnly';
        h=e.innerHTML + this.getObject();
        e.innerHTML='';
        e.innerHTML=h;
      }
      else { alert("PNMGFlash error: The image '"+ this.image +"' does not exist."); }
    }
    else { alert("PNMGFlash error: The flash div '"+ this.div +"' does not exist.");  }
  }
}
addLoadEvent(function(){
  for(var i=0;i<PNMGFlash.length;i++){
    PNMGFlash[i].show();
  }
});

//Fancy text scrolling script
var visible = 'visible';
var hidden = 'hidden';
var layerRef = '';
var styleRef = '';

if (navigator.appName == "Netscape"){
  visible = 'show';
  hidden = 'hide';
  layerRef = '.layers';
  styleRef = '';
}
else {
  visible = 'visible';
  hidden = 'hidden';
  layerRef = '.all';
  styleRef = '.style';
}

// begin absolutely positioned scrollable area object scripts

function verifyCompatibleBrowser(){
  this.ver=navigator.appVersion
  this.dom=document.getElementById?1:0
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
  this.ie4=(document.all && !this.dom)?1:0;
  this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
  return this
}

bw=new verifyCompatibleBrowser()
var speed=50
var loop, timer;

function ConstructObject(obj,nest){
  if(obj && document.getElementById(obj)){
    nest=(!nest) ? '':'document.'+nest+'.'
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
    this.up=MoveAreaUp;this.down=MoveAreaDown;
    this.MoveArea=MoveArea; this.x; this.y;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this;
  }
}

function MoveArea(x,y){
  this.x=x;this.y=y
  this.css.left=this.x +"px"
  this.css.top=this.y +"px"
}

function MoveAreaDown(move){
  if(this.y>-this.scrollHeight+objContainer.clipHeight){
    this.MoveArea(0,this.y-move)
    if(loop){ setTimeout(this.obj+".down("+move+")",speed) }
  }
}

function MoveAreaUp(move){
  if(this.y<0){
    this.MoveArea(0,this.y-move)
    if(loop){ setTimeout(this.obj+".up("+move+")",speed) }
  }
}

function PerformScroll(speed){
  if(initialised){
    loop=true;
    if(speed>0){ objScroller.down(speed) }
    else { objScroller.up(speed) }
  }
}

function CeaseScroll(){
  loop=false
  if(timer){ clearTimeout(timer) }
}

var initialised;
var objContainer;
var objScroller;

function InitialiseScrollableArea(){
  objContainer=new ConstructObject('newsContainer')
  objScroller=new ConstructObject('newsArticles','newsContainer')
  objScroller.MoveArea(0,0)
  objContainer.css.visibility='visible'
  initialised=true;
}

// end absolutely positioned scrollable area object scripts
