
// aejw.atlas.js - G2:0050
// copyright (c)2005 Adam Woods - All Rights Reserved - www.aejw.com
//   Permission must be granted from the respitive owners for any usage of this script 
//   and/or related files or material.
//   Image Red Ltd has unlimted rights and usage of this script / document.

//[ env ]
//
// 0003 - 02-12-05 - improved genearation 3 browsers id & support
// 0002 - 20-11-05 - updated into function/class structure - added g3 + g4 support
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
var z_env=function(){
	this.ver=navigator.appVersion;
	this.verMagor=parseInt(this.ver);
	this.browser=navigator.appName;
	this.base=navigator.appCodeName;
	this.g4=(document.getElementById);
	this.ie=(typeof(document.all)!='undefined');
	this.ie=(navigator.appName.indexOf("MSIE")||navigator.appName.indexOf("Microsoft"));
	this.ieKnown=(this.ie5||this.ie4);
	this.ie4=((document.all&&!this.g4));
	this.ie5=((this.ver.indexOf("MSIE 5")>-1&&this.g4));
	this.ns=(typeof(document.all)!='undefined');
	this.nsKnown=(this.ns5||this.ns4||this.ns6);
	this.ns5=((this.verMagor>=5)&&this.dom);
	this.ns4=(this.ns&&!this.g4);
	this.ns6=(this.ns&&document.getElementById);	
	return(this)
}
env=new z_env();

//[ dom ]
//
// 0002 - 07-12-05 - complete restructure
//                 - improved object fetch for moz/ff
//                 - added 'getFromEvent' function
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
var obj=function(){return{
	get:function(pId){
		if(document.getElementById&&document.getElementById(pId)){return(document.getElementById(pId));}else if(document.all&&document.all(pId)){return(document.all(pId));}else if(document.layers&&document.layers[pId]){return(document.layers[pId]);}var o=eval('document.'+pId);if(o!=null) return(o);
	},
	getStyle:function(pId){
		if(document.getElementById&&document.getElementById(pId)){return document.getElementById(pId).style;}else if (document.all&&document.all(pId)){return document.all(pId).style;}else if(document.layers&&document.layers[pId]){return document.layers[pId];}else{return(null);}
	},
	getFromEvent:function(pE){
		if(!pE){pE=window.event;}
		if(pE.originalTarget){
			return(pE.originalTarget);
		}else if(pE.srcElement){
			return(pE.srcElement);
		}
	},
	setInner:function(pId,pText){
		if(document.getElementById){
			oDiv=document.getElementById(pId);
			oDiv.innerHTML='';
			oDiv.innerHTML=pText;
		}else if(document.all){
			oDiv=document.all[pId];
			oDiv.innerHTML=pText;
		}else if(document.layers){
			oDiv=document.layers[pId];
			oDiv.document.open();
			oDiv.document.write('<p style="margin:0px:padding:0px;">'+pText+'</p>');
			oDiv.document.close();
		}
	},
	isDef:function(pId){
		return(typeof(pId)!='undefined');
	}
};}();

//[ evalex ]
//
// 0001 - 03-12-05 - created to execute js 1.5 is safe wrapper while ignoring older browsers
//
function evalSafe(pEval){
	return(eval("try{"+pEval+";throw('');}catch(e){}"));
}
function evalTry(pEval,pFailMsg){
	if(!pFailMsg||pFailMsg.length==0){pFailMsg='[Site Javascript Error]';}
	return(eval("try{"+pEval+";}catch(e){var desc=e.description?e.description:e;alert(pFailMsg+'\\n\\nError Desc: '+desc);}"));
}

//[ style ]
//
// 0002 - 07-12-05 - corrected bug if opacity was passed as a string
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
// clip: visible-css2:  display:block;visibility:visible;
// clip: hidden-css2:   display:block;visibility:hidden;
// clip: collapse-css2: display:none;visibility:hidden;
// clip: opacity-css2:  width:100px;filter:alpha(opacity=50);opacity=0.5;-moz-opacity:0.5;
//
function styleHide(pId){var oStyle=obj.getStyle(pId);if(oStyle){oStyle.visibility='hidden';oStyle.display='block';}return(false);}
function styleHideToggle(pId){var oStyle=obj.getStyle(pId);if(oStyle){if(oStyle.visibility!='visible'){oStyle.visibility='visible';oStyle.display='block';}else{oStyle.visibility='hidden';oStyle.display='block';}};return(false);}
function styleCollapse(pId){var oStyle=obj.getStyle(pId);if(oStyle){oStyle.visibility='hidden';oStyle.display='none';}return(false);}
function styleCollapseToggle(pId){var oStyle=obj.getStyle(pId);if(oStyle){if(oStyle.visibility!='visible'){oStyle.visibility='visible';oStyle.display='block';}else{oStyle.visibility='hidden';oStyle.display='none';}};return(false);}
function styleShow(pId){var oStyle=obj.getStyle(pId);if(oStyle){oStyle.visibility='visible';oStyle.display='block';};return(false);}

