﻿/* Last published: 06 Jul 2011 13:17 */



  
(function($) {
    $.fn.gpExpando = function(options, callback) {
        
            // default options - these are used when no others are specified
            $.fn.gpExpando.defaults = {
                slideToggleSpeed: 400,
                closedAncClass: "expand",
                openAncClass: "contract",
                closedAncTitle: "Show contents",
                openAncTitle: "Hide contents"
            };
        
        // build main options before element iteration
            var o = $.extend({}, $.fn.gpExpando.defaults, options);
             this.each(function() {
                var thisExpando = $(this);
                $(thisExpando).wrapInner('<div></div>');
        
                var firstHeading = $('div:first h2:first, div:first h3:first, div:first h4:first', thisExpando).get(0); //Get the first heading from the selected and assign it to a variable
                $(firstHeading)
                    .wrapInner('<a href="#" title="'+o.closedAncTitle+'" class="gpExpandoAnc '+o.closedAncClass+'"></a>')
                    .insertBefore($('div:first', thisExpando))
                    .addClass('gpExpandoHeading');
                $('div:first', thisExpando).hide();
            
                $('.gpExpandoAnc', thisExpando).click(function() {
                    var thisAnc = $(this);
                    if  ($(this).parent().next('div').is(":hidden")) {
                            $(thisAnc).attr('title', o.openAncTitle);
                            $(thisAnc).removeClass(o.closedAncClass);
                            $(thisAnc).addClass(o.openAncClass);
                        } else {
                            $(thisAnc).attr('title', o.closedAncTitle);
                            $(thisAnc).removeClass(o.openAncClass);
                            $(thisAnc).addClass(o.closedAncClass);
                        }
                    $(this).parent().next('div').slideToggle(o.slideToggleSpeed);
                    return false;
                });
            
            });
                 
            return this;
        };
        //  invoke the function we just created passing it the jQuery object
    })(jQuery); 

(function($) {
    $.fn.gpFormFieldHider = function(options, callback) {
        
            // default options - these are used when no others are specified
            $.fn.gpFormFieldHider.defaults = {
                inputParentClass: ".inputParent",
                hiddenId: "opt_fields_",
                actionType: 'slide'
            };
        
            // build main options before element iteration
            var o = $.extend({}, $.fn.gpFormFieldHider.defaults, options);
            this.each(function() {
                var thisHidden = $(this);
                var height = $(thisHidden).height();
                var optFieldRegEx = new RegExp('\\b'+o.hiddenId+'(\\w+)\\b'); 
                var thisInput = $(this).attr('id').match(optFieldRegEx)[1]; 
                var inputName = $('#'+thisInput).attr('name'); 
                
                function performAction(first) {
                    if ($('#'+thisInput).is(':checked') ) {
                        if (o.actionType == 'fade') {
                            $(thisHidden).fadeIn();
                        } else if (o.actionType == 'disable'){
                            $(thisHidden).find('input, textarea, select').each(function() {
                                $(this).removeAttr("disabled");                            
                            });
                        } else if (o.actionType == 'slide'){
                            $(thisHidden).show().animate({ height : height }, { duration: 200 });
                        }    
                    } else {                    
                        if (o.actionType == 'fade') {
                            if (first == 'yes') {
                                $(thisHidden).hide();
                            } else {
                                $(thisHidden).fadeOut();
                            }
                        } else if (o.actionType == 'disable'){
                            $(thisHidden).find('input, textarea, select').each(function() {
                                $(this).attr("disabled", "disabled");
                            });
                        } else if (o.actionType == 'slide'){
                            if (first == 'yes') {
                                $(thisHidden).animate({ height: 0 }, { duration: 1, complete: function () { 
                                    $(thisHidden).hide();
                                } 
                                });
                            } else {
                                $(thisHidden).animate({ height: 0 }, { duration: 200, complete: function () {
                                    $(thisHidden).hide();
                                } 
                                });
                            }
                        }
                    }
                };
                
                performAction('yes'); 
                $('input[type=radio][name='+inputName+'], #'+thisInput).click(function(){ 
                    performAction();
                });
            });
            return this;
        };
        
    })(jQuery); 

 
$.fn.reorder = function() {
 
  function randOrd() { return(Math.round(Math.random())-0.5); }
 
  return($(this).each(function() {
    var $this = $(this);
    var $children = $this.children();
    var childCount = $children.length; 
    if (childCount > 1) {
      $children.remove(); 
      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      $.each(indices,function(j,k) { $this.append($children.eq(k)); }); 
    }
  }));
}    
        
$(document).ready(function() {

    
    $("img.close_rollover").hover(
        function()
            {
            this.src = this.src.replace("cross","cross_2");
            },
        function()
            {
            this.src = this.src.replace("cross_2","cross");
            }
        );


    
    $('div.randomWithin').reorder();

    
    $('table:not(.nozebra).simpledatatable tr:odd td').addClass('odd');
    $('table:not(.nozebra).simpledatatable tr:even td').addClass('even');
    
    $('table:not(.nozebra).simpledatatable tr td.even.nozebra').removeClass('even');
    $('table:not(.nozebra).simpledatatable tr td.odd.nozebra').removeClass('odd');
    
    $(".browser_back").before('<div><a href="#" onclick="history.back(); return false;">Previous page</a></div>').remove();
    
    $( '.splitlist2col ol, .splitlist2col ul').each(function() {
          var classes = $(this).attr('class');
          if($(this).is("ol")) { var ordered = true; }
          var colsize = Math.round($(this).find("li").size()/2);
          $(this).find("li").each(function(i) {
               if (i>=colsize) {
                    $(this).addClass('right_col');                    
               }
            });
          if(ordered) {
               $(this).find('.right_col').insertAfter(this).wrapAll('<ol start="' + (colsize+1) + '" class="' + classes + '"></ol>');                
          } else {
                $(this).find('.right_col').insertAfter(this).wrapAll('<ul class="' + classes + '"></ul>');            
            }                
     });
    $('.splitlist2col ul .right_col, .splitlist2col ol .right_col').parent().after('<div class="clear"> </div>');
    $('.splitlist2col ul, .splitlist2col ol').wrap('<div style="float: left; width: 49.9%;"></div>'); 
    $('.splitlist2col ol li').css('margin-left', '0.5em');
    
    
    $('input.fck_js').removeAttr("disabled");
    
    $('.fck_disabled_message').remove();

    
    $('div[class*=colminheight]').each(function(index) { 
        var cmheight = $(this).attr('class').match(/\bcolminheight(\d+)\b/)[1];             
    
        $(this).css({
                'min-height' : cmheight+'px'
                })
                .height (cmheight+'px'); 
    });

    $('body').addClass('js'); 
    $('.showhide_small').gpExpando();
    $('.showhide_large').gpExpando( {  
       closedAncClass: "expand_large",
       openAncClass: "contract_large"
    });   
    $('div[id^=opt_fields_]').gpFormFieldHider(); //Grab divs that start with opt_fields_
    $('div[id^=disabled_opt_fields_]').gpFormFieldHider({actionType: 'disable', hiddenId:'disabled_opt_fields_'});
    $('div[id^=fade_opt_fields_]').gpFormFieldHider({actionType: 'fade', hiddenId:'fade_opt_fields_'});
});


$(document).ready(function() {

    
    $('ul#menuList li.menubar a[href*="sectors.htm"]').siblings('ul.menu').addClass("secMenu");
    $('ul#menuList li.menubar a[href*="sectors.htm"]').siblings('ul.menu').children('li:odd').addClass("col1");
    $('ul#menuList li.menubar a[href*="sectors.htm"]').siblings('ul.menu').children('li:even').addClass("col2");

    
    $('#main_logo div:not(.home_page_logo)').hover(
        function() {
            $(this).css('background-position', '0 -68px');
            },
        function() {
            $(this).css('background-position', '0 0');
            }
        );

    
    $('a[href*=#]').click(function(){
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });

    
    $('form#search_box').append('<img width="98" height="24" border="0" src="/assets/images/logos/powered_by_google.gif" alt="powered by Google">');
    
    
        var cookie_value = $.cookie('SearchBoxState');
    
        // setup toggler icon HTML states
        var togglerHTMLon  = '<div id="search_button" style="position: absolute; margin-top: -1em; margin-left: 940px;"><a href=""><img src="/assets/images/icons/toggle_searchbox_on.gif"  width="27" height="19" alt="Hide site search box"></a></div>';
        var togglerHTMLoff = '<div id="search_button" style="position: absolute; margin-top: -1em; margin-left: 940px;"><a href=""><img src="/assets/images/icons/toggle_searchbox_off.gif" width="27" height="19" alt="Show site search box"></a></div>';        
        
        // inject initial toggler icon and clearfix
        $('#wrapper').prepend(togglerHTMLoff + '<div class="clear">&nbsp;</div>');
        // initialise cookie
        if ($.cookie('SearchBoxState') != 'hide'){
            $('#search_button').before(togglerHTMLon).remove();        
            var cookie_date = new Date (3000, 01, 01 );        
            $.cookie('SearchBoxState', 'show', { expires: cookie_date});
            }
        // initialise search_header and search_button if 'hide' cookie found
        if ($.cookie('SearchBoxState') == 'hide' ){
            $('#search_button').before(togglerHTMLoff).remove();
            $('#search_header').css({opacity: 0});
            $('#search_header').hide();
            }
        // toggle things
        var searchToggle = function(){
            if (cookie_value ==  'show'){
                hideSearchBox();
                }
                else if (cookie_value ==  'hide'){
                    showSearchBox();
                }
            return false;
            };
            
         $('#search_button a').click(searchToggle);
        function resetSearchToggle(node) {
            node.remove();
            $('#search_button a').click(searchToggle);
            }
        
        // function to hide box and set cookie
        function hideSearchBox(){
            $('#search_button').before(togglerHTMLoff).fadeOut(400, function(){resetSearchToggle($(this));});        
            $('#search_header').animate({ opacity: 0 }, 400 );
            $('#search_header').slideToggle(400);            
            // update the cookie that specifies hide mode
            var cookie_date = new Date (3000, 01, 01 );                    
            $.cookie('SearchBoxState', 'hide', { expires: cookie_date});    
            cookie_value = 'hide';
            }    
            
        // function to show box and delete cookie        
        function showSearchBox(){
            $('#search_button').before(togglerHTMLon).fadeOut(400, function(){resetSearchToggle($(this));});
            $('#search_header').slideToggle(200, function(){$('#keyword').focus();});
            $('#search_header').animate({ opacity: 1 }, 400 );            
            // update the cookie that specifies show mode
            var cookie_date = new Date (3000, 01, 01 );                    
            $.cookie('SearchBoxState', 'show', { expires: cookie_date});    
            cookie_value = 'show';            
            }
    
});
