﻿function doMenuTab(menuId, submenuId, containerId, hidecontent, backOption) {
    hideBox(containerId, "#nothing");
    // Se carga el submenu
    doSubMenuTab(submenuId, containerId);
    //applyOpacity(menuId, "#nothing");    
    // Se agrega funcionalidad al backOption
    jQuery('#' + backOption).each(function() {
        var a_opcion = jQuery('a', this).get(0);        
        // Se agrega click                
        jQuery(a_opcion).click(function() {
            hideBox(containerId, "#nothing");
            resetOpacity(menuId, "#nothing");
            jQuery("." + hidecontent).show();
            jQuery("#" + backOption).hide();
            jQuery("#" + menuId).show();
            jQuery("#" + submenuId).hide();
            return false;
        });        
    });
    
    // Se agrega funcionalidad a los botones imagen
    jQuery('#' + menuId + ' .opcion').each(function() {
        var a_opcion = jQuery('a', this).get(0);
        var img_opcion = jQuery('.img-opacity', this);

        // Se agrega click                
        jQuery(a_opcion).click(function() {
            hideBox(containerId, "#" + jQuery(a_opcion).attr("rel"));
            resetOpacity(menuId, img_opcion);
            jQuery("#" + jQuery(a_opcion).attr("rel")).toggle();
            jQuery(img_opcion).stop().animate({ opacity: 0.4 }, 200);            
            
            // Se esconde o muestra el hidecontent
            if (jQuery("#" + jQuery(a_opcion).attr("rel")).css('display') == 'none') {
                jQuery("." + hidecontent).show();
                jQuery("#" + backOption).hide();
            } else {
                jQuery("." + hidecontent).hide();
                jQuery("#" + backOption).show();
            }
            jQuery("#" + menuId).hide();
            jQuery("#" + submenuId).show();
            // Activa opcion del submenu
            resetOpacity(submenuId, img_opcion);
            applyOpacitySubmenu(submenuId, jQuery(a_opcion).attr("rel"));            
            return false;
        });
        // Se agrega hover
        jQuery(img_opcion).hover(function() {
            jQuery(this).stop().animate({ opacity: 0.4 }, 200);
        },
                    function() {
                        if ((jQuery("#" + jQuery(a_opcion).attr("rel")).css('display')) == 'none') {
                            jQuery(this).stop().animate({ opacity: 1.00 }, 200);
                        }
                    });
    });
}

function hideBox(containerId, exclusion) {
    jQuery("#" + containerId + " .content").not(exclusion).each(function() {
        jQuery(this).hide();
    });
}

function resetOpacity(menuId, exclusion) {
    jQuery('#' + menuId + ' .img-opacity').not(exclusion).each(function() {
        jQuery(this).stop().animate({ opacity: 1.00 }, 200);
    });
}

function applyOpacity(menuId, exclusion) {
    jQuery('#' + menuId + ' .img-opacity').not(exclusion).each(function() {
        jQuery(this).stop().animate({ opacity: 0.4 }, 200);
    });
}

/* Submenu */

function doSubMenuTab(menuId, containerId) {    
    // Se agrega funcionalidad a los botones imagen        
    jQuery('#' + menuId + ' .opcion').each(function() {
        var a_opcion = jQuery('a', this).get(0);
        var img_opcion = jQuery('.img-opacity', this);

        // Se agrega click                
        jQuery(a_opcion).click(function() {
            hideBox(containerId, "#" + jQuery(a_opcion).attr("rel"));
            resetOpacity(menuId, img_opcion);
            jQuery("#" + jQuery(a_opcion).attr("rel")).show();
            jQuery(img_opcion).stop().animate({ opacity: 0.4 }, 200);            
            return false;
        });
        // Se agrega hover
        jQuery(img_opcion).hover(function() {
            jQuery(this).stop().animate({ opacity: 0.4 }, 200);
        },
                    function() {
                        if ((jQuery("#" + jQuery(a_opcion).attr("rel")).css('display')) == 'none') {
                            jQuery(this).stop().animate({ opacity: 1.00 }, 200);
                        }
                    });
    });
}

function applyOpacitySubmenu(menuId, slickbox_selected_name) {
    jQuery('#' + menuId + ' .opcion').each(function() {
        var a_opcion = jQuery('a', this).get(0);
        var img_opcion = jQuery('.img-opacity', this);        
        if (jQuery(a_opcion).attr("rel") == slickbox_selected_name) {          
            jQuery(img_opcion).stop().animate({ opacity: 0.4 }, 200);
        }
    });
}

function doMenuPerformance(menuId, submenuId, containerId, hidecontent, backOption) {
   
    // Se agrega funcionalidad a los botones imagen
    jQuery('#' + menuId + ' .opcion').each(function() {
        var a_opcion = jQuery('a', this).get(0);
        var img_opcion = jQuery('.img-opacity', this);

        // Se agrega click                
        jQuery(a_opcion).click(function() {
            resetOpacity(menuId, img_opcion);
            jQuery(img_opcion).stop().animate({ opacity: 0.4 }, 200);
            window.location = jQuery(this).attr("href");            
            
        });
        // Se agrega hover
        jQuery(img_opcion).hover(function() {
            jQuery(this).stop().animate({ opacity: 0.4 }, 200);
        },
                    function() {
                        if ((jQuery("#" + jQuery(a_opcion).attr("rel")).css('display')) == 'none') {
                            jQuery(this).stop().animate({ opacity: 1.00 }, 200);
                        }
                    });
    });
}
/* Para ligar slickbox en la misma pagina */
function doMenuInternal(a_opcion) {
    var containerId = "container";
    var submenuId = "menu-tab-submenu";
    //Oculta resto de contenido
    jQuery("#" + containerId + " .content").not(a_opcion).each(function() {
        jQuery(this).hide();
    });
    //Muestra contenido seleccionado
    jQuery("#" + a_opcion).show();
    //Cambia la opacidad de la opción seleccionada
    var img_opcion = jQuery('.img-opacity', a_opcion);
    resetOpacity(submenuId, img_opcion);
    applyOpacitySubmenu(submenuId, a_opcion);
}

/* Para ligar slickbox en otra pagina */
function doMenuExternal(a_opcion, menuId) {
    var containerId = "container";
    var submenuId = "menu-tab-submenu";
    var hidecontent = "contentFirst";
    var backOption = "backLink";
    //Oculta resto de contenido
    jQuery("#" + containerId + " .content").not(a_opcion).each(function() {
        jQuery(this).hide();
    });
    // Se esconde o muestra el hidecontent
    if (jQuery("#" + jQuery(a_opcion).attr("rel")).css('display') == 'none') {
        jQuery("." + hidecontent).show();
        jQuery("#" + backOption).hide();
    } else {
        jQuery("." + hidecontent).hide();
        jQuery("#" + backOption).show();
    }
    //Muestra contenido seleccionado
    jQuery("#" + a_opcion).show();
    jQuery("#" + menuId).hide();
    jQuery("#" + submenuId).show();
    jQuery('html, body').animate({scrollTop:0});
    //Cambia la opacidad de la opción seleccionada
    var img_opcion = jQuery('.img-opacity', a_opcion);
    resetOpacity(submenuId, img_opcion);
    applyOpacitySubmenu(submenuId, a_opcion);
}
