
var $={ // v1.2
	addOnload:function(func){
		if(document.getElementById&&(window.addEventListener||window.attachEvent)){
			var prev=window.onload;
			if(typeof window.onload!='function'){
				window.onload=func;
				}
			else{
				window.onload=function(){prev();func();}
				}
			}
		},
	getByClass:function(str,node,tag){
		var classEls=new Array();
		var elements
		node=!node?document:node;
		elements=!tag?node.all||node.getElementsByTagName('*'):node.getElementsByTagName(tag);
		var pattern=new RegExp('(^|\\s)'+str+'(\\s|$)');
		for(counter=0,found=0;counter<elements.length;counter++){
			if(pattern.test(elements[counter].className)){
				classEls[found]=elements[counter];
				found++;
				}
			}
		return classEls;
		},
	getById:function(){
		var elements=new Array();
		for(var counter=0;counter<arguments.length;counter++){
			var arg=arguments[counter];
			if(typeof arg=='string')arg=document.getElementById(arg);
			if(arguments.length==1)return arg;
			elements.push(arg);
			}
		return elements;
		},
	getByTag:function(str,node){
		if(node==null)node=document;
		return node.getElementsByTagName(str);
		}
	};

var CIPHER={
	decrypt:function(strIn){
		var strOut="";
		for(var i=1;i<strIn.length;i++){
			strOut+=CIPHER.shiftChar(strIn.charAt(i),((i % 25)*-1));
			}
		hexRegEx=/\.([A-Za-z0-9]{2})/;
		foundHex=hexRegEx.exec(strOut);
		while(foundHex!=null){
			if(foundHex[1]=="2E"){
				strOut=strOut.replace(foundHex[0],"%%dotx%%");
				}
			else{ 
				strOut=strOut.replace(foundHex[0],String.fromCharCode(parseInt(foundHex[1],16)));
				}
			foundHex=hexRegEx.exec(strOut);
			}	
		strOut=strOut.replace(/%%dotx%%/g,".");
		return strOut;
		},
	shiftChar:function(charIn,count){
		var decCode=charIn.charCodeAt(0);
		var resCode=decCode+count;
		if(decCode>=65&&decCode<=90){
			if(resCode>90)resCode=resCode-26;
			if(resCode<65)resCode=resCode+26;
			}
		else if(decCode>=97&&decCode<=122){
			if(resCode>122)resCode=resCode-26;
			if(resCode<97)resCode=resCode+26;
			}
		else resCode=decCode;
		return String.fromCharCode(resCode);
		},
	init:function(){
		cipherObject=$.getByClass("cipher");
		for(cipherCounter=0;cipherCounter<cipherObject.length;cipherCounter++){
			cipherObject[cipherCounter].innerHTML=CIPHER.decrypt(cipherObject[cipherCounter].id);
			}
		}
	}
$.addOnload(CIPHER.init);

var NAV={ // v1.1
	init:function(){
		if(window.attachEvent){
			var items=$.getByClass("menu",$.getById("nav"));
			for(counter=0;counter<items.length;counter++){
				items[counter].onmouseover=function(){this.className+=" hover"};
				items[counter].onmouseout=function(){this.className=this.className.replace(new RegExp(" hover\\b"),"")};
				}
			}
		}
	};
$.addOnload(NAV.init);

