/*[version]2008-09-15 18:51[/version]*/
/**
 * Class AnemaMenuEntry.js
 *
 * Das ist jetzt einmal nur für Bilder (und auch nicht komplett). Links kommen bei Bedarf.
 *
 *
 *
	activeImagePath
	inactiveImagePath
		bzw.
	label
	url
	domElement (Image oder Link)
	parentMenu
	ID
	attach
	detach
	heatUp
	coolDown
 */
function AnemaMenuEntry( id, domId, activeImagePath, inactiveImagePath, parentMenu ){
	this.domElement = null;
	this.image = null;
	this.parentMenu = parentMenu;
	this.activeImagePath = activeImagePath;
	this.inactiveImagePath = inactiveImagePath;
	this.id = id;
	this.domId = domId;
	this.isHot = false;

	var self = this;
	this.onClickHandler = function(){
		self.parentMenu.activateEntry( self );
	};
	this.onMouseOverHandler = function(){
		if( !self.isHot && self.image ) self.image.src = self.activeImagePath;
	};
	this.onMouseOutHandler = function(){
		if( !self.isHot && self.image ) self.image.src = self.inactiveImagePath;
	};
}


AnemaMenuEntry.prototype.attach = function(){
	if( !this.domElement ) throw "[AnemaMenuEntry] attach: cannot attach entry, DOM element missing";
	if( !this.parentMenu ) throw "[AnemaMenuEntry] attach: cannot attach entry, parent menu missing";
	if( this.attached ) this.detach();
	this.parentMenu.domElement.appendChild( this.domElement );
	Acu.registerEvent( this.domElement, "click", this.onClickHandler );
	Acu.registerEvent( this.domElement, "mouseover", this.onMouseOverHandler );
	Acu.registerEvent( this.domElement, "mouseout", this.onMouseOutHandler );
	this.attached = true;
};

// Liefert das DOM-Element, an dem der Menüeintrag bisher
// attached war oder null, wenn's nicht existiert.
AnemaMenuEntry.prototype.detach = function(){
	if( !this.attached || !this.domElement ) return null;
	Acu.unregisterEvent( this.domElement, "click", this.onClickHandler );
	Acu.unregisterEvent( this.domElement, "mouseover", this.onMouseOverHandler );
	Acu.unregisterEvent( this.domElement, "mouseout", this.onMouseOutHandler );
	if( this.domElement.parentNode ) this.domElement.parentNode.removeChild( this.domElement );
	this.attached = false;
	return this.domElement;
};

AnemaMenuEntry.prototype.heatUp = function(){
	if( this.image ) this.image.src = this.activeImagePath;
	this.isHot = true;
};

AnemaMenuEntry.prototype.coolDown = function(){
	if( this.image ) this.image.src = this.inactiveImagePath;
	this.isHot = false;
};

AnemaMenuEntry.prototype.hasDomElement = function(){
	return (this.domElement != null);
};

AnemaMenuEntry.prototype.setDomElement = function( obj ){
	if( typeof obj == "string" ) obj = document.getElementById( obj );
	this.domElement = obj;
};

AnemaMenuEntry.prototype.getDomElement = function(){
	return this.domElement;
};

AnemaMenuEntry.prototype.setDomImage = function( obj ){
	if( typeof obj == "string" ) obj = document.getElementById( obj );
	this.image = obj;
};

AnemaMenuEntry.prototype.getDomImage = function(){
	return this.image;
};


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

