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/home_mouseOn.png", "img/home_mouseOff.png", "img/aedipeCat_mouseOn.png", "img/aedipeCat_mouseDown.png", "img/noticies_mouseOn.png", "img/noticies_mouseDown.png", "img/publicacions_mouseOn.png", "img/publicacions_mouseDown.png", "img/tribuna_mouseOn.png", "img/tribuna_mouseDown.png", "img/festenSoci_mouseOn.png", "img/festenSoci_mouseDown.png", "img/salaPremsa_mouseOn.png", "img/salaPremsa_mouseDown.png", "img/contacte_mouseOn.png", "img/contacte_mouseDown.png");

    // 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").mousedown(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");
        }
    );
    
});