// Selectors that apply functions to elements in PDE.
// Please define functions in pde-functions.js
// with meaningful names, so we can see what's going on.

$(function () {
    // IE 4 and 5 seem to attempt to run the code, but have various problems.
    // Therefore, we detect them and get out.
    if ( $.browser.msie && $.browser.version <6 ) return;
    

    // This is the on ready function. All selectors should go in here:

    // =============================================================
    // Global behaviors (well almost global due to optimisation)

    // Any <a class="newwindow"> should open in a new window.
    // This is because target attribute is disallowed in strict
    // (X)HTML.
    // 
    // Optimisation: This used to apply to ALL a.newwindow 
    // Now, to make it faster we only look in areas we know 
    // are going to contain it: header, footer, article main text
    $('#header #snowflake_logo_link').openInNewWindow();    
    $('#footer #pm_logotype_link').openInNewWindow();    
    $('#article #main a.newwindow').openInNewWindow();    
    $('.external').openInNewWindow();
    
    // =============================================================
    // Search form behaviour
    //

    // Pre-fill the Quick and Advanced search input boxes
    //  with the last search if saved in the cookie.
    $('#searchBox input#searchBoxText').preFillValue('last_search');
    $('body#advanced_search input#search1').preFillValue('last_search');

    // Select the contents of the query box on focus 
    // (so the hint or last search can be cleared easily)
    $('body#advanced_search input#search1').selectOnFocus();
    $('#searchBox input#searchBoxText').selectOnFocus();

    // Apply the Quick Search label contents as a hint when the box is empty    
    $('#searchBox input#searchBoxText').hint(false);

    // Clear out the default value on submit.
    $('#searchBox form').clearDefaultValuesOnSubmit();

    // Convert the radio buttons in the topic select form into a collapsing tree
    $('div#topicSelect').toggleNestedLists('topic_' + $.getURLParam('topicid'));

   
});

/*
    http://stackoverflow.com/questions/318630/get-real-image-width-and-height-with-javascript-in-safari-chrome
    The root problem is that WebKit browsers (Safari and Chrome) load JavaScript 
    and CSS information in parallel. Thus, JavaScript may execute before the styling 
    effects of CSS have been computed, returning the wrong answer
*/
$(window).load(function() {
  	// resize the organizatino logo to these maximum dimensions
    $('#org_logo').resize_org_logo(75, 210);
});