function setOpacity(pId,pOpacity){
	var o=obj.get(pId);
	if(typeof(o.style.MozOpacity)!='undefined'){
		o.style.MozOpacity=z_percent2mozOpacity(pOpacity);
	}else if(typeof(o.filters.alpha.opacity)!='undefined'){
		o.filters.alpha.opacity=pOpacity;
	}else if(typeof(o.style.opacity)!='undefined'){
		o.style.opacity=z_percent2mozOpacity(pOpacity);
	}
}
function getOpacity(pId){
	var iRet=0;
	var o=obj.get(pId);	
	if(typeof(o.style.MozOpacity)!='undefined'){
		iRet=z_mozOpacity2percent(o.style.MozOpacity);
	}else if(typeof(o.filters.alpha.opacity)!='undefined'){
		iRet=o.filters.alpha.opacity;
	}else if(typeof(o.style.opacity)!='undefined'){
		iRet=z_mozOpacity2percent(o.style.opacity);
	}
	return(iRet);
}
function z_mozOpacity2percent(pOpacity){
	pOpacity=''+pOpacity+'';
	if(pOpacity.indexOf('.')>-1){
		pOpacity=pOpacity.replace('0.','');
		if(pOpacity.length==1){pOpacity=pOpacity+'0';}
	}else{
		pOpacity=100;
	}	
	return(parseInt(pOpacity));
}
function z_percent2mozOpacity(pOpacity){
	pOpacity=''+pOpacity+'';
	pOpacity=pOpacity.replace('%','');
	if(pOpacity=='0'||pOpacity=='0.0'){
		pOpacity='0.01';
	}else if(pOpacity.length>=3){
		pOpacity='1.0';
	}else if(pOpacity.length==2){
		pOpacity="0."+pOpacity;
	}else{
		pOpacity="0.0"+pOpacity;
	}
	return(pOpacity);
}

//[ event binding ]
//
// 0003 - 03-12-05 - added support for constant event tags holding cross browser values, eg. load, unload
//                 - corrected fault with attachEvent, bind now does not always return false (0)
//                 - improved onLoad g3 support, odd browsers cannot have the 'onLoad' event binded but allow timers...
// 0002 - 20-11-05 - reopermised dispose and cleaned up bind code
// 0001 - 18-11-05 - bassed from an old event script, updated to handle ff events, ie4+ + ff1 + moz
//
var eventLoad='load';
var eventUnload=((typeof(window.onbeforeunload)!='undefined')?'beforeunload':'unload');
var eventBinder=function(){
	var lo_Index=[];
	var lf_BindInit=false;
	var li_LoadTimer=0;
	return{
		bind:function(pId,pOnEvent,pFunction,pCapture){
			var iRet=0;
			if(pOnEvent.substring(0,2)=='on'){pOnEvent=pOnEvent.substring(2,pOnEvent.length);};			
			if(lf_BindInit==false){
				lf_BindInit=true;
				eventBinder.bind(window,eventUnload,eventBinder.dispose,false);
			}
			if(!pCapture||pCapture==0){pCapture=false;}else{pCapture=true;}								
			if(pId.addEventListener){
				pId.addEventListener(pOnEvent,pFunction,pCapture);
				iRet=1;
			}else if(pId.attachEvent){
				iRet=pId.attachEvent('on'+pOnEvent,pFunction);
			}else{			
				pId['on'+pOnEvent]=pFunction;
				if(typeof(pId['on'+pOnEvent])!='function'){				
					if(li_LoadTimer==0&&pOnEvent=='load'){
						li_LoadTimer=setTimeout(overLoad+'();',3000);
					}
				}
			}
			if(iRet&&iRet!=0){
				lo_Index.push(arguments);
			}
			return(iRet);
		},
		unbind:function(pId,pOnEvent,pFunction,pCapture){
			if(lf_BindInit==false){return;}
			if(pOnEvent.substring(0,2)!="on"){pOnEvent="on"+pOnEvent;}
			if(pId.removeEventListener){
				pId.removeEventListener(pOnEvent.substring(2,pOnEvent.length),pFunction,pCapture);
			}else if(pId.detachEvent){
				pId.detachEvent(pOnEvent,pFunction);
			}else{
				pId[pOnEvent]=null;
			}
		},
		dispose:function(){
			if(lf_BindInit==false){return;}
			for(var i=lo_Index.length-1;i>=0;i--){
				eventBinder.bind(lo_Index[i][0],lo_Index[i][1],lo_Index[i][2],lo_Index[i][3]);
			}
			lo_Index=[];
			lf_BindInit=false;
		}
	};	
}();

