		//MENU DROPDOWN
		var current_progress = 0, programme_length = 0, timeout = 500, closetimer = 0, ddmenuitem = 0, numImages, thing; 
		var height = null, success = false, iphone = false, currentImage = 1;

		function jsddm_open() {  
		  jsddm_canceltimer();
      jsddm_close();
      ddmenuitem = $(this).find('ul').css('visibility', 'visible');
		}	 

	  function jsddm_close() {  
      if(ddmenuitem) { ddmenuitem.css('visibility', 'hidden'); }	 
	 	}

 	 	function jsddm_timer() { 
		  closetimer = window.setTimeout(jsddm_close, timeout);
		}

	  function jsddm_canceltimer(){  
		  if(closetimer) {  
			  window.clearTimeout(closetimer);
        closetimer = null;
			}
		}

		$(document).ready(function()
		{  $('#menu > li, #toolbar li#account').bind('mouseover', jsddm_open)
   	$('#menu > li, #toolbar li#account').bind('mouseout',  jsddm_timer)});

	  document.onclick = jsddm_close;

    //ROTATE THE BANNER IMAGES
		function changeImage()
		{
    $("#img" + currentImage).fadeOut(3000);
    currentImage = (currentImage >= numImages) ? 1 : currentImage + 1;
    $("#img" + currentImage).fadeIn(3000);
		}

		//POPUP WINDOW CLOSE
		function popupClose() {
		 		$('.modal-window').remove();
				$('#overlay').remove();
				if (success) {
				  window.location.reload();
				}
		}		
		
		//POPUP WINDOW OPEN
		function popupOpen(location, height) {		
				$('body').append('<div id="overlay"></div>');
				$('#overlay').show();		
	   		var parent ="body";
				margin_top = 0;
				margin_left = 0;
				popup_left = "";	
				popup_top = "";							
		 		width = 720;							
		     //if ((height == null) || (height == '')) {
 		         //height = 500;		 
				 //}	
				height = 575; 
				iframe_width = width-40;
				iframe_height = height-90;				 
								 
				if (iphone) {
				  width = "100%"
					popup_left = "left:0;"
					popup_top = "top:0;"										
				} else {
				  margin_top = height / 2;
					margin_left = width / 2;
				}
				var modal = "<div id='popup_iframe' class='modal-window' style='width:" + width + "px; height:" + height + "px; margin-top:-" + margin_top + "px; margin-left:-" + margin_left + "px;"+popup_left+popup_top+"'>";
				modal += "<div></div>";
				modal += "</div>";			
				$('body').append(modal);
				var content = "<img id='loading' src='/images/loading.gif' alt='Loading'/><iframe id='popup_container' width='"+iframe_width+"' height='"+iframe_height+"' frameborder='0' scrolling='auto' allowtransparency='true' src='"+location+"'></iframe><hr /><input type='button' class='cancel' value='Close' />";
				$('#popup_iframe div').html(content);
				$('#popup_container').ready(function() {$('#loading').remove();});		
    		//IF THE FORM WAS SUBMITTED, RELOAD THE PARENT PAGE ONLY ON CLOSE ???????????????????????
				$('input[type=submit]').click(function() {alert('success');success = true;})				    						
				//BIND POPUP CLOSE
				$('.modal-window div .cancel').click(function(){
				    popupClose(success);				
				});					
		}		
		
		function resetFAQs() {
		  $('#faqs').fadeOut();
		  $('#topic select option[value=0]').attr('selected', 'selected');
		}		
		
		function changeFAQs(option) {						 
	   if (option != 0) {
	       $('#faqs ul').hide();		 
   	     $('#faqs').show();				 			 
		     option = '#faq_'+option;		 
    	   $(option).show();		
		 } else {
   	     $('#faqs').hide();				 	 
		 }	
		}
		
