$(document).ready(function() {

(
	function($){
		$.simpledropdown = function(selector, id, width, height) {
			$(selector).addClass("dropdown");
if (jQuery.browser.msie) $(selector).html('<img src="/images/dropdown-izq.png">'+$(selector).html()+'<img src="/images/dropdown-der.png" style="margin-left:'+(width-12)+'px">');
			$(selector).show();
			$(selector).attr("rel", id);
			$(selector).prepend('<input type="hidden" name="' + id + '" id="' + id + '">');
			var ul = $(selector).children("ul");
			ul.addClass("dropdown");
if (jQuery.browser.msie) {
	ul.css("background-position", (width-20) + "px 9px");
	ul.css("width", (width-12) + "px");
	$("ul.dropdown li").css("width", (width-36) + "px");
} else {
	ul.css("background-position", (width-18) + "px 9px");
	ul.css("width", width + "px");
	$("ul.dropdown li").css("width", (width-24) + "px");			
}
			$("ul.dropdown>li:first-child").addClass("selected");
			$("ul.dropdown>li").not(".dropdown>li:first-child").addClass("drop");
			
			$("ul.dropdown li[v!='']").live("mouseover", function() { $(this).addClass("hover"); });
			$("ul.dropdown li[v!='']").live("mouseout", function() { $(this).removeClass("hover"); });

			$("ul.dropdown").live("click", function() {
				var cRel=$(this).parent().attr("rel");
				var selecteditem = $(this).find(".selected");
				$(".drop", this).slideToggle("fast", function(){
					$("ul li", this).bind("click", function() {
						if ($(this).attr("v").length) {
							var t = $(this).text()
							if (t.length>40) t = Left(t, 40) + "...";
							$("#" + cRel).val($(this).attr("v"));
							$("#" + cRel).attr("ami", $(this).attr("ami"));
							var selection = t;
							selecteditem.text(selection).fadeOut(5, function() {
								if (jQuery.browser.msie) {
									$(this).fadeIn(100);
								} else {
									$(this).fadeIn(400);
								}
							});
						}
					});
				});
				return false;
			});
			
			var i=0
			$("div.dropdown .dropdown").each(function() {
				$(this).css("z-index", 1000-i);
				i++;
			});
		};
	}
)(jQuery);

(
	function(c){
		c.fn.NuevaOpcion=function(v, t, s){
			var a=this.children("ul").children("li.drop").children("ul");
			a.append('<li v="' + v + '">' + t + '</li>');
			//if(!(typeof f.type=="undefined"||f.type.toString().toLowerCase()!="select-one")){
		}

		c.fn.QuitarOpcion=function(v){
			var a=this.children("ul").children("li.drop").children("ul");
			a.find("li[v='" + v + "']").each(function() {
				$(this).remove();
			});
		}

		c.fn.Seleccionar=function(v){
			var selecteditem = this.find(".selected");
			var cRel=this.attr("rel");
			this.children("ul").children("li.drop").children("ul").find("li[v='" + v + "']").each(function() {
				var t = $(this).text()
				if (t.length>40) t = Left(t, 40) + "...";
				selecteditem.text(t);
				$("#" + cRel).val(v);
				$("#" + cRel).attr("ami", $(this).attr("ami"));
			});
		}
	}
)(jQuery);

});