//[ timer ]
//
// 0002 - 07-12-05 - restructure and clean up
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
var tmr=function(){return{
	set:function(pEval,pTimeout,pLoop){
		var sExec='';if(pLoop==true&&pTimeout>10){sExec='tmr.set(\''+pEval+'\','+pTimeout+',true);';}var iTimer=setTimeout(sExec+pEval,pTimeout);return(iTimer);
	},
	kill:function(pId){
		if(pId){clearTimeout(pId);}
	}
};}();

//[ metrics ]
//
// 0002 - 20-11-05 - added mouse xy tracking
//                 - updated into function/class structure
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
var metrics=function(){var li_MouseX=0,li_MouseY=0,lf_Capture=false;return{
	pageWidth:function(){return(metrics.portalWidth()+metrics.scrollLeft());},
	pageHeight:function(){return(metrics.portalHeight()+metrics.scrollTop());},	
	portalWidth:function(){var iWidth=0;if(document.documentElement&&document.documentElement.clientWidth){iWidth=document.documentElement.clientWidth-5;}else if(typeof(window.innerWidth)=='number'){iWidth=window.innerWidth;}else if(document.body&&document.body.clientWidth){iWidth=document.body.clientWidth-4;}return(iWidth);},
	portalHeight:function(){var iHeight=0;if(document.documentElement&&document.documentElement.clientHeight){iHeight = document.documentElement.clientHeight-5;}else if(typeof(window.innerHeight)=='number'){iHeight = window.innerHeight;}else if(document.body&&document.body.clientHeight){iHeight=document.body.clientHeight-4;}return(iHeight);},
	scrollLeft:function(){var i=(document.documentElement.scrollLeft>0)?document.documentElement.scrollLeft:document.body.scrollLeft;return(i);},
	scrollTop:function(){var i=(document.documentElement.scrollTop>0)?document.documentElement.scrollTop:document.body.scrollTop;return(i);},
	mouseX:function(){return(li_MouseX);},
	mouseY:function(){return(li_MouseY);},
	startMouseCapture:function(){if(lf_Capture) return;eventBinder.bind(document,'mousemove',metrics.z_captureMouseEvent);if(document.captureEvents){document.captureEvents(Event.MOUSEMOVE);}lf_Capture=true;},
	z_captureMouseEvent:function(pEvent){if(document.captureEvents){li_MouseX=pEvent.pageX;li_MouseY=pEvent.pageY;}else if(window.event.clientX){li_MouseX=window.event.clientX+document.documentElement.scrollLeft;li_MouseY=window.event.clientY+document.documentElement.scrollTop;}}
};}();

//[ window ]
//
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
function wndStatus(pStatus){if(window.status!=null){window.status=pStatus;}}
function wndBreakFrames(){if(self.parent.frames.length!=0){self.parent.location=document.location;}}

//[ image ]
//
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
// for max compat use inline scripting on A for image swap... 
//    <a onmouseover="img_x.src='img-over.gif';" onmouseout="img_x.src='img.gif';" href="#"><IMG id="img_x" name="img_x" alt="ImgX" src="img.gif" width="160" height="40" border="0"></a>
// (example caching)
//		function OnPageLoad(){
//			Img_Cache('nav_home-over.gif');
//		}
// (example image swap)
//		Img_Swap('nav_cont','x.gif');
//
var zImgCacheImages=new Array();
var zImgCacheImagesCount=0;
function Img_Cache(pImgFile){
	if(document.images){
		zImgCacheImagesCount++;
		var oImg=new Image();
		oImg.src=pImgFile;
		zImgCacheImages[zImgCacheImagesCount]=oImg;
		//if(document.imgCache==null){
			document.imgCache=zImgCacheImages;
		//}
	}
	return;
}
function Img_Swap(pId,pImgFile){if(document.images){obj.get(pId).src=pImgFile;}}