$(document).ready(function(){    
		//IF IS LOGIN PAGE, FOCUS THE FIRST INPUT FIELD
		$('#login #un').focus();
    
    //ROTATE BANNER IMAGES    
    numImages = $('#banner img.background').size();
    imageInterval = window.setInterval("changeImage()", 8000);		
		
		//SET UP THE MENU
    $('#menu li.parent').hover(
		function()  {
		    $(this).children('a').addClass('menu_parent_hover');
		},
		function () {		    
        $(this).children('a').removeClass('menu_parent_hover');
				jsddm_close();		   
		});					
		
		//BIND POPUP CLICK
		$('.open_popup').click(function() {
		  var location = $(this).attr('href');
		  var rel = $(this).attr('rel');		
			popupOpen(location, rel);
			return false;
		});																		
		
		//PREVENT DISABLED LINKS FROM WORKING
		$('.disabled, .disabled a, a.open_popup').click(function () {return false;});
				
		//MAKE THE PAGE TURN		
    //$('#target').fold();
		
		//CHANGE SEARCH VALUE
		$('#search input').blur(function() {
				if ($(this).val() == '') {
				  $(this).val('Search site');
				}		
		});
		$('#search input').focus(function() {			
				if ($(this).val() == 'Search site') {
				  $(this).val('');
				}		
		});						
		
		//ANIMATE THE GORILLA AND SHOW HIS TIPS ON HOVER
		$('#rigby').hover(function() {$(this).children('p').show();$(this).children('img').show();}, function() {$(this).children('p').hide();$(this).children('img').hide();});		
					
		//RESET THE CONTACT FORM ON PAGE REFRESH 
		resetFAQs();
		
		//BIND FAQ CLOSE
		//$('#close_faq').click(function() {resetFAQs();});
		
		//BIND FAQ EXPAND
		$('#faqs ul li span').toggle(
		function() {$(this).next().show();$(this).parent().addClass('expanded');return false;},
		function() {$(this).next().hide();$(this).parent().removeClass('expanded');return false;}		
		);
		
		//CHANGE THE CONTACT FORM FAQS BASED ON TOPIC
	  $('#topic select').change(function () {var option = $(this).children('option:selected').attr('value');changeFAQs(option); });
		
		//SHOW AND HIDE DIFFERENT TIMELINE DATA
		$('#timeline select').change(function() {
								var option = $(this).children('option:selected').attr('value');
								$('#timeline .timeline_data').hide();
								$('#'+option).show();								
		});
			
    //ANIMATE THE TIMELINE ON REFRESH
    $("#progress_bar").progressBar(current_progress);			
			
		//RESET TIMELINE TO PROGRAMME ON REFRESH
		$('#timeline select option[value=programme]').attr('selected', 'selected');		
	
});
	