var SPLURT={
	bkgSize:function(){
		heightA=window.innerHeight?window.innerHeight:document.documentElement.clientHeight;
		heightB=document.body.scrollHeight;
		height=heightA>heightB?heightA:heightB;
		$.getById("splurt-bkg").style.height=height+"px";
		widthA=window.innerWidth?window.innerWidth:document.documentElement.clientWidth;
		widthB=window.scrollMaxX?document.body.scrollWidth-window.scrollMaxX:document.body.scrollWidth;
		width=widthA>widthB?widthA:widthB;
		$.getById("splurt-bkg").style.width=width+"px";
		window.scrollMaxY?$.getById("splurt-bkg").style.height=(width-window.scrollMaxY)+"px":0;
		window.scrollMaxX?$.getById("splurt-bkg").style.width=(width-window.scrollMaxX)+"px":0;
		},
	addElement:function(parent,type,params){
		var newElem=document.createElement(type);
		if(params)for(key in params){newElem.setAttribute(key,params[key]);if(key=="class")newElem.setAttribute("className",params[key]);}
		if(parent)parent.appendChild(newElem);
	 	return newElem;
		},
	center:function(){
		SPLURT.bkgSize();
		var pagesize=SPLURT.getPageSize();	
		var arrayPageScroll=SPLURT.getPageScrollTop();
		with($.getById("splurt-div").style){
			width=SPLURT.WIDTH+"px";
			left=(arrayPageScroll[0]+(pagesize[0]-SPLURT.WIDTH)/2)+"px";
			top=(arrayPageScroll[1]+(pagesize[1]-SPLURT.HEIGHT)/2)+"px";
			}
		},
	centerLoad:function(){
		var pagesize=SPLURT.getPageSize();
		var arrayPageScroll=SPLURT.getPageScrollTop();
		with($.getById("splurt-load").style){
			left=(arrayPageScroll[0]+(pagesize[0]-100)/2)+"px";
			top=(arrayPageScroll[1]+((pagesize[1]-100)/2))+"px";
			display="block";
			}
		},
	getPageScrollTop:function(){
		var xscrleft;
		var yscrtop;
		if(self.pageYOffset||self.pageXOffset)
			with(self){yscrtop=pageYOffset;xscrleft=pageXOffset;}
		else if(document.documentElement&&document.documentElement.scrollTop||document.documentElement.scrollLeft)	 
			with(document.documentElement){xscrleft=scrollLeft;yscrtop=scrollTop;}
		else if(document.body)
			with(document.body){xscrleft=scrollLeft;yscrtop=scrollTop;}
		arrayPageScroll=new Array(xscrleft,yscrtop);
		return arrayPageScroll;
		},
	getPageSize:function(){
		var de=document.documentElement;
		var w=window.innerWidth||self.innerWidth||(de&&de.clientWidth)||document.body.clientWidth;
		var h=window.innerHeight||self.innerHeight||(de&&de.clientHeight)||document.body.clientHeight;
		arrayPageSize=new Array(w,h);
		return arrayPageSize;
		},
 	init:function(){
		var anchors=$.getByClass("splurt",null,"a");
		for(var counter=0;counter<anchors.length;counter++){
			anchors[counter].onclick=function(){this.blur();SPLURT.show(this.href);return false;}
			}
		},
	kill:function(){
		SPLURT.killElement("splurt-bkg");
		SPLURT.killElement("splurt-div");
		SPLURT.killElement("splurt-load");
		window.onresize=null;
		window.onscroll=null;
		return false;
		},
	killElement:function(elem){
		if(typeof elem=='string')elem=$.getById(elem);
		try{elem.parentNode.removeChild(elem);}catch(err){}
		},
	show:function(splurtURL){
		SPLURT.kill();
		var splurtBkg=SPLURT.addElement(document.body,"div",{"id":"splurt-bkg"});
		splurtBkg.onclick=function(){return SPLURT.kill();};
		var splurtDiv=SPLURT.addElement(document.body,"div",{"id":"splurt-div"});
		window.onscroll=function(){SPLURT.center();}
		SPLURT.bkgSize();
		var splurtLoad=SPLURT.addElement(document.body,"div",{"id":"splurt-load"});
		var splurtLoadImg=SPLURT.addElement(splurtLoad,"img",{"src":"/_img/shared/splurt-load.gif"});
		splurtCaption=SPLURT.addElement(splurtDiv,"h2");
		splurtCaption.innerHTML="GREENWOOD RESOURCES WORLDWIDE";
		splurtClose=SPLURT.addElement(splurtDiv,"a",{"href":"#","title":"Close"});
		splurtClose.innerHTML="CLOSE";
		splurtClose.onclick=function(){return SPLURT.kill();};
		SPLURT.centerLoad();
		splurtPreload=new Image();
		splurtPreload.onload=function(){
			splurtPreload.onload=null;
			var imgWidth=splurtPreload.width;
			var imgHeight=splurtPreload.height;
			SPLURT.WIDTH=imgWidth+24;
			SPLURT.HEIGHT=imgHeight+60;
			SPLURT.addElement(splurtDiv,"img",{"id":"splurt-image","src":splurtURL,"width":imgWidth,"height":imgHeight});
			SPLURT.center();
			SPLURT.killElement("splurt-load");
			splurtDiv.style["display"]="block";
			}
		splurtPreload.src=splurtURL;
		window.onresize=function(){SPLURT.center();}
		}
	};	
$.addOnload(SPLURT.init);

var TARGET={ // v1.1
	init:function(){
		var anchors=$.getByTag("a");
		for(var counter=0;counter<anchors.length;counter++){
			var anch=anchors[counter];
			if(anch.getAttribute("href")&&anch.getAttribute("rel")=="external")anch.target="_ext";
			}
		}
	};
$.addOnload(TARGET.init);
