/* Fading Image */

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
		}
	}
}

addLoadEvent(initImage);

document.write("<style type='text/css'>#client {visibility:hidden;}</style>");

function initImage() {
	imageId = 'client';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

/* Animated Navigation */

var Site = {
	
	start: function(){
		
		Site.appearText();

	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#sidebar li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			el.setStyle('margin-left', '-155px');
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-left', {
				duration: 400,
				transition: Fx.Transitions.backOut,
				wait: false,
				onComplete: Site.createOver.pass([el, i])
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
	},
	
	createOver: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a') return;
		var overfxs = new Fx.Styles(first, {'duration': 200, 'wait': false});
		if (first.hasClass('onstate')){
			var tocolor = '2E8DAA';
			var fromcolor = '2E8DAA';
		} else {
			var tocolor = '2E8DAA';
			var fromcolor = 'fff';
		}
		el.addEvent('mouseover', function(){
			overfxs.start({
				'color': tocolor,
				'margin-left': 10
			});
		});
		el.addEvent('mouseout', function(){
			overfxs.start({
				'color': fromcolor,
				'margin-left': 0
			});
		});
	}
	
};

window.addEvent('domready', Site.start);


/* Simon Willison's addLoadEvent function 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 current 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=no,top=15,left=15,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}


/* new accessible, unobtrusive popup code */

function windowLinks() {                      // create a new function called windowLink(); 
    if(!document.getElementsByTagName) {      // Only run the function on browsers that
         return;                              // understand 'getElementsByTagName' - new browsers
    }
	
    var anchors = document.getElementsByTagName("a"); // grab all links and pop them in an array called 'anchors'
    for (var i = 0; i < anchors.length; i++) {        // start a loop to work our way through 
         var anchor = anchors[i];                     // grab the next link & copy it to 'anchor' for working
         var relIndex = anchor.rel;                   // get the value of it's 'REL' attribute
		 if (relIndex){                               // does it have a value for REL?...
		 var relSplit = relIndex.split("|");          
		 /* if it does, look for '|' to use to split the value into an 
		 array - relSplit[0], relSplit[1], relSplit[2], etc . If it doesn't 
		 find any '|', the whole value gets transferred to relSplit[0] */
		 
/* XHTML compliant target attribute */

		 if (relSplit[0] == "external") {       // If the relSplit[0] is 'external'...
            anchor.target = "_blank";           // then set it's 'target' attribute to '_blank'
			anchor.className = "external";      // then attach a CSS class to it 
			anchor.title = "Load in new window: "+ anchor.href;  
			// And give it a new title attribute to warn users a new window is launching
			
/* Elegantly degrading window code */

   			} else if (relSplit[0] == "popup") {      // else if relSplit[0] is 'popup'...
			anchor.className = "popup";               // attach a CSS class to it 
			anchor.title = "Loads in a Popup Window"; // Give it a helpful title attribute
			anchor.popupWidth = relSplit[1];          // set the popup's width
			anchor.popupHeight = relSplit[2];          // set the popup's height
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			// plug all this information into our origainl window launch function (acpopup) 
			}
		}
	  }
} 

addLoadEvent(function() {
	windowLinks();	// run our new function as soon as the page loads. 
	//otherFunctions();
	//goHere();
});
