/*
Bei Klick setze Galerie kalt.
Hole Content und schmeiÃŸ' ihn in den Div.

Was ist mit Scroll-Pfeilen?! MÃ¼ssen auf alle FÃ¤lle zurÃ¼ckgesetzt werden.
*/

var menLinks = null;
var menHome = null;
var menContact = null;
var serverConnection = null;
var contentDiv = null;

function contentInit(){
	menLinks = document.getElementById( 'men_links' );
	menHome = document.getElementById( 'men_home' );
	menContact = document.getElementById( 'men_contact' );
	contentDiv = document.getElementById( 'scroller2' );
//	serverConnection = new ATP( "content.php", "post", "", true );	// Kein Access-Key ("") und sequentielle Requests (true).
	serverConnection = Acu.getHttpRequest();
}

function coolContentMenu(){
	// Setze alle Content-MenÃ¼punkte kalt.
	setMenuState( menLinks, 'cold' );
	setMenuState( menHome, 'cold' );
	setMenuState( menContact, 'cold' );
}

function showLinksPage(){
	//Acu.displayNavigatorData(contentDiv);return;
	prepareContentDisplay( menLinks, 'links' );
}

function showHomePage(){
	prepareContentDisplay( menHome, 'home' );
}

function showContactPage(){
	prepareContentDisplay( menContact, 'contact' );
}

// Was fÃ¼r alle Links gleich ist.
function prepareContentDisplay( menuEntry, serverParam ){
	var data = menuEntryData[currentGalleryIndex];
	if( data ){
		document.getElementById( data.domId ).src = data.inactiveImagePath;
	}
	currentGalleryIndex = -1;
	coolGalleryMenu();	// gal.js
	hideRightsideScrolling();	// definied in scroll.js
	contentDiv.style.visibility = 'hidden';
	coolContentMenu();	// Die anderen beiden dreh ab.
	setMenuState( menuEntry, 'hot' );
//	serverConnection.send( {what : serverParam}, [{tagname:'content'}], displayContent );
	// Sitzt im Falle von Text-Content weiter links als bei der Galerieanzeige.
	document.getElementById( 'content_pane' ).className = "picholder2";

	// Wir schicken einen synchronen Request (false-Argument).
	serverConnection.open( "POST", 'content.php', false );
	serverConnection.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
	serverConnection.setRequestHeader( "Connection","close" );
	serverConnection.send( "what=" + serverParam );

	if( serverConnection.status != 200 ){
		throw "[content.js] Cannot load content: request failed - " + request.statusText;
	}
	contentDiv.innerHTML = serverConnection.responseText;
	contentDiv.style.visibility = 'visible';
}

/**
 * Eine ATP-Server-Response hat den vom XML-Tag eingeschlossenen Wert
 * in der Property "InnerValue".
 *
 */
function displayContent( atpServerResponse ){
	if( atpServerResponse.error ){
		contentDiv.innerHTML = atpServerResponse.errmsg;
	}else{
		contentDiv.innerHTML = atpServerResponse.content.innerValue;
	}
	contentDiv.style.visibility = 'visible';
}

/**
 * Wenn state == 'hot', dann heiÃŸ, sonst kalt.
 *
 */
function setMenuState( obj, state ){
	if( state == 'hot' ){
		obj.className = 'link_menue_h';
	}else{
		obj.className = 'link_menue';
	}
}