

///////////// PRELOAD IMAGES ////////////////

preloadArray = new Array();
function addPreload(imgSrc) { preloadArray[preloadArray.length] = imgSrc; }
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		for (i=0; i<preloadArray.length; i++) eval("preloadImage"+i+" = newImage('"+preloadArray[i]+"');");
		preloadFlag = true;
	}
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

addPreload("images/ma_round1a.gif");


// initialises functionality for the social networking links
function initSN() {
	el = document.getElementById('sn');
	if (el) {
		snImages = el.getElementsByTagName('IMG');
		for(i=0;i<snImages.length;i++) {
			snImg = snImages[i];
			snImg.onmouseover = function() {
				el = document.getElementById('snInfo');
				el.innerHTML = this.getAttribute('ALT');
			}
			snImg.onmouseout = function() {
				el = document.getElementById('snInfo');
				el.innerHTML = '';
			}
		}
	}
}


// image swap function
// swaps src on mouseover for images using the "imageSwap" CSS class
function initImageSwap() {
	imgs = document.getElementsByTagName('IMG');
	for(i=0;i<imgs.length;i++) {
		el = imgs[i];
		if (el.className=='imageSwap') {
			el.ext = el.src.substr(el.src.length-3,3);
			addPreload(el.src.replace('0.'+el.ext,'1.'+el.ext));
			addPreload(el.src);
			if (targetId = el.getAttribute('swapTarget')) {
				// attach events to target element instead of this image
				if (!el.id) el.id = "swapTargetSrc"+Math.random();
				targetEl = document.getElementById(targetId);
				targetEl.setAttribute('swapTargetSrc',el.id);
				// is the target a form?
				targetIsForm = false;
				for(f=0;f<document.forms.length;f++) {
					if (document.forms[f]==targetEl) {
						targetIsForm = true;
						break;
					}
				}
				if (targetIsForm) {
					targetEl.onfocus = function() {
						srcImg = document.getElementById(this.getAttribute('swapTargetSrc'));
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						if (srcImg.src.indexOf('1.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('0.'+srcImg.ext,'1.'+srcImg.ext);
						this.mactive = true;
					}
					targetEl.onblur = function() {
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						setTimeout("if (!document.getElementById('"+this.id+"').mactive) { srcImg = document.getElementById(document.getElementById('"+this.id+"').getAttribute('swapTargetSrc')); if (srcImg.src.indexOf('0.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('1.'+srcImg.ext,'0.'+srcImg.ext)+r; }" ,250);
						this.mactive = false;
					}
				} else {
					targetEl.onmouseover = function() {
						// force animated GIFs to reload in IE
						srcImg = document.getElementById(this.getAttribute('swapTargetSrc'));
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						if (srcImg.src.indexOf('1.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('0.'+srcImg.ext,'1.'+srcImg.ext) + r;
						this.mactive = true;
					}
					targetEl.onmouseout = function() {
						// force animated GIFs to reload in IE
						r = (srcImg.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
						setTimeout("if (!document.getElementById('"+this.id+"').mactive) { srcImg = document.getElementById(document.getElementById('"+this.id+"').getAttribute('swapTargetSrc')); if (srcImg.src.indexOf('0.'+srcImg.ext)==-1) srcImg.src = srcImg.src.replace('1.'+srcImg.ext,'0.'+srcImg.ext)+r; }" ,250);
						this.mactive = false;
					}
				}
			} else {
				el.onmouseover = el.onmouseup = function() {
					// force animated GIFs to reload in IE
					r = (this.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
					this.src = this.src.replace('0.'+this.ext,'1.'+this.ext)+r;
				}
				el.onmouseout = el.onmousedown = function() {
					// force animated GIFs to reload in IE
					r = (this.getAttribute("swapAni") && document.all) ? "?r="+Math.random() : '';
					this.src = this.src.replace('1.'+this.ext,'0.'+this.ext)+r;
				}
			}
		}
	}
}


// forces rss feed links to open in new window:
function breakOutRSSLinks() {
	el = document.getElementById('rssFeed');
	if (el) {
		rssLinks = el.getElementsByTagName('A');
		for(rLinkId=0;rLinkId<rssLinks.length;rLinkId++) {
			rLink = rssLinks[rLinkId];
			rLink.setAttribute('target','_blank');
		}
	}
}



///////////////// VIDEO EMBED /////////////////////////


function embedVideo() {
	el = document.getElementById('streambox');
	el.style.display = (el.style.display=='block') ? 'none' : 'block';
}




//////////////// IE CSS POSITION FIX ////////////////////

function shiftContainer() {
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer") {
		winWidth = document.body.offsetWidth;
		el = document.getElementById('cont1');
		if (winWidth < 1330) el.style.marginLeft = '0px';
		else el.style.marginLeft = '1px';
	}
}
onresize = function() {
	shiftContainer();
}


///////////////// MATCH COLUMNS ////////////////////

// forces the red background element to sit at the correct height
// all elements marked with the class "matchColumn" will be set to the same height
function matchColumns(){ 
     var divs,contDivs,maxHeight,divHeight,d; 	
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 
     maxHeight=0; 
     for(var i=0;i<divs.length;i++){ 
          if(/\bmatchColumn\b/.test(divs[i].className)){ 
                d=divs[i];
				d.style.height='auto'; // reset height first
          } 
     } 
     for(var i=0;i<divs.length;i++){ 
          if(/\bmatchColumn\b/.test(divs[i].className)){ 
                d=divs[i];
                contDivs[contDivs.length]=d; 
                if(d.offsetHeight){ 
                     divHeight=d.offsetHeight;
                } 
                else if(d.style.pixelHeight){ 
                     divHeight=d.style.pixelHeight;					 
                } 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 
     } 
     for(var i=0;i<contDivs.length;i++){ 
          contDivs[i].style.height=maxHeight + "px"; 
     }	 
     // realign anchor
     if (location.href.indexOf('#') != -1 && !pageLoaded) {
     	window.location = location.href;
     }
}



//////////////// ONLOAD SEQUENCE //////////////

pageLoaded = false;
onload = function() {
	pageLoaded = true;
	initSN();
	initImageSwap();
	shiftContainer();
	preloadImages();
	// breakOutRSSLinks();
	matchColumns();
	
	// reset the background treatment
	el = document.getElementById('pageContent');
	el.style.background = 'none';
}

// document.write("<style type='text/css'>#pageContent { background:none; } </style>");









