/*
 * JavaScript Components Beta
 * http://www.axa.com/
 *
 * Date: Sat Feb 13 22:33:48 2010 -0500
 */
var navegacionPrincipal = {
	cssActivo: 'activo',
	cssOver: 'over',
	cssActivoSiguiente: 'activoSiguiente',
	cssActivoActivoSiguiente: 'activoActivoSiguiente',
	cssSegundoNivelActivo: 'itemSegundoNivelActivo',
	cssOpciones: 'opciones',
	cssMenu: '.primerNivel',
	cssNivelTres: '.opcionesNivelTres',
	cssComponenteC1: '.c1_header',
	cssComponenteC11: '.c1_menu2',
	categorias: [],
	init: function(){
		this.menu = $('#cabecera').find(this.cssMenu);
		if(this.menu.size() <= 0) return;
		this.config();
		this.customOverPrimerNivel();
		this.customOverSegundoNivel();
		this.crearCapaNivelTres();
		this.identificarNivelTres();
		this.customOverNivelTres();
	},
	config: function(){
		this.componenteC1 = $('#cabecera').find(this.cssComponenteC1);
		this.componenteC11 = this.componenteC1.find(this.cssComponenteC11);
		var submenu;
		this.menu.find('ul').each(function(){
			var menu = $(this);
			if(menu.is(':visible')) submenu = menu;
		});
		this.submenu = submenu;
		this.capaMasOpciones = this.submenu.find(this.cssNivelTres);
		return;
	},
	identificarNivelTres: function(){
		this.capaNivelTres = this.componenteC1.next();
		return;
	},
	crearCapaNivelTres: function(){
		this.componenteC1.parent().append(this.componenteC11);
		return;
	},
	customOverPrimerNivel: function(){
		var that = this;
		var enlace;
		var li;
		var anterior;
		this.menu.find('ul').prev().hover(
			function(){
				enlace = $(this);
				li = enlace.parents('li');
				anterior = li.prev();
				if(!li.hasClass(that.cssActivo)){
					li.addClass(that.cssOver);
					anterior.hasClass(that.cssActivo)? anterior.addClass(that.cssActivoActivoSiguiente) : anterior.addClass(that.cssActivoSiguiente);
					//that.capaNivelTres.hide();
				}
			}, 
			function(){
				if(!li.hasClass(that.cssActivo)){
					li.removeClass(that.cssOver);
					anterior.hasClass(that.cssActivo)? anterior.removeClass(that.cssActivoActivoSiguiente) : anterior.removeClass(that.cssActivoSiguiente);
				}				
			});
		return;
	},
	customOverSegundoNivel: function(){
		var that = this;
		var li;
		var isActivo;
		this.submenu.find('li').hover(
			function(){
				li = $(this);
				isActivo = li.hasClass(that.cssSegundoNivelActivo);
				if(!isActivo) li.addClass(that.cssSegundoNivelActivo);
			},
			function(){
				if(!isActivo) li.removeClass(that.cssSegundoNivelActivo);
			});
		return;
	},
	customOverNivelTres: function(){
		var that = this;
		this.capaMasOpciones.hover(
			function(){
				that.capaNivelTres.show();
			},
			function(){that.capaNivelTres.hide();
		}); 
		this.capaNivelTres.hover(
			function(){that.capaNivelTres.show();
			},
			function(){
				that.capaNivelTres.hide();
		});
		return;
	}
	
};
