/*[version]2008-09-16 18:01[/version]*/
/**
 * Class AnemaMenu.js
 *
 * Nicht komplett.
 *
 * Demo-entryDOMElementCreatorFunction:

function createMenuEntryDomElement( entry ){
	// <div class="pichold1"><img class="pix" id="gal_$id" src="$path" alt="" /></div>
	var img = document.createElement( "img" );
	img.src = entry.inactiveImagePath;
	img.id = entry.domId;
	img.className = "pix";
	img.alt = "";
	entry.setDomImage( img );

	var div = document.createElement( "div" );
	div.className = "pichold1";
	div.appendChild( img );

	return div;
}


JScript:
galleryMenu = new AnemaMenu( showGallery, createMenuEntryDomElement );
galleryMenu.addEntry( new AnemaMenuEntry( entry.id, entry.domId, entry.activeImagePath, entry.inactiveImagePath, galleryMenu ) );
galleryMenu.attachTo( 'scroller' );

 */

function AnemaMenu( onClickHandler, creatorFunction ){
	this.entries = new Array();
	this.onClickHandler = onClickHandler;
	this.entryDOMElementCreatorFunction = creatorFunction;
	this.domElement = null;
	this.attached = false;
}

AnemaMenu.prototype.addEntry = function( entry ){
	this.entries.push( entry );
};

AnemaMenu.prototype.activateEntry = function( entry ){
	if( !entry ) "[AnemaMenu] activateEntry: no entry to activate";
	for( var i=0; i<this.entries.length; i++ ){
		if( this.entries[i] !== entry ){
			this.entries[i].coolDown();
		}
	}
	entry.heatUp();
	if( this.onClickHandler ) this.onClickHandler( entry );
};

AnemaMenu.prototype.ActivateEntryAtIndex = function( index ){
	if( index < 0 || index >= this.entries.length ) "[AnemaMenu] ActivateEntryAtIndex: illegal index (" + index + ")";
	var entry = this.entries[index];
	if( this.onClickHandler ) this.onClickHandler( entry );
	for( var i=0; i<this.entries.length; i++ ){
		if( i != index ){
			this.entries[i].coolDown();
		}
	}
	entry.heatUp();
};

// Hängt alle Einträge in das angegebene DOM-Element obj
// und registriert sich an selbigem in der Property
// anemaMenu.
AnemaMenu.prototype.attachTo = function( obj ){
	// Falls noch nicht attached, tu's jetzt.
	// Falls schon, aber an ein anderes Objekt, löse dich zuerst.
	// Sonst erzeuge für alle nicht eingehängten Knoten ein
	// DOM-Element und füge sie ein.
	if( typeof obj == "string" ) obj = document.getElementById( obj );

	if( this.attached ) this.detach();
	this.domElement = obj;

	// Im ersten Schritt erzeugen wir zu allen Einträgen, die noch kein DOM-Element haben, ein solchiges.
	// Und wo sie an einem hängen, lösen wir's wieder ab.
	for( var i=0; i<this.entries.length; i++ ){
		var entry = this.entries[i];
		if( !entry.hasDomElement() ){
			var o = this.entryDOMElementCreatorFunction( entry );
			entry.setDomElement( o );
		}
		if( entry.attached ) entry.detach();
	}

	for( var i=0; i<this.entries.length; i++ ){
		var entry = this.entries[i];
		entry.attach();
	}

	this.domElement.anemaMenu = this;
	this.attached = true;
};

// Liefert das DOM-Element, an dem das Menu bisher
// attached war oder null, wenn's nicht existiert.
// Menüeinträge werden ebenfalls ausgehängt.
AnemaMenu.prototype.detach = function(){
	if( !this.attached ) return null;
	for( var i=0; i<this.entries.length; i++ ){
		var entry = this.entries[i];
		if( entry.attached ) entry.detach();
	}
	this.domElement.parentNode.removeChild( this.domElement );
	this.domElement.anemaMenu = null;
	this.attached = false;

	return this.domElement;
};



AnemaMenu.prototype.insertEntry = function( index, entry ){
	throw "[AnemaMenu] insertEntry not yet implemented";
};

AnemaMenu.prototype.removeEntry = function( entry ){
	throw "[AnemaMenu] removeEntry not yet implemented";
};

AnemaMenu.prototype.removeEntryAtIndex = function( index ){
	throw "[AnemaMenu] removeEntryAtIndex not yet implemented";
};

AnemaMenu.prototype.setEntryCreatorFunction = function(){
	throw "[AnemaMenu] setEntryCreatorFunction not yet implemented";
};

AnemaMenu.prototype.getEntryCreatorFunction = function(){
	throw "[AnemaMenu] getEntryCreatorFunction not yet implemented";
};

AnemaMenu.prototype.setOnclickHandler = function(){
	throw "[AnemaMenu] setOnclickHandler not yet implemented";
};

AnemaMenu.prototype.getOnclickHandler = function(){
	throw "[AnemaMenu] getOnclickHandler not yet implemented";
};

AnemaMenu.prototype.getSize = function(){
	return this.entries.length;
};

AnemaMenu.prototype.coolAllMenuEntries = function(){
	for( var i=0; i<this.entries.length; i++ ){
		this.entries[i].coolDown();
	}
};


AnemaMenu.prototype.xx = function(){
	throw "[AnemaMenu] xx not yet implemented";
};