/*
 * jQuery Progress Bar plugin
 * Version 2.0 (06/22/2009)
 * @requires jQuery v1.2.1 or later
 *
 * Copyright (c) 2008 Gary Teo
 * http://t.wits.sg
*/
(function($) {
	$.extend({
		progressBar: new function() {

			this.defaults = {
				steps			: 50,											// steps taken to reach target
				step_duration	: 40,											
				max				: 100,											// Upon 100% i'd assume, but configurable
				showText		: true,											// show text with percentage in next to the progressbar? - default : true
				textFormat		: 'fraction',									// Or otherwise, set to 'fraction'
				width			: 750,											// Width of the progressbar - don't forget to adjust your image too!!!												// Image to use in the progressbar. Can be a single image too: 'images/progressbg_green.gif'
				height			: 26,											// Height of the progressbar - don't forget to adjust your image too!!!
				callback		: null,											// Calls back with the config object that has the current percentage, target percentage, current image, etc
				boxImage		: '/images/progressbar2.gif',						// boxImage : image around the progress bar
				barImage		: {
									//0:	'/images/progressbar_red.png',
									0: '/images/progressbar_orange.png',
									30: '/images/progressbar_yellow.png',
									70: '/images/progressbar_green.png'
								},								
				// Internal use
				running_value	: 0,
				value			: 0,
				image			: null
			};
			
			/* public methods */
			this.construct = function(arg1, arg2) {
				var argvalue	= null;
				var argconfig	= null;
				
				if (arg1 != null) {
					if (!isNaN(arg1)) {
						argvalue = arg1;
						if (arg2 != null) {
							argconfig = arg2;
						}
					} else {
						argconfig = arg1; 
					}
				}
				
				return this.each(function(child) {
					var pb		= this;
					var config	= this.config;
					
					if (argvalue != null && this.bar != null && this.config != null) {
						this.config.value 		= argvalue
						if (argconfig != null)
							pb.config			= $.extend(this.config, argconfig);
						config	= pb.config;
					} else {
						var $this				= $(this);
						var config				= $.extend({}, $.progressBar.defaults, argconfig);
						config.id				= $this.attr('id') ? $this.attr('id') : Math.ceil(Math.random() * 100000);	// random id, if none provided
						
						if (argvalue == null)
							argvalue	= $this.html().replace("%","")	// parse percentage
						
						config.value			= argvalue;
						config.running_value	= 0;
						config.image			= getBarImage(config);
						
						//$this.html("");
						//var bar					= document.createElement('img');
						var text				= document.createElement('span');
						var $bar				= $('#progress_bar img');
						var $text				= $(text);
						pb.bar					= $bar;
						
						//$bar.attr('id', config.id + "_pbImage");
						$text.attr('id', config.id + "_pbText");
						$text.html(getText(config));
						//$bar.attr('title', 'Expedition programme progress');
						//$bar.attr('alt', getText(config));
						$bar.attr('src', config.boxImage);
						$bar.attr('width', config.width);
						$bar.css("width", config.width + "px");
						$bar.css("height", config.height + "px");
						$bar.css("background-image", "url(" + config.image + ")");
						$bar.css("background-position", ((config.width * -1)) + 'px 50%');
						$bar.css("padding", "0");
						$bar.css("margin", "0");
						//$this.append($bar);
						$this.append($text);
					}

					function getPercentage(config) {
						return config.running_value * 100 / config.max;
					}

					function getBarImage(config) {
						var image = config.barImage;
						if (typeof(config.barImage) == 'object') {
							for (var i in config.barImage) {
								if (config.running_value >= parseInt(i)) {
									image = config.barImage[i];
								} else { break; }
							}
						}
						return image;
					}
					
					function getText(config) {
						if (config.showText) {
							if (config.textFormat == 'percentage') {
								return "" + Math.round(config.running_value) + "% completed";
							} else if (config.textFormat == 'fraction') {
								return "" + Math.floor((programme_length-((config.running_value*programme_length)/100))) + ' days to go';
							}
						}
					}
					
					config.increment = Math.round((config.value - config.running_value)/config.steps);
					if (config.increment < 0)
						config.increment *= -1;
					if (config.increment < 1)
						config.increment = 1;
					
					var t = setInterval(function() {
						var pixels	= config.width / 100;			// Define how many pixels go into 1%
						var stop	= false;
						
						if (config.running_value > config.value) {
							if (config.running_value - config.increment  < config.value) {
								config.running_value = config.value;
							} else {
								config.running_value -= config.increment;
							}
						}
						else if (config.running_value < config.value) {
							if (config.running_value + config.increment  > config.value) {
								config.running_value = config.value;
							} else {
								config.running_value += config.increment;
							}
						}
						
						if (config.running_value == config.value)
							clearInterval(t);
						
						var $bar	= $("#" + config.id + "_pbImage");
						var $text	= $("#" + config.id + "_pbText");
						var image	= getBarImage(config);
						if (image != config.image) {
							$bar.css("background-image", "url(" + image + ")");
							config.image = image;
						}						
						$bar.css("background-position", (((config.width * -1)) + (getPercentage(config) * pixels)) + 'px 50%');
						$bar.attr('title', getText(config));
						$bar.attr('alt', getText(config));
						$text.html(getText(config));
						offset = (((665-config.width)) + (getPercentage(config) * pixels))
						if (offset < 5) {offset = 5;} 
						$text.css("left", offset + 'px');						
						
						if (config.callback != null && typeof(config.callback) == 'function')
							config.callback(config);
						
						pb.config = config;
					}, config.step_duration); 
				});
			};
		}
	});
		
	$.fn.extend({
        progressBar: $.progressBar.construct
	});
	
})(jQuery);

