( function($) {
	
    $.fn.APS_menuHorizontal = function(opciones){
				
	var porDefecto = {  
			botonEncimaDuracion:150,
			botonFueraDuracion:100,
			espaciadoIcono:25,
			iconoRoot:"MEN02_iconoRoot",
			iconoNiveles:"MEN02_iconoNiveles"
	};  
	
	var opc = $.extend(porDefecto, opciones );
	
	var menu=$(this).children("ul").find("ul").parent();
	
	if(jQuery.browser.version==6.0){

		$(this).find("li").not(".MEN02_division").filter(function(){
				
				$(this).hover(
				function(){
						$(this).attr("class","iehover");
				},function(){
						$(this).attr("class","");
				})

		})
	
	}
	
	if($.browser.msie){
	    if($.browser.version>=6){
		    $(this).find("li").not(".MEN02_division").filter(function(){
				    
				    $(this).hover(
				    function(){
						    $(this).css({"z-index":1});
				    },function(){
						    $(this).css({"z-index":0});
				    })
		    })
	    }
	}

	return menu.each( function(){

		var padre=$(this);
		var hijo=$(this).find("ul:eq(0)");

		this.dimenciones={ancho:this.offsetWidth, alto:this.offsetHeight, hijo_ancho:hijo.outerWidth(), hijo_alto:hijo.outerHeight()};
		this.antecesores=padre.parents("ul").length==1? true : false;

		hijo.css({top:this.antecesores? this.dimenciones.alto+'px' : 0});
		
		padre.children("a:eq(0)").css({paddingRight: (this.antecesores? opc.espaciadoIcono+'px' : '')}).append('<div class="' + (this.antecesores? opc.iconoRoot : opc.iconoNiveles) + '"></div>')
		
		padre.hover(
			function(){
				
				var padre_evento=$(this).children("ul:eq(0)");
				
				this.posicion={izquierdo:$(this).offset().left, superior:$(this).offset().top};

				var alinear_menu=this.antecesores? 0 : this.dimenciones.ancho;

				alinear_menu=(this.posicion.izquierdo+alinear_menu+this.dimenciones.hijo_ancho>$(window).width())? (this.antecesores? -this.dimenciones.hijo_ancho+this.dimenciones.ancho : -this.dimenciones.ancho) : alinear_menu;

				if (padre_evento.queue().length<=1)
					padre_evento.css({left:alinear_menu+'px', width:this.dimenciones.hijo_ancho+'px'}).slideDown(opc.botonEncimaDuracion);
					
			},
			function(){

				var padre_evento=$(this).children("ul:eq(0)");
				
				padre_evento.slideUp(opc.botonFueraDuracion);

			}
		) 

	}).find("ul").css({display:'none',visibility:'visible'})
				
    };

})(jQuery);
