function callInProgress (xmlhttp) {
switch (xmlhttp.readyState) {
case 1: case 2: case 3:
return true;
break;
// Case 4 and 0
default:
return false;
break;
}
}
function showFailureMessage() {
alert('uh oh, it looks like the network is down. Try again shortly');
}
// Register global responders that will occur on all AJAX requests
Ajax.Responders.register({
onCreate: function(request) {
request['timeoutId'] = window.setTimeout(
function() {
// If we have hit the timeout and the AJAX request is active, abort it and let the user know
if (callInProgress(request.transport)) {
request.transport.abort();
showFailureMessage();
// Run the onFailure method if we set one up when creating the AJAX object
if (request.options['onFailure']) {
request.options['onFailure'](request.transport, request.json);
}
}
},
5000 // Five seconds
);
},
onComplete: function(request) {
// Clear the timeout, the request completed ok
window.clearTimeout(request['timeoutId']);
}
});
	
	var myTimeout;
	var fadeEffect;
	var loadQueue = Effect.Queues.get('loadScope');
	var loadDescQueue = Effect.Queues.get('loadDescScope');
	var loadIt = true;
	var loadVar;

	function startLoading() {
		loadIt = false;
		Effect.Appear('mainAreaLoading',{duration:.75,queue:{position:'end',scope:'loadScope',limit:2}});
		Effect.Appear('descAreaLoading',{duration:.75,queue:{position:'end',scope:'loadDescScope',limit:2}});
	}
	function finishLoading() {
	  
      Effect.Fade('mainAreaLoading',{duration:.75,queue:{position:'end',scope:'loadScope',limit:2}});
	  Effect.Fade('descAreaLoading',{duration:.75,queue:{position:'end',scope:'loadDescScope',limit:2}});
	  loadIt = true;
	}
	
	
	function loader(loadVar) {
		new Ajax.Updater('descAreaInternal','workdesc.php', {method:'post',postBody:'content='+ loadVar +''});
		new Ajax.Updater('mainAreaInternal', 'rpc.php', 
			//Adding an empty function "function()" in order to make the function "finishLoading()" execute AFTER the code has been updated.
			{asynchronous:true,
			 onComplete:function() {
			 myTimeout = setTimeout("finishLoading();",1000);},
			 onlyLatestOfClass: 'thing', evalScripts: true, method: 'post', postBody:'content='+ loadVar +''});
	}
	
	function loadContent(id) {
		loadVar = id;
		if(loadIt==true){	
			if(loadQueue.toArray().length<1){
				if(loadDescQueue.toArray().length<1){
			
					clearTimeout(myTimeout);
					workSubCatActivate(id);
					startLoading();
					setTimeout('loader(loadVar);',1000);
				}
			}
		}
	}


function workSubCatActivate(id){
	var x = document.getElementById('rightCol');
	var y = x.getElementsByTagName('a');
	
	for(var $i=1; $i<=y.length; $i++){
		if($i == id){
			document.getElementById("workSubCatButton" + id).className = "active"
		} else {
			document.getElementById("workSubCatButton" + $i).className = "normal"
		}
	}
	return;
}

//WORK MAIN CATEGORY STICKY FUNCTION
function workButtonActivate($workCat){
	var x = document.getElementById('categories');
	var y = x.getElementsByTagName('a');
	for (var $i=1;$i<=y.length; $i++){
			if($i == $workCat){
				document.getElementById("workNavButton" + $workCat).className = "active"
			} else {
				document.getElementById("workNavButton" + $i).className = "normal"
			}
	}
}


//GLIDER BUTTON STICKY FUNCTION
function gliderButtonActivate($button){
	var x = document.getElementById('gliderNav');
	var y = x.getElementsByTagName('a');
	for (var $i=1;$i<=y.length; $i++){
		if($i == $button){
			document.getElementById("gliderButton" + $button).className = "active"
		} else {
			document.getElementById("gliderButton" + $i).className = "normal"
		}
	}
	return;
}


//MENU DIV SWAP
Effect.divSwap = function(element,container,$workCat,id){
    var div = document.getElementById(container);
    var nodeList = div.childNodes;
    var queue = Effect.Queues.get('menuScope');

    
 if(loadIt==true){
	if(queue.toArray().length<1){
        if(Element.visible(element)==false){
            for(i=0;i<nodeList.length;i++){
                if(nodeList.item(i).nodeName=="DIV" && nodeList.item(i).id!=element){
                    if(Element.visible(nodeList.item(i))==true){
                        Effect.Fade(nodeList.item(i),{queue:{position:'end',scope:'menuScope',limit:2}})
						loadContent(id);
                    }
                }
            }
		   Effect.Appear(element,{queue:{position:'end',scope:'menuScope',limit:2}})
			workButtonActivate($workCat);
       }
   }
 }
}

function P7_Uberlink(cl,d){
	var i,ob,tA,h=document.location.href;
	if(document.getElementById){
	ob=(d)?document.getElementById(d):document;
	if(ob){
	tA=ob.getElementsByTagName('A');
	for(i=0;i<tA.length;i++){
	if(tA[i].href==h){
	tA[i].className=cl;
}}}}}



function init() {
	loadContent(56);
	P7_Uberlink('uberlink','nav');

}	 
window.onload = init;