/*	
 *	@author			Marcus Dahlström
 *	@created		2008-02-19
 *	@copyright		
 *	@modified		2008-02-19
 *	
 */ 
DC = {
	
	navigate: function(linkelem, level, page) {
		$(linkelem).className;
		$A($$('.dc_navigation_level_'+level+'.selected')).each(function(e){e.removeClassName('selected')});
		[['SubMenu', 'Sidebar'], ['Content', 'Content'], ['Imagebox', 'Imagebox']].each(function(a){
			new Ajax.Request(window.location.pathname, {parameters: {action: a[0], p: page}, onSuccess: function(t) {
				$(a[1]).update(t.responseText);
			}});
		});
	},
	
	loadPage: function(a, page) {
		DC.page = page; 
		$A($$('.MainMenu .selected')).each(function(e){e.removeClassName('selected')});
		$(a).addClassName('selected');
		var okToLoadWithAjax=false;
		if (okToLoadWithAjax) {
			[['SubMenu', 'Sidebar'], ['Content', 'Content'], ['Imagebox', 'Imagebox']].each(function(a){
				new Ajax.Request(window.location.pathname, {parameters: {action: a[0], p: page}, onSuccess: function(t) {
					$(a[1]).update(t.responseText);
				}});
			});
		}
		return !okToLoadWithAjax;
	},
	initiate: function() {
		/* register methods for start and stop of an ajax request, to handle an loading */
		Ajax.Responders.register({
			onCreate: Core.onAjaxRequest, 
			onComplete: Core.onAjaxComplete
		});
		
		// todo: install timers to change random images with a fade. 
	}
}

Core = {
	onAjaxRequest: function() {
		 if (Core.ajaxRequestCount++==Core.ajaxCompleteCount) {
			ajaxInfoElem = document.createElement("img");
			ajaxInfoElem.style.cssText = "position: absolute; z-index: 99; top: 0; left:0;"
										+"background-color: transparent; border: none; color: #fff;";
			ajaxInfoElem.src="images/busy.gif";
			ajaxInfoElem.title = "Processing (" + Core.ajaxCompleteCount + "/" + Core.ajaxRequestCount + ")";
			$('Content').update(ajaxInfoElem);
		}
	},
	onAjaxComplete: function() {
			ajaxInfoElem.title = "Processing (" + ++Core.ajaxCompleteCount + "/" + Core.ajaxRequestCount + ")";
			if (Core.ajaxCompleteCount==Core.ajaxRequestCount) {
				Core.ajaxCompleteCount=Core.ajaxRequestCount=0;
			//	ajaxInfoElem.parentNode.removeChild(ajaxInfoElem);
		 } 
	}, 
	ajaxRequestCount: 0, 
	ajaxCompleteCount: 0
};
window.onload = DC.initiate;

//Element.observe(window, "load", DC.initiate);
