// JavaScript Document
 $(document).ready(function(){

    $('#jumpMenu').change(function() {
        var message = $(this).val();
          alert(message);
          top.location = message;
        });

      //hide the all of the element with class msg_body
  $(".toggle-container").hide();
  //toggle the componenet with class msg_body
  $(".toggle").click(function()
  {
    $("div.toggle-container:visible").slideToggle(250);
    $(this).next(".toggle-container").slideToggle(250);
  });
    
    // initiate the timer function for drop down menu delay    

    (function($){  
    $.fn.timeout = function(options) {  
        var defaults = {timeout:'2000',callback:function(){return true;}}; 
        var options = $.extend(defaults, options);  
        return this.each(function() {
            var e=$(this)[0];
            setTimeout(function(){options.callback.call(e)},options.timeout);
        }); 
    }
    })(jQuery); 

    // code to initiate switching of tabs 
    
    $('.tabs a').click(function(){
        switch_tabs($(this));
    });
    
    switch_tabs($('.current'));
    
    // hide SELECT options from IE6 drop downs
    
    // ############ Commented out by Rob to stop bug. Graham: You need to fix this ###############
    // $('.selectBox').bgiframe();

    // use javascript to hide the sub menus from the main nav
    
    $("#nav li ul").addClass("jqhide");
    
    // use javascript to hide the link lists from pages where they appear
    
    $(".hide").addClass("jqhide");
    
    // if user has javascript enabled display the post and online tabs on the contact box
    
    $("#wrap #right-navigation #tabs .tabs .post #post").css("display", "block");
    $("#wrap #right-navigation #tabs .tabs .online #online").css("display", "block");
    
    // if javascript is enabled, create drop down list and increase padding
    
    $("#service-search").css("padding-top", "85px");
    
    // hide link list of service selector
    
    $("#wrap #left-main-page-section #content .push-body li a").css("display", "none");
    
    //
    // LEFT MENU JQUERY OBJECTS
    //
    // if the active link in left menu is level 5 then do not auto hide the sub menu
    
    if($(".left-nav-sub-menu li.active").length == 0) {
            $(".left-nav-sub-menu").css("display", "none");
    }
    
    //
    // If active link is not a sub menu link then hide menu and display menu on clicking 'areas of expertise'
    //
    
    $('.left-nav-sub-link').hover(function () {
                                                $(this).children('ul').slideDown('medium'); 
                                                });
                                            
    //
    // TOP NAV jquery objects
    //
    // For all li objects in top nav, when mouse hovers, slide toggle the sub menu UL items
    //
    
    $("#nav li").bind('mouseenter',function(){
        $(this).children('ul').fadeIn('fast');
        });
    
    $("#nav li").bind('mouseleave',function(){
        $(this).timeout({timeout:'250',callback:function(elem){  
        $(this).children('ul').fadeOut(200);
        }});
                                                        
    });

    //
    //
    // make all links to video open in viewer if javascript is switched on
    //
    
    $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});

   
});
 
     //
    // function to switch tabs when clicked. First hide tab with .current class then add id of new tab and current class
    //
 
function switch_tabs(obj) {
                        $('.tab-content').hide();
                        $('.tabs a').removeClass("current");
                        var id = obj.attr("rel");
 
                        $('#'+id).show();
                        obj.addClass("current");
}