function cornerstone()
{
	this.navFlag = false;
	this.lastItem = false;
	this.navInterval = 0;
	this.init();
}

cornerstone.prototype.init = function()
{
	//check for nav
	if($('pagenav')){
		
		this.lastItem = $('pagenav').select('.selected')[0];
		
		var tA = $('pagenav').select('.sectionnav');
		var iMax = tA.length;
		for(var i=0;i<iMax;i++){
			var eventType = 'mousemove';
			
			if(tA[i].previous().hasClassName('click')){
				eventType = 'click';
			}			
			
			Event.observe(tA[i].previous(), eventType, this.trackNav.bindAsEventListener(this));
			
			if(tA[i].previous().hasClassName('selected')){
				tA[i].previous().addClassName('open');
				tA[i].show();
			}else{
				tA[i].hide();
			}			
		}
	}
	
	this.decrypt();
}

cornerstone.prototype.decrypt = function()
{	
	if($('body')){
		var tA = $('body').select('a[class="em_encrypted_native"]');
		var iMax = tA.length;
		for(var i=0;i<iMax;i++){
			var obj = tA[i];
			var encA = obj.rev.split('_');
			var str = des(_em_key,hexToString('0x' + encA[2]),0,1,hexToString('0x' + encA[3]),0).substring(0,Number(encA[1]));
			obj.update(str);
			Event.observe(obj,'click',function()
			{
				window.location = 'mailto:' + this.innerHTML;
				Event.stop(arguments[0]);
			});
		}
	}
};

cornerstone.prototype.toggleFlag = function()
{
	this.navFlag = false;
	clearInterval(this.navInterval);
}

cornerstone.prototype.trackNav = function(event)
{
	if(this.navFlag == false){
		var elem = Event.element(event);
		
		if(this.lastItem != elem){
		
			elem.addClassName('open');
			Effect.BlindDown(elem.next(),{duration:0.4});
			
			if(this.lastItem){
				if(this.lastItem.next()){
					Effect.BlindUp(this.lastItem.next(),{duration:0.4});
				}
				this.lastItem.removeClassName('open');
			}
			
			this.navFlag = true;
			this.lastItem = elem;
			
			clearInterval(this.navInterval);
			this.navInterval = setInterval(this.toggleFlag.bind(this),400);
		
		}
		
	}

}

//Clear text field default value
// Original script: http://www.scriptygoddess.com/archives/2005/11/15/clear-default-text-onclick-restore-if-nothing-entered/
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}





// Recall text field default value
// Original script: http://www.scriptygoddess.com/archives/2005/11/15/clear-default-text-onclick-restore-if-nothing-entered/
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
