$(document).ready(function(){
    $('input#global-search').hover(function(){
        $(this).css('color', 'black');
    }, function(){
        if (!$(this).focus()) {
            $(this).css('color', '#e6e4e4');
        }
    }).focus(function(){
        $(this).css('color', 'black');
        if ($(this).val() == this.defaultValue) {
            $(this).val('');
        }
    }).blur(function(){
        if ($(this).val() == '') {
            $(this).val(this.defaultValue);
        }
    });

    $('body:not(#body-products) div#menu div#products').hover(function(){
        $('div#hover-menu').show();
    }, function(){
        $('div#hover-menu').hide();
    });

    $('form.ajax-enabled').submit(function(e){
        e.preventDefault();

        var url     = $(this).attr('action');
        var data    = $(this).serialize();

        $.get(url, data, processForm, 'json');
    });

    $('a.ajax-enabled').click(function(){
        $.get($(this).attr('href'), {}, processForm, 'json');
        return false;
    });
    
    $('a[rel=appendix],a[rel=external]').click(function(e){
        window.open($(this).attr('href'));
        e.preventDefault();
    });

    $("#dialog").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        height: 292,
        width: 378,
        open: function() {
            $('a.close', this).click(function(e){
                e.preventDefault();
                $('#dialog').dialog('close');
            });
        }
    });

    this.overlay = null
    $('#loadingDiv').hide().ajaxStart(function() {
        $(this).show();
        this.overlay = new $.ui.dialog.overlay(self);
    }).ajaxStop(function() {
        $(this).hide();
        if (this.overlay) {
            this.overlay.destroy();
        }
    });
    
    Cufon.replace('h2',{hover: true});
    Cufon.replace('.button p',{hover: true});
    Cufon.replace('#left-menu',{hover: true});
    Cufon.replace('form p a',{hover: true});
});
