function initIndex() {
	//jQuery.noConflict();
	// init twitter news
    $("div#twitter").load("/_system/twitter-news.php");
	
	// disable screen navi links
	// @TODO: shouldn't this go into the showscreenmenu function?
	$('.screen-navi-link').click( function (ev) {
		ev.preventDefault();
		return false;
	});
	
	// init screenshot navi (hovering)
	$('.screen-navi').hover( 
		function () { 
			$(this).siblings(".screen-navi-title").fadeIn();
			return false;
		},
		function () { 
			$(this).siblings(".screen-navi-title").fadeOut();
			return false;
		}
	);

	// init page disabler style (@TODO: can't we do this in the CSS as default?)
	$('#page-disable').css('opacity', 0);
	
	// init close-layer when clicking anywhere outside the layer
	$('#page-disable,#home-band-img').click( function (e) {
		doHideLayer(false, null);
		location.hash=''; // remove anchor from url
		return false;
	});

	// show the navi screen menu (delayed)
	window.setTimeout("showScreenMenu()", 500);
		
	// init the text-links before the navi
	$('.screen-navi-link').each ( function () {
		$(this).prepend("<img src='/_system/fontrender/font.php?text="+$(this).attr('title')+"&style=h6' class='fontrender screen-navi-title'/>");
	});
	// @TODO: can't we put this in the css as default?
	$(".screen-navi-title").css('display','none');
		
}

// init the right top screen menu
function showScreenMenu() {
	initScreenNavi();
	$('.screen-navi').each( function() { 
		$(this).effect("bounce", {times: 3}, getRandomNumber(200,800));
	});
}

// init all clickable layer-openers
function initScreenNavi() {
	/*$('.page-opener').live('click', function() {*/
	/* @TODO: this should be "live", but doesn't trigger . We will simulate this by re-calling the initScreenNavi every time a layer is loaded. To prevent duplicate bindings, we have to unbind existing clickevents first.*/
	$(".page-opener").unbind('click').click(function () {
		showLayer($(this));
		return false;
	});
}

// show a layer when you know its filename (dows not close other layers first, so is only suitable for initial page loads)
function showLayerByFileId(new_page_fileid) {
	doShowLayer(new_page_fileid, new_page_fileid=="" ? null : $("a[href='"+""+"layer_"+new_page_fileid+".php"+"']").attr("id"));
}

function showLayer(clickObj) {
	if(clickObj == null) { clickObj=$('#center'); }
	var new_page_fileid = $(clickObj).attr('href').replace(/^.*layer_([a-z\-]+).php$/, "$1");
	if(current_page_fileid != new_page_fileid)
	{
		// closure, defining a callback function
		doHideLayer(true, function () { 
			return function (new_page_fileid) { 
				doShowLayer(new_page_fileid, $(clickObj).attr('id')); // @TODO: check if transmitting the whole obj would also work... 
		}(new_page_fileid);
		});
	}
}
	
function doShowLayer(new_page_fileid, clickObjId) {
	// console.log("called for "+new_page_fileid+" by "+clickObjId);
	var new_page_filename = "layer_"+new_page_fileid+".php";
	$('#page-layer').load(""+new_page_filename, function() { /* Here "" would be the url path to the files if we chose to put the layer files somewhere else */
		current_page_fileid = new_page_fileid;
		location.hash=new_page_fileid;
		$('#page-layer').scrollTop(0); // make sure we always link to the top of the page
		doTransfer(clickObjId);
		pageTracker._trackPageview(new_page_filename);  // Google Analytics Ajax tracking
		initScreenNavi(); // @TMP: this can be removed as soon as "live" does trigger
	});
	
	if(current_page_fileid == "") {
		// hide the main screen if this is a new layer (and no layer change)
		$('#home-content-area').fadeOut();
		$('#page-disable').css('opacity', 0).show( function () {
			$(this).fadeTo("slow", 0.77);
		});
	}
}	

function doHideLayer(has_callback_function, callback_function) {
	// is there any layer opened at all?
	if(current_page_fileid == "") { 
		if(has_callback_function == true) {
			callback_function.call();
		}
	} else {
		// identify the hide target
		var hideTarget = $("a[href='"+""+"layer_"+current_page_fileid+".php"+"']");
		var hideTargetId = 'center'; // default if none can be found
		if(hideTarget.length > 0) {
			hideTargetId = hideTarget.attr("id");
		}
		$('#page-layer').css("visibility", "hidden").css("display","block").effect('transfer', {to:'#'+hideTargetId, className: 'ui-effects-transfer'},500);

		if(callback_function == null) {
			// there is no page to open afterwards, so just close this and bring the index page to foreground
			current_page_fileid = "";
			$('#page-disable').fadeOut("slow", function () {
				$(this).css('opacity', 0).hide();
				$('#home-content-area').fadeIn("normal"); 
			});
		} else {
			callback_function.call();
		}
	}
}
	
function doTransfer(clickObjId) {
	var clickObj = $("#"+clickObjId);
	if(clickObj.length == 0) {
		// if our opener element is not visible (e.g. because it was a content link), just choose any page-opener as a transfer source
		clickObj = $('.page-opener').first();
	}
	$(clickObj).effect('transfer', {to:'#page-layer', className: 'ui-effects-transfer'},500, function () {
		$('#page-layer').css("visibility", "visible").fadeIn();
	});
}

function getRandomNumber( min, max ) {
  if( min > max ) {
    return( -1 );
  }
  if( min == max ) {
    return( min );
  }
  return( min + parseInt( Math.random() * ( max-min+1 ) ) );
} 







