//Extension
if(!window.Element){Element={};}
Element.build=function(t,o,a){
	t=document.createElement(t);
	for(var i in o){t[i]=o[i];};
	if(lib.e(a)){a=document.body;}
	a.appendChild(t);
	return t;
};
Array.prototype.rotate=function(){n=(arguments.length==0)?1:arguments[0];
	while(n>0){this.push(this.shift());n--;}
	while(n<0){this.unshift(this.pop());n++;}
	return this;
};
Array.prototype.last=function(){return this[this.length-1];}
Number.uni=(function(i){
	var j={};
	return function(i){if(!j[i]){j[i]=0;}return i+''+j[i]++;};
})();
//Namespace
var lib={},usr={};
//Convenience
lib.id=function(i){return document.getElementById(i);};
lib.tg=function(t){return document.getElementsByTagName(t);};
lib.e=function(){
if(typeof arguments[0]=='undefined' || arguments[0]===null || arguments[0]==='') return true;
return false;
};
//Objects
lib.Banner=function(data){//period,panels,passes
	var i=[],t=8,j=3,k=3,id=0,loc='/img/inductions/',e=lib.id('banner');
	if(lib.e(e)){return;}
	data=data.sort(function(){return 0.5-Math.random();}).slice(0,j*k);
	while(id<j){i.push(Element.build('div',{},e));Element.build('img',{src:loc+data[id]},i.last());id++;}
	window.setTimeout(start,t*0.5*1000);data.rotate(3);
	function start(){e.className='on';
	id=0;while(id<j-1){lib.Pan(i[id].firstChild,t*(id+1));id++;}
	Element.build('img',{src:loc+data[0]},i[0]);data.rotate();
	id=window.setInterval(next,t*1000);
	}
	function next(){
	lib.Fade(i[0].firstChild,t);Element.build('img',{src:loc+data[0]},i[1]);
	lib.Pan(i[2].lastChild,t*(i.length-1));data.rotate();i.rotate();
	}
};
lib.Pan=function(e,s){if(lib.e(e)){return;}
	var m,i,j=0,id,d;
	m=(e.width/e.height>e.parentNode.clientWidth/e.parentNode.clientHeight)?'Width':'Height';
	e.className='pan_'+m;i=e['client'+m]-e.parentNode['client'+m];d=i/(10*s);id=setInterval(step,100);
	function step(){i-=d;j+=d;
	switch(m){
		case 'Width':e.style.marginLeft='-'+j+'px';break;
		case 'Height':e.style.marginTop='-'+j+'px';break;}
	if(i<=0){window.clearInterval(id);}
	}
};
lib.Fade=function(e,s){if(lib.e(e)){return;}
	var i=100,d=10/s,id=window.setInterval(step,100);
	function step(){i-=d;
		if(usr.ie){e.style.filter='alpha(opacity='+i+')';}
		else{e.style.opacity=i/100;}
		if(i<=0){window.clearInterval(id);e.parentNode.removeChild(e);
		delete e;}
	}
};
lib.Compare=function(a,b){return a[0]-b[0];
};
lib.Sort=function(e){e=e[usr.tg];
	var i=e.parentNode.parentNode,j=e.cellIndex,k=0;
	var mode=e.className,int=i.rows[1].cells[j][usr.tc].substr(0,1).search(/[0-9 ]/)+1;
	while(k<i.rows[0].cells.length){i.rows[0].cells[k].className=null;k++}k=[];
	while(i.rows.length>1){k.push([i.rows[1].cells[j][usr.tc],i.rows[1]]);i.removeChild(i.rows[1]);}
	if(int){k.sort(lib.Compare);}else{k.sort();}
	if(mode=='up'){e.className='down';}else{k.reverse();e.className='up';}
	while(k.length>0){i.appendChild(k.pop()[1]);}
};
lib.Sort.prepare=function(){
	var i=lib.tg('table'),j=0,k;
	while(j<i.length){if(i[j].className=='sort'){k=0;
	while(k<i[j].rows[0].cells.length){lib.Event(i[j].rows[0].cells[k],'click',lib.Sort);k++;}
	}j++;}
};
lib.Zoom=function(e){e=e[usr.tg];
	if(e.className=='zoom'){usr.scrim.on();e.className='unzoom';e.width=e.naturalWidth;e.height=e.naturalHeight;}
	else{usr.scrim.off();e.className='zoom';e.width=500;e.height=(500/e.naturalWidth)*e.naturalHeight;}
};
lib.Zoom.prepare=function(){var i=lib.tg('img'),j=0,k=false;
	while(j<i.length){if(i[j].className=='zoom'){k=true;lib.Event(i[j],'click',lib.Zoom);
		if(lib.e(i[j].naturalWidth)){i[j].naturalWidth=i[j].width;i[j].naturalHeight=i[j].height;}
		i[j].width=500;i[j].height=(500/i[j].naturalWidth)*i[j].naturalHeight;}j++;}
};
lib.Slides=function(i){
	var f=Element.build('ul',{innerHTML:'<li><a>First<\/a><\/li><li><a>Previous<\/a><\/li><li><a><span class="play">Play<\/span><span class="pause">Pause<\/span><\/a><\/li><li><a>Next</a><\/li><li><a>Last</a><\/li>'},lib.id(i.id)),
	i=i.data,id=null,j=0,s=f.parentNode.getElementsByTagName('img')[0],c=f.parentNode.getElementsByTagName('p')[0];
	f.parentNode.insertBefore(f,f.parentNode.firstChild);
	lib.Event(f.childNodes[0],'click',first);lib.Event(f.childNodes[1],'click',previous);
	lib.Event(f.childNodes[2],'click',play);lib.Event(f.childNodes[3],'click',next);
	lib.Event(f.childNodes[4],'click',last);
	function play(){if(j<i.length-1){if(!lib.e(id)){pause();}else{f.className='pause';id=window.setInterval(step,5000);}}}
	function step(){if(j<i.length-1){next();}else{pause();}}
	function pause(){window.clearInterval(id);id=null;f.className='';}
	function first(){j=0;change();}
	function last(){j=i.length-1;change();}
	function next(){if(j<i.length-1){j++;change();}}
	function previous(){if(j!=0){j--;change();}}
	function change(){s.src=i[j].s;c[usr.tc]=i[j].c;}
};
lib.Load=function(f){
	if (!lib.Load.state){
	lib.Event(window,'load',function(){var j=lib.Load;
	for (var i in j.list){j.list[i]();}delete j.list;});
	lib.Load.state=true;lib.Load.list=[];}
	if (lib.Load.list){lib.Load.list.push(f);}
	else{f();}
};
lib.Cookie = {
	set:function(n,v,o){var j=[n+'='+encodeURIComponent(v)];for (var i in o){j.push(i.replace('_','-')+'='+o[i]);}
		document.cookie=j.join(';');usr.cookie[n]=v;},
	unset:function(n,o){var j=[n+'=','max-age=0'];for (var i in o){j.push(i+'='+o[i]);}
		document.cookie=j.join(';');delete usr.cookie[n];}
};
lib.User=function(){
	if(document.all){lib.Event=function(obj,evt,f,once){
	if(once){var g=f;f=function(e){obj.detachEvent('on'+evt,arguments.callee);g(e);};}
	obj.attachEvent('on'+evt,f);};
	usr={ie:true,tc:'innerText',tg:'srcElement',sP:function(e){e.cancelBubble=true;},pD:function(e){e.returnValue=false;}};
	var j=['XMLHttpRequest()','ActiveXObject("MSXML2.XMLHTTP.6.0")','ActiveXObject("MSXML2.XMLHTTP")'];
	while(j.length>0){try{eval('usr.ajax=new '+j[0])}catch(e){j.shift();continue;}break;}}
	else{lib.Event=function(obj,evt,f,once){
	if(once){var g=f;f=function(e){obj.removeEventListener(evt,arguments.callee,true);g(e);};}
	obj.addEventListener(evt,f,true);};
	usr={ie:false,tc:'textContent',tg:'target',sP:function(e){e.stopPropagation();},pD:function(e){e.preventDefault();},ajax:new XMLHttpRequest()};}
	usr.cookie=(function(){if (!navigator.cookieEnabled){return false;}
	var i=document.cookie,j,k={};if(i==''){return k;}i=i.split(';');
	while(i.length>0){j=i.pop().split('=');k[j[0]]=decodeURIComponent(j[1]);}return k;})();
};
lib.User.load=function(){
	usr.scrim = {it:Element.build('div', {id:'scrim'}),
	on:function(){it.style.display='block';},
	off:function(){it.style.display='none';}};
};
lib.User.warn=function(){
	var i = navigator.userAgent.match(/MSIE (\d\.\d)/);
	if(i!=null && i[1]<8.0 && usr.cookie['nag']!='false'){usr.scrim.on();
	Element.build('div',{id:'warning',innerHTML:'<h1>Internet Explorer '+i[1]+
	'</h1><p>You are using an out-dated version of Internet Explorer. Please <a href="http://windowsupdate.microsoft.com">update your computer</a>, or return using <a href="http://www.google.com/chrome">Chrome</a>,  <a href="http://www.mozilla.com">Firefox</a>, <a href="http://www.apple.com/safari/">Safari</a>, or <a href="http://www.opera.com/">Opera</a>.</p><p id="continue">Continue Anyway</p>'});
	lib.Event(lib.id('continue'),'click',lib.User.proceed);}
};
lib.User.proceed=function(){usr.scrim.off();lib.id('warning').style.display='none';
	lib.Cookie.set('nag','false',{path:'/',max_age:81400});
};
//Begin Execution
lib.User();
lib.Load(lib.User.load);
if(usr.ie){lib.Load(lib.User.warn);}
lib.Load(lib.Zoom.prepare);
lib.Load(lib.Sort.prepare);