//[ data ]
//
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
function str2int(p){return(parseInt(p));}
function any2str(p){if(!p){p="";}return(parseStr(p));}
function strReplace(pStr,pFind,pReplace){return(pStr.split(pFind).join(pReplace))}
function datePlusDays(piAdjDays){var oDate=new Date();if(piAdjDays||piAdjDays!=0){oDate.setTime(oDate.getTime()+(((((piAdjDays*24)*60)*60)*1000)));}return(oDate);}
function getDayStr(piIntDay){var DayArray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");return(DayArray[piIntDay]);}
function getMonthStr(piMonth){var arMonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");return(arMonth[piMonth]);}
function getYearStr(piYear){if(piYear<2000){piYear=piYear+1900;}return(piYear);}
function getDateStr(){var today=new Date();var mon=envMonthStr(today.getMonth());var day=envDayStr(today.getDay());var year=envYearStr(today.getYear());return(day+", "+mon+" "+today.datePlusDays()+", "+year);}

//[ mozilla ]
//
// 0002 - 20-11-05 - rewrote mozilla scroll bar fix
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
// clip: <div style="float:right;"><img id="mozScroll" src="res/s.gif" width="1" height="1" style="position:absolute;left:0px;top:0px;" alt=""/></div>
//
function mozForceScrollbar(e){ //call with onLoad
	if(document.documentElement.clientHeight>0){
		eventBinder.bind(window,'onresize',z_mozForceScrollbarOnResize);
		obj.get('mozScroll').height=(metrics.pageHeight()+8);
	}	
}
function z_mozForceScrollbarOnResize(){
	obj.get('mozScroll').height=(metrics.pageHeight()+8);	
}

//[ ie ]
//
// 0001 - 03-12-05 - added set homepage
//
// clip: <span id="homepage" style="BEHAVIOR: url(#default#homepage)"></span>
//
function ieSetHomepage(pUrl){
	if(!homepage.isHomePage(pUrl)){
		document.write("<p stlye=\"margin:0px;\"><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('"+pUrl+"');\">Make this my homepage</a></p>");
	}
}

//[ spawn ]
//
// 0001 - 16-11-05 - imported from janus, dubbed build 0001 - spawns popups, browsers and dialogs
//
function spawn(phRef,phWin,piWidth,piHeight){window.open(phRef,phWin,'alwaysRaised=yes,width='+piWidth+'px,height='+piHeight+'px,resizable,scrollbars=yes,status=yes');}
function spawnBrowser(phRef,phWin,piWidth,piHeight){window.open(phRef,phWin,'width='+piWidth+'px,height='+piHeight+'px,resizable,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,status=yes');}
function spawnDialog(phRef,phWin,piWidth,piHeight,pfRefreshAfterClose){
	if(piWidth==null) piWidth=640; if(piHeight==null) piHeight=480;
	if(window.showModalDialog){
		phRef='atlas/dialog.aspx?href=../'+phRef;
		window.showModalDialog(phRef,phWin,'dialogHeight:'+piHeight+'px;dialogWidth:'+piWidth+'px;edge:Raised;center:yes;resizable:yes;help:no;status:yes;scroll:no;');
		if(pfRefreshAfterClose==true){window.location=window.parent.location.href.toString().replace('&',';jsand;');}
	}else{
		window.open(phRef,phWin,'alwaysRaised=yes,modal=yes,width='+piWidth+'px,height='+piHeight+'px,resizable,scrollbars=yes,status=yes');
	}
}
function spawnDialogRet(pRet){
	if(pRet!=null&&pRet!=''&&window.returnValue){
		window.returnValue=pRet;		
	}
	window.close();
}
		
//[ cookie ]
//
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
function cookieGet(psName){var sArg=psName+"=";var ii=0;while(ii<document.cookie.length){var jj=ii+sArg.length;if(document.cookie.substring(ii,jj)==sArg){var endstr=document.cookie.indexOf(";",jj);if(endstr==-1){endstr=document.cookie.length;}return(unescape(document.cookie.substring(jj,endstr)));}ii=document.cookie.indexOf(" ",ii)+1;if(ii==0){break};}return null;}
function cookieSet(psName,psValue,poExpire,psPath,psDomain,pfSecure){var oExpires=(poExpire)?poExpire:datePlusDays(7);var sPath=(psPath)?psPath:null;var sDomain=(psDomain>4)?psDomain:null;var fSecure=(pfSecure)?true:false;document.cookie=psName+"="+escape(psValue)+((oExpires==null)?"":("; expires="+oExpires.toGMTString()))+((sPath==null)?"":("; path="+sPath))+((sDomain==null)?"":("; domain="+sDomain))+((fSecure==true)?"; secure" : "");}
function cookieDel(psName){var exp=new Date();exp.setTime(exp.getTime()-1);var cval=cookieGet(psName);document.cookie=psName+"="+cval+"; expires="+exp.toGMTString();}

//[ tooltip ]
//
// 0003 - 28-11-05 - improved timers and garbage collection, fixed glitter
// 0002 - 20-11-05 - updated to handle scroll off screen
// 0001 - 16-11-05 - imported from janus, dubbed build 0001
//
// onload: eventBinder.bind(window,eventLoad,tooltipInit);
// clip:   <div id="tooltip" onmouseover="tooltipHold();" onmouseout="tooltipHide();" style="font:12px Tahoma,Arial,Helvetica,sans-serif;border:solid 1px #666666;padding:1px;position:absolute;z-index:100;visibility:hidden;color:#333333;top:0px;left:0px;background-color:#ffffcc;-moz-border-radius:5px;border-radius:5px;"></div>
//
var li_tooltipTimer=0;
var ls_tooltipActive='';
function tooltipInit(e){
	metrics.startMouseCapture();
}
function tooltipHold(){
	if(li_tooltipTimer>0){
		tmr.kill(li_tooltipTimer);
	}
	li_tooltipTimer=0;
}
function tooltipHide(){
	li_tooltipTimer=tmr.set('z_tooltipHide();',200)		
	return;
}
function tooltip(pEvent,pText,pAltName){

	if(!pText||!pEvent||pEvent==null||pText==null||pText.length==0){		
		tooltipHide();
		return;
	}	
	if(ls_tooltipActive.length>0){
		z_tooltipHide();		
	}
	if(!pAltName||pAltName==null){pAltName='tooltip';}	
	ls_tooltipActive=pAltName;
	
	var oObjStyle=obj.getStyle(ls_tooltipActive); 
	var oObjProp=obj.get(ls_tooltipActive);
	if(oObjStyle==null){	
		return;
	}
	if(pText!='#'){
		obj.setInner(ls_tooltipActive,pText);
	}
	
	var iX=metrics.mouseX()+12;
	var iY=metrics.mouseY()+12;
	
	if(oObjStyle.visibility!="visible"&&oObjStyle.visibility!="show"){		
		iX+=metrics.scrollLeft();
		if((iX+oObjProp.offsetWidth)>=metrics.pageWidth()){
			iX=(metrics.pageWidth()-oObjProp.offsetWidth);
		}
		oObjStyle.left=(iX)+'px';			
		oObjStyle.top=(iY)+'px';
		oObjStyle.visibility="visible";		
	}
}
function z_tooltipHide(){
	if(ls_tooltipActive.length==0) return;
	var o=obj.getStyle(ls_tooltipActive);
	if(o!=null){
		o.visibility="hidden";
		o.left=0;
		o.top=0;
	}
	ls_tooltipActive='';
	tooltipHold();
}

//[ fading rotation ]
//
// 0001 - 07-12-05 - created to fade an array of text in and out
//
var li_Rotation_TextPos=0;
var li_Rotation_HoldSeconds=5;
var li_Rotation_Speed=0;
var lo_Rotation_Text=new Array();

function initRotation(){
	if(lo_Rotation_Text.length>0){
		tmr.set('setRotation()',50);
		obj.setInner('rotation',lo_Rotation_Text[0]);
	}
}

function setRotation(){
	var i=getOpacity('rotation')+(3+li_Rotation_Speed);
	if(i>100) i=100;
	setOpacity('rotation',i);
	if(i!=100){
		tmr.set('setRotation()',50);
	}else{
		tmr.set('fadeRotation()',(1000*li_Rotation_HoldSeconds));
	}
}

function fadeRotation(){
	var i=getOpacity('rotation')-(3+li_Rotation_Speed);
	if(i<0) i=0;
	setOpacity('rotation',i);
	if(i!=0){
		tmr.set('fadeRotation()',50);
	}else{
		li_Rotation_TextPos++;
		if(li_Rotation_TextPos>(lo_Rotation_Text.length-1)){
			li_Rotation_TextPos=0;
		}
		obj.setInner('rotation',lo_Rotation_Text[li_Rotation_TextPos]);
		tmr.set('setRotation()',50);
	}
}