function emptyQueue(q){var queue = Effect.Queues.get(q);queue.each(function(e) { e.cancel() });}
function pageLoad(){
		emptyQueue('pLoading');
		$('pageContainer').style.display = '';
		$('pLoading').style.display = 'none';
		$('pLoading').style.zIndex = -1000;
		$('pLoading').style.height = -0;
		$('pLoading').style.width = 0;
		$('pLoading').style.padding = 0;
		$('pLoading').style.margin = 0;
		$('pLoading').style.visibility = 'hidden';
		new Effect.Opacity('footer',{delay:0.4, duration:0.3, from:0, to:1, queue:{scope:'pLoad'}});	
		new Effect.Opacity('navT2',{delay:0.2, duration:0.4, from:0, to:1, queue:{scope:'pLoad'}});	
		new Effect.Opacity('content', {delay:0.2, duration:0.4, from:0, to:1, queue:{scope:'pLoad'}});
}
var easterEggStr = '';
function easterEgg(char){
	easterEggStr = easterEggStr += char.toLowerCase();
	easterEggStr = easterEggStr.slice(-10);
	if(easterEggStr == "&&((%'%'ba"){
		$('pageContainer').style.backgroundImage = 'url("skin/nim/image/banana.gif")';	
		$('pageContainer').style.backgroundRepeat = 'repeat';
	}
}
function pageUnload(loc){
		ePath=loc;
		new Effect.Opacity('page',{delay:0, duration:0.5, from:1, to:0, queue:{scope:'pUnload'}});
		setTimeout("window.location=ePath;",750);	
}
function sendForm(loc)
	{
		ePath=loc;
		$(ePath).submit();
	}
function pageUnloadForm(loc)
	{
		ePath=loc;
		new Effect.Opacity('page',{delay:0, duration:0.5, from:1, to:0, queue:{scope:'pUnload'}});
		setTimeout("sendForm(ePath);",750);
	}
Event.observe(document, 'dom:loaded', function(){
		$('pLoading').setOpacity(0);
		$('pLoading').style.display = "";
		new Effect.Opacity('pLoading', {delay:0, duration:0.3, from:0, to:1, queue:{scope:'loading', position:'front'}});
		$('content').setOpacity(0);
		$('navT2').setOpacity(0);
		$('footer').setOpacity(0);
		// set onClick to pageExit in all links except lightbox
		var links = $$('#page a:not([rel ^= lightbox])');	
		links.each(function(i){if(i.target != "_blank") {i.onclick= function() {pageUnload(this.href); return false;};}});
		// set attribute in all submit buttons
		var links = $$('form');
		links.each(function(i){i.onsubmit = function() {pageUnloadForm(i.id); return false;};});	
	});
Event.observe(window, 'load', function(){
	pageLoad();
	
		Event.observe(document, 'keypress', function(e){
		var code;
			if (!e) var e = window.event;
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code);
			//alert('Character was ' + character);
			easterEgg(character);
		});
});
// safari reload fix
checkReload=
	{
		checker: function(x)
			{
				if (x && !this.ignorer && new Date().getTime()-x>1200){this.reloader()};
				this.ignorer=false;
				setTimeout("checkReload.checker("+new Date().getTime()+")",1000)
			},
		init: function(x){this.reloader=x;	this.checker()},
		ignore: function(){this.ignorer=true}
	};
function loader(){checkReload.ignore();};
onload=loader;	 
function reloader(){if($('page').getStyle('opacity') == 0){pageLoad();}};
checkReload.init(reloader);
