/*
Author: seba
Date: 2010-12-09
----------------
- Requiere prototype
*/



/*
container: el div que contendrá al menú.
id: el id para el ul.
*/

var menubase = Class.create( {
	initialize: function(container, id, definer) {
		try {
			if( (this.container = utils.getContainer(container) ) == false) {
				throw { name:"menubase container error" };
			}
		} catch(e) {
			alert(e.name);
			return false;
		}
		this.id = utils.validateId(id);
		this.definer = definer;
		this.ul;
		this.i = 0;
		this.prevActive;
		this.prepare();
	},	

	prepare: function() {
		Element.insert(this.container, (this.ul =  new Element("ul", { "id": this.id } ) ) );
	}
} );


var simplemenu = Class.create( {
	initialize: function(container, id, definer, style, force) {
		Object.extend(this, new menubase(container, id, definer));
		this.style = style;
		this.force = force;
		this.draw();
	},

	draw: function() {
		var gbn = utils.getBasename.bind(this);
		var gdb = this.getDrawButton.bind(this);
		var ul = this.ul;
		var force = this.force;
		var basename = utils.getBasename();
		$A(this.definer).each( function(n) {
			if( !Object.isUndefined( force ) ) {
				n.active = ( gbn(n.href) == force );
			} else {
				n.active = (basename == gbn(n.href));
			}
			Element.insert( ul, gdb(n) );
		} );

	},

	getDrawButton: function(n) {
		var content;
		switch(this.style) {
			case "curveStyle" :
				var active = (n.active == true) ? "On" : "Off";
				if( this.i == 0) {
					content = '<li class="bt0lft'+active+'"></li>';
				} else {
					content = '<li class="sep'+( (this.prevActive == true) ? "On" : "Off" )+active+'"></li>';
				}
				content += '<li'+( (active == "On") ? ' class="on"' : '' )+'>';
				content += '<a'+( (active == "On") ? ' class="on"' : '' )+' href="'+n.href+'" target="'+n.target;
				content += '" title="'+n.title+'">'+n.label+'</a></li>';

				if( this.i == this.definer.length-1 ) {
					content += '<li class="btNrgt'+active+'"></li>';
				}
				break;
		}
		this.prevActive = ( active == "On" ) ? true : false;
		this.i++;
		return content;
	}

} );






