$(function(){
    $(".imageButton").live("mousedown", function(e){
        var isDisabled = $(this).attr('disabled');
        
        if (typeof isDisabled != 'undefined' && isDisabled == 'yes') {
            return;
        }
        
        var base = $(e.target).attr('imgbase');
        
        // Check that shift key is pressed if necessary.
        if (typeof $(this).attr('shift') != 'undefined') {
            if (!e.shiftKey) 
                return;
        }
        
        e.target.src = base + '-pressed.png';
    });
    
    $(".imageButton").live("mouseup", function(e){
    
        var isDisabled = $(this).attr('disabled');
        
        if (typeof isDisabled != 'undefined' && isDisabled == 'yes') {
            return;
        }
        
        var base = $(this).attr('imgbase');
        $(this)[0].src = base + '-released.png';
        
        // Check that shift key is pressed if necessary.
        if (typeof $(this).attr('shift') != 'undefined') {
            if (!e.shiftKey) 
                return;
        }
        
        var action = $(this).attr('action');

		if (action.match(/\(\);*$/))
		    eval(action);
		else
            eval(action + "($(this));");
    });
    
    $(".imageButton").live("mouseout", function(e){
        var base = $(this).attr('imgbase');
        $(this)[0].src = base + '-released.png';
    });
});


$(function(){
    $(".imageCheck").live("mousedown", function(e){
        var base = $(e.target).attr('imgbase');
        
        // Check that shift key is pressed if necessary.
        if (typeof $(this).attr('shift') != 'undefined') {
            if (!e.shiftKey) 
                return;
        }
        
        e.target.src = base + '-pressed.png';
    });
    
    $(".imageCheck").live("mouseup", function(){
        var base = $(this).attr('imgbase');
        var checked = $(this).attr('checked');
        
        // Check that shift key is pressed if necessary.
        if (typeof $(this).attr('shift') != 'undefined') {
            if (!e.shiftKey) 
                return;
        }
        
        if (typeof checked == 'undefined') {
            $(this).attr('checked', "yes");
            base = base.replace('uncheck', 'check');
            $(this).attr('imgbase', base);
        }
        else {
            $(this).removeAttr('checked');
            base = base.replace('check', 'uncheck');
            $(this).attr('imgbase', base);
        }
        
        $(this)[0].src = base + '-released.png';
        
        var action = $(this).attr('action');
        if (typeof action != 'undefined') 
            eval(action + "($(this));");
    });
    
    $(".imageCheck").live("mouseout", function(){
        var base = $(this).attr('imgbase');
        $(this)[0].src = base + '-released.png';
    });
});

