// Random Image Selector (bek)

// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = '/images/banner1.jpg'
theImages[1] = '/images/banner2.jpg'
theImages[2] = '/images/banner3.jpg'
theImages[3] = '/images/banner4.jpg'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img  class="banner-pic" alt="" src="'+theImages[whichImage]+'">');
}

// Popup function (bek)

function popup(input_url,w,h,s) {
 window.open(input_url,"_blank","height="+h+",width="+w+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars="+s+",status=0,toolbar=0");
}

// General functions (DW)

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* This handy addLoadEvent function from Simon Willison allows you to stack up 'window.onload' events 
without them stepping on each other's toes. It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/* This is our old popup function - parts of the site still use it, so I need to keep it */
function acpopup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") {
	strOptions="resizable,height="+strHeight+",width="+strWidth;
	window.open(strURL, '', strOptions);

} else if (strType=="fixed") {
	strOptions="height="+strHeight+",width="+strWidth;
	window.open(strURL, '', strOptions);
}
}

/* new accessible, unobtrusive popup code */
function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }
	
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
		 if (relIndex){
		 var relSplit = relIndex.split("|");    // Split our REL value into parts 
/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {       // If the REL=external...
            anchor.target = "_blank";           // set it's 'target' attribute to '_blank'
			anchor.className = "external";      // attach a CSS class to it to allow us to style it
			anchor.title = "Load in new window: "+ anchor.title +" "+ anchor.href;  // Add a new title attribute to warn the users of a new window
			
/* XHTML compliant popup attribute */
   			} else if (relSplit[0] == "popup") { // If the REL=popup...
			anchor.className = "popup";          // attach a CSS class to it to allow us to style it
			anchor.title = "Loads in a Popup Window"; // Add a new title attribute to warn the users of a new window
			anchor.popupWidth = relSplit[1]; 
			anchor.popupHeight = relSplit[2];
	        anchor.onclick = function() {acpopup(this.href,'fixed',this.popupWidth,this.popupHeight);return false;};
			}
		}
	   }
} 

addLoadEvent(function() {
	windowLinks();	
	//otherFunctions();
	//goHere();
});