$(function() {
    //
    // Global stuff
    //
    
    // Improve a little the search box
    var searchbox = $("#hd #navigation input[name='q']")
    var initial_search_value = searchbox[0].value;
    searchbox.focus(function() { this.value = (this.value == initial_search_value) ? '' : this.value; })
             .blur(function() { this.value = this.value == '' ? initial_search_value : this.value; });
             
     // Improve a little the photobucket search box
     var pb_searchbox = $("#panel-from_photobucket input[name='query']")
     if(pb_searchbox.length > 0) {
         var pb_initial_search_value = pb_searchbox[0].value;
         pb_searchbox.focus(function() { this.value = (this.value == pb_initial_search_value) ? '' : this.value; })
                     .blur(function() { this.value = this.value == '' ? pb_initial_search_value : this.value; });
    }
    
    // Add to favorite
    $(".add-to-favorite").click(function() {
        if ($.browser.msie)
            window.external.addFavorite(window.location.href, document.title);
        else
            alert("To bookmark this page please type:\n Ctrl+D (PC) or Cmd+D (MAC).");
    });
    
    // Make our jquery button activate on mouse-hover
    $(".fg-button")
        .hover(
            function() { $(this).addClass("ui-state-hover"); },
            function() { $(this).removeClass("ui-state-hover"); }
        )
        .focus(function() { $(this).addClass("ui-state-focus"); })
        .blur(function() { $(this).removeClass("ui-state-focus"); })
    
    // Let's add some rounded corners for IE
    DD_roundies.addRule('#main', '5px');
    DD_roundies.addRule('#sidebar', '5px');
    
    //
    // page-effect
    //
    
    // Create the tabs, and rid of jui background / fonts / rounded corners
    $(".page-effect #main #upload-tabs-throbber").hide()
    $(".page-effect #main #upload-tabs")
        .tabs()
        .removeClass('ui-widget ui-widget-content ui-corner-all')
        .addClass('ui-helper-clearfix')
        .show()
    ;
    // Select the right tab
    if (typeof submitted != 'undefined') {
        $(".page-effect #main #upload-tabs").tabs('option', 'selected', '#panel-'+submitted);
    }
    // Get rid of the jui background / rounded corners
    $(".page-effect #main #upload-tabs .ui-tabs-nav")
        .removeClass('ui-widget-header ui-corner-all')
    ;
    // Fix the rounded corners
    $(".page-effect #main #upload-tabs .ui-tabs-nav li")
        .removeClass('ui-corner-top')
        .addClass('ui-corner-left')
    ;
    // Get rid of jui background and fix the rounded corners
    $(".page-effect #main #upload-tabs .ui-tabs-panel")
        .removeClass('ui-widget-content ui-corner-bottom')
        .addClass('ui-corner-right ui-corner-bottom')
    ;
    
    // Submit form!
    $(".page-effect #main #upload-tabs .ui-tabs-panel form").submit(function() {
        var value = $(this).children("p").children("input:visible").val();
        if (value && value != "http://") {
            $(this).children("p").children(":submit").addClass('ui-state-active').next().show();
            return true;
        }
        $(this).children("ul.pre-upload-error").removeClass("ui-helper-hidden");
        return false;
    });

});
