jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

$(document).ready(function() {
	
	// preload images first (can run before page is fully loaded)
    $.preloadImages("img/buscar_mouseOn.png", "img/buscar_mouseDown.png", "img/responsables_mouseon.gif", "img/proveedores_mouseon.gif", "img/gurus_mouseon.gif", "img/ladohumano_mouseon.gif", "img/libros_mouseon.gif", "img/bestpractices_mouseDown.gif", "img/responsables_mousedown.gif", "img/proveedores_mousedown.gif", "img/gurus_mousedown.gif", "img/ladohumano_mousedown.gif", "img/libros_mousedown.gif", "img/bestpractices_mouseon.gif", "img/proveedores_mouseoff.gif", "img/gurus_mouseoff.gif", "img/ladohumano_mouseoff.gif", "img/libros_mouseoff.gif", "img/bestpractices_mouseoff.gif");

    // set up rollover
    $("img.rollover").hover(
        function() {
            this.src = this.src.replace("_mouseoff","_mouseon");
        },
        function() {
            this.src = this.src.replace("_mouseon","_mouseoff");
        }
    );
    
    // set up click    
    $("img.rollover").click(function() {
        $('img.active').removeClass('active').attr('src', function() {
            return this.src.replace('_mousedown', '_mouseoff');
        });
        this.src = this.src.replace("_mouseon","_mousedown");
        $(this).addClass("active");
    });

    // set up rollover2
    $("input[type='image']").hover(
        function() {
            this.src = this.src.replace("_mouseOff","_mouseOn");
        },
        function() {
            this.src = this.src.replace("_mouseOn","_mouseOff");
        }
    );
    
    $('#busquedaTematica ul ul ul').hide();
    /* acordeón
    $('#busquedaTematica ul ul li a').click(function() {
        var checkElement = $(this).next();
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            return false;
        }
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#busquedaTematica ul ul ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    });
    */
    $('#busquedaTematica ul ul li a').click(
        function() {
            $(this).next().slideToggle('normal');
            $(this).toggleClass('active');
            $('.active span').text('-');
            $(this).not('.active').children('span').text('+');
            //return false;
        }
    );

});

jQuery(function($) {
    $("#top h1").pngfix();
});