var currentSection;
var mooFX;
var enableLoadingMsg = false;
var loading = false;
var loadReplace = "";

function loadFirst() {
  if (currentSection == null) {
		currentSection = "home";
		mooFX = new fx.Combo("mooFX", {height: true, opacity: false, duration: 300});
	}
  selectContent("home");
}

function selectContent(section) {
  mooFX.hide();
	if (currentSection != null) {
		$(currentSection).className = "";
	}
	currentSection = section;
	toggleLoad();
	var rand = Math.round( ( Math.random() * 666 ) );
	new ajax (currentSection + ".html?nochache=" + rand, {
	   method: "get",
	   //update: $("content"), 
	   onComplete: displayContent
    });
}

function displayContent(request) {
  // extract only the part witin <body> and </body>!!
  var text = request.responseText;
  var startIndex = text.indexOf("<body>") + 6;
  var endIndex = text.indexOf("</body>");
  text = text.substring(startIndex, endIndex);
  $("content").innerHTML = text;
  toggleLoad();
  if (currentSection == "gallery") { initLightbox(); }
  mooFX.toggle();
	var element = $(currentSection);
	element.blur();
	element.className = "current";
} 

function toggleLoad() {
  if (!enableLoadingMsg) { return; }
  if (loading) {
    $(currentSection).innerHTML = loadReplace;
    loading = false;
  } else {
    loadReplace = $(currentSection).innerHTML;
    $(currentSection).innerHTML = 'pocakaj...';
    loading = true;
  }
}
