jQuery(document).ready(function($) {

    /* Main Navigation Drop Down */
    $('#nav-inner ul li:has(div)').hover(function() {
        $(this).find("a").addClass("hover");
        $(this).find('div').show();
    },
    function() {
        $(this).find("a").removeClass("hover");
        $(this).find('div').hide();
    });
    
    /* preload picture menu images */    
    $.preload( 'div.nav-pictures img', {
    find:/menuImage/,
    replace:'menuRolloverImage'
    });    
    
    /* picture menu drop down */
    $(function() {
      $("div.nav-pictures img").hover(function() {
        $(this).attr("src", $(this).attr("src").split("menuImage").join("menuRolloverImage"));
      }, function() {
        $(this).attr("src", $(this).attr("src").split("menuRolloverImage").join("menuImage"));
      });
    });    

    /* Product detail sliding nav-menus */
    $('.feature-nav-item-header').bind('click', function(e){
        e.preventDefault();
    $(this).siblings('.feature-nav-item-subnav').slideToggle('normal');
    });
    
    /* Advanced search toggle */
    $("#refine-search").click(function (e) { 
      e.preventDefault();
      $(this).toggleClass("selected");
      $(this).parents("DIV.searchbox").find("#advanced-search").toggle();
    });

    /* homepage news ticker */
    var currentHeadlineCount = 0;
    var headlineCount = $('DIV.news-headlines').children().size();
    var heightOfHeadline = $('DIV.news-headlines').children().height();
    setInterval(function() {    
    if (currentHeadlineCount < headlineCount - 1) {
        $('DIV.news-headlines').animate({top: '-=' +  heightOfHeadline + 'px'}, 'normal');
        currentHeadlineCount++;
    } else {
        $('DIV.news-headlines').animate({top:'0px'}, 'normal');
        currentHeadlineCount = 0;
    }
    }, 5000);

    /*  
     *
     *  START Navigation: Project Matrix 
     *
     */

    /* Navigation menu behaviour. */
    $(function() {

        var bgcolor = '#C2C8CB';
        var bgcolor_rollover = $("UL.productmatrix LI A").attr("bgcolor");

        /* Behaviour for selected menu item. */
        $("UL.productmatrix LI A").map(function() {

            $selected = $(this).attr("class");

            if ($selected == 'selected') {

                /* Selected item uses rollover background colour. */
                $(this).attr("style", 'background-color:' + bgcolor_rollover);

            } else {

                /* Non-selected items have rollover effect. */
                $(this).hover(
                    /* On rollover */
                    function() {
                        $(this).attr("style", 'background-color:' + bgcolor_rollover);
                    },

                    /* On rollout */
                    function() {
                        $(this).attr("style", 'background-color:' + bgcolor);
                    }
                );

            }

        });
    });    

    /* 
     *
     * END Navigation: Project Matrix 
     *
     */
    
    $(function(){
        $('.distloc').change(function(){
            v = $(this).val();
            if(v){
                $("ul.distlist>li>*").hide();
                li = $("ul.distlist>li>span.country:contains('" + v + "')").parent().show();
                $(".results", li).show();
            }
        });
    });

});
