/*
jQuery.noConflict();
jQuery(document).ready(function(){ 
    jQuery("ul.sf-menu").supersubs({ 
        minWidth:    12,                                // minimum width of sub-menus in em units 
        maxWidth:    27,                                // maximum width of sub-menus in em units 
        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over 
                                                        // due to slight rounding differences and font-family 
    }).superfish({ 
        delay:       400,                               // delay on mouseout 
        animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation 
        speed:       'fast',                            // faster animation speed 
        autoArrows:  false,                             // disable generation of arrow mark-up 
        dropShadows: false                              // disable drop shadows 
    }); 
});
*/


jQuery(document).ready(init);

function init() {	
	// aplicar evento para hacer toggle a los submenues:
	jQuery("#access ul.sf-menu > li > a").click(toggleShowSubMenus);
	// hacer aparecer los elementos:
	hacerAparecerLosElementos();
}

function toggleShowSubMenus(){
	var estabaVisible;
	// chequear si el submenu estaba visible:
	if(jQuery("ul", jQuery(this).parent()).css("display") == "none"){
		estabaVisible = false;
	} else {
		estabaVisible = true;
	}
	
	// ocultar todos los submenues:
	jQuery("#access ul.sf-menu > li ul").animate({height: 'hide', opacity: 'hide'}, 200);
	
	// si tiene submenu:
	if(jQuery(this).parent().children().size() > 1 ){
		if(estabaVisible == false){
			// si NO estaba visible: mostrar
			jQuery("ul", jQuery(this).parent()).animate({height: 'show', opacity: 'show'}, 200);
		} else{
			// si estaba visible: ocultar
			jQuery("ul", jQuery(this).parent()).animate({height: 'hide', opacity: 'hide'}, 200);
		}
		// no ir al link:
		return false;
	}
}

function hacerAparecerLosElementos(){
		// desaparecer todos los submenues de la bootnera:
		jQuery("#access ul.sf-menu li ul").hide();
		// hacer aparecer el submenu correspondiente:
		jQuery("#access ul.sf-menu li.current_page_ancestor ul").show();
	
}


// funcion util que nos devuelve los segmentos de la URL posteriores al dominio:
function getSegment(num) {
    num += 1;
    var segments = window.location.pathname.toString().split('/');
    if (segments[num] != undefined) {
        return segments[num];
    }
    return '';
}

