jQuery.noConflict(); //the editor uses prototype so need to put it in noConflict

(function($){
	/* ########################################################################### *
	/* ***** DOCUMENT INFO  ****************************************************** *
	/* ########################################################################### *
	 * ##### NAME:  global.js
	 * ##### VERSION: v0.1
	 * ##### UPDATED: 10/01/2011 (Damian Keeghan - Deloitte's Online Practice)
	/* ########################################################################### *
	
	/* ########################################################################### *
	/* ***** INDEX *************************************************************** *
	/* ########################################################################### *
	/* ##### GLOBAL VARIABLES
	/* ##### INITIALISATION
	/* ##### VISUAL INITIALISATION
	/* ##### FUNCTIONAL INITIALISATION
	/* ##### MEDIA PLAYER
	/* ##### NEED ASSISTANCE TIMER
	/* ##### UTIL FUNCTIONS
	/* ########################################################################### */
	
	/* ########################################################################### *
	/* ##### GLOBAL VARIABLES
	/* ########################################################################### */
	
	var STATIC_ANIMATION = false;
	var BASIC_ANIMATION = false;
	
	/* ########################################################################### *
	/* ##### INITIALISATION
	/* ########################################################################### */
	
	$(document).ready(function(){
		init_visual();
		init_functional();
	});
	
	/* ########################################################################### *
	/* ##### VISUAL INITIALISATION
	/* ########################################################################### */
	
	function init_visual(){
		init_classHelpers();
		init_tabs();
		init_splashScreen();
		init_hintText();
		init_rotatingBanner();
		init_awards();
		init_leftNavigation();
		init_videoThumbnail();
		init_filters();
		init_expandcollapse();
		init_modulesHeight();
		init_togglePanels();
		init_highlightTable();
	}
	
	/* ########################################################################### *
	/* ##### FUNCTIONAL INITIALISATION
	/* ########################################################################### */
	
	function init_functional(){
		init_tooltip();
		init_loginNav();
		init_nav();
		init_shareViaEmail();
		init_rotatingTile();
		init_carousel();
		init_scrollTo();
		init_searchAutocomplete();
	}
	
	/* ########################################################################### *
	/* ##### CSS3 HELPER
	/* ########################################################################### */
	
	function init_classHelpers(){
		$("html").removeClass("noJS");
		
		if($("html").hasClass("ie7") || $("html").hasClass("ie6")){
			BASIC_ANIMATION = true;
			
			$("table caption.offscreen").each(function(){
				$(this).parent().addClass("adjustForOffscreen");
			});
			
			$("table thead tr:not('.offscreen'):last-child th, table thead tr:not('.offscreen'):last-child td").addClass("thead");
			
			init_ie8_classes();	
		} else if($("html").hasClass("ie8")){
			init_ie8_classes();
		};
		
	}
	
	function init_ie8_classes(){
		$("li:last-child, tr:last-child").each(function(){
			$(this).addClass("last");
		});
		
		$("table").each(function(){
			$(this).find("tr:odd").addClass("odd");
			$(this).find("tr:even").addClass("even");
		});
		
		$(".fn_alternating").each(function(){
			$(this).find("li:odd").addClass("odd");
			$(this).find("li:even").addClass("even");	
		});
		
		$("#form fieldset").each(function(i){
			if(i%2==0){
				$(this).addClass("even");	
			} else {
				$(this).addClass("odd");
			}
		});
		
		//selectbox width fix - IE only issue
		$("select").each(function(){
			var $select = $(this);
			
			var currentWidth = $select.width();
			$select.addClass("autoWidth");
			
			var autoWidth = $select.width();
			$select.removeClass("autoWidth");
			
			var onFocus = function(event){
				$select.parent().height($select.parent().height()).addClass("relative");
				var selectPos = $select.position();
				$select.addClass("autoWidth").css({"left": selectPos.left, "top": selectPos.right});
				$select.parent().find(".inlineError").css("float", "right");
				
				if(event.type=="focus" || event.type=="onfocus"){
					$select.unbind("mouseout", onBlur);
					$select.data("focused", true);	
				}
			}
			
			var onBlur = function(event){
				$select.parent().height("").removeClass("relative");
				$select.removeClass("autoWidth").css({"left": "", "top": ""});
				$select.parent().find(".inlineError").css("float", "");
				
				$select.bind("focus", onFocus);	
				
				if(event.type=="blur" || event.type=="onblur"){
					$select.bind("mouseout", onBlur);
					$select.data("focused", false);	
				}
			}
			
			if(currentWidth < autoWidth){
				$select.bind("focus", onFocus);
				$select.bind("blur", onBlur);
				
				$select.bind("mouseover", onFocus);
				$select.bind("mouseout", onBlur);
			}
		});
	}
	
	function init_tooltip(){
		$("a.fn_tooltip").accessibleTooltip({
			topOffset: -2,
			leftOffset: 10,
			labelText: function(btn){
				return $(btn).parents(".ctrlHolder").find("label, .label").clone().children().remove().end().text().replace("*", "").replace(/^\s+|\s+$/g, '');	
			}
		});		
	}
	
	/* ########################################################################### *
	/* ##### SPLASH SCREEN
	/* ########################################################################### */
	
	function init_splashScreen(){
		if($("#splashscreen").length>0){
			var $bg = $("#splashscreen .bg");
			$bg.height($("body").height()).width($(window).width()).animate({"opacity": 0.8}, 0);
			
			var $content = $("#splashscreen .content");
			$content.find(".btnHolder .button").each(function(){
				if($(this).height()<30){
					$(this).addClass("single");	
				}
			});
			
			$("#splashscreen").bind("splashscreen.close", function(){
				$content.fadeOut(200, function(){
					$bg.fadeOut(150, function(){
						$("#splashscreen").remove();
					});
				});
			});
			
			$("#splashscreen").find(".content .fn_close, .bg").bind("click", function(){
				$("#splashscreen").trigger("splashscreen.close");
				return false;
			});
		}
	}
	
	/* ########################################################################### *
	/* ##### NAV
	/* ########################################################################### */
	
	function init_nav(){
		$(".fn_nav").each(function(){
			var $nav = $(this);
			var $items = $nav.find("li");
			
			$items.each(function(){
				var $item = $(this);
				var $link = $item.find("a:not(.megadd a)");
				var $megadd = $item.find(".megadd");
				
				var $megadd_link = $megadd.find("a");
				
				var MEGADD_TIMEOUT;
				var MEGADD_TIMEOUT_SPEED = 200;
				var MEGADD_ANIMATE_SPEED = 200;
				var MEGADD_ANIMATE_DELAY = 100;
				
				$megadd.addClass("offscreen").animate({"opacity": 0}, 0);
				
				// Display logic to make the mega dropdown look nice
				var rows = Math.ceil($megadd.find(".columns .col").length / 5);
				
				//if there are more than 1 row required, we need to add them
				for(var i = 1; i<rows; i++){
					$megadd.find(".columns").eq(0).after("<div class=\"columns clearfix\"></div>");
				}
				
				var row = 0;
				
				$megadd.find(".columns .col").each(function(i, el){
					var $col = $(el);
					
					if(i>0 && i%5==0){
						row++;
					}
					
					if(row>0){
						var clone = $col.clone();
						$col.remove();
						$megadd.find(".columns").eq(row).append(clone);	
					}
				})
				
				// Animation logic for showing and hiding the mega dropdown
				var showMegaDD = function(){
					$("#contentColumn .youtube-player").parent().css("visibility", "hidden");
					$nav.data("animating", true);
					
					$megadd.stop().delay(MEGADD_ANIMATE_DELAY).removeClass("offscreen").animate({"opacity": 1}, MEGADD_ANIMATE_SPEED, function(){
						$nav.data("animating", false);
					});
				}
				
				var hideMegaDD = function(){
					$megadd.stop().animate({"opacity": 0}, 0, function(){
						if($nav.data("animating")==false){
							$("#contentColumn .youtube-player").parent().css("visibility", "visible");
						}
						$megadd.addClass("offscreen");
					});
				}
				
				$item.hoverIntent({
					timeout: 250,
					over: showMegaDD,
					out: hideMegaDD
				});
				
				$item.find("a").bind("focus", function(){
					try{
						clearTimeout(MEGADD_TIMEOUT);	
						MEGADD_TIMEOUT = null;
					} catch(e){}
					
					$megadd.stop().delay(MEGADD_ANIMATE_DELAY).removeClass("offscreen").animate({"opacity": 1}, MEGADD_ANIMATE_SPEED);	
				});
				
				$item.find("a").bind("blur", function(){
					try{
						clearTimeout(MEGADD_TIMEOUT);	
						MEGADD_TIMEOUT = null;
					} catch(e){}
					
					MEGADD_TIMEOUT = setTimeout(hideMegaDD, MEGADD_TIMEOUT_SPEED);
				});
			});
		});
	}
	
	/* ########################################################################### *
	/* ##### TABS
	/* ########################################################################### */
	
	function init_tabs(){
		var ANIMATION_FADEIN = 200; //speed for animated fade in (ms)
		var ANIMATION_FADEOUT = 200; //speed for animated fade out (ms)
		var MARGIN_BOTTOM = 60; //includes nav height
		
		$(".fn_tabs").each(function(){
			var container = $(this);
			$(container).removeClass("fn_tabs");
			
			$(container).prepend("<ul class=\"nav clearfix\"></ul>");
			var navigation = $(container).find(".nav");
			
			var activeTab = null;
			var isAnimating = false;
			
			var hideActiveTab = function(id, callback){
				if(activeTab==null){
					callback();
				} else {
					if(id!=activeTab.id){
					
						$(activeTab.listItem).removeClass("active");
						
						$(activeTab.tab).stop().animate({"opacity": 0}, ANIMATION_FADEOUT, function(){
							$(activeTab.tab).addClass("offscreen");
							callback();	
						});	
					} else {
						isAnimating = false;
					}
				}
			}
			
			var tabActions = function(){
				var containerHeight = $(container).data("maxHeight") + $(navigation).height() + MARGIN_BOTTOM;
				if($(container).hasClass("inlineText")==false){
					$(container).css("height", containerHeight+"px");
				}
				
				$(navigation).find("li").each(function(index){
					var listItem = $(this);
					var button = $(listItem).find("a");
					var id = $(button).attr("href");
					
					id = id.substring(id.indexOf("#"), id.length);
					
					$(button).bind("click", function(event){
						event.preventDefault();
						
						if(isAnimating==false){
							isAnimating = true;
							
							$(listItem).addClass("active");
							hideActiveTab(id, function(){
								$(id).stop().removeClass("offscreen").animate({"opacity": 1}, ANIMATION_FADEIN, function(){
									isAnimating = false;							  
									activeTab = {id: id, tab: $(id), listItem: $(listItem)};
								});
							});
							
							var tempId = id.replace("#", "temp_");
							$(id).attr("id", tempId);
							$("#"+tempId).attr("id", id.replace("#", ""));
						}
						
						return false;								 
					});
					
					if(($(container).find(".tab.active").length>0 && $(id).hasClass("active")) || ($(container).find(".tab.active").length==0 && index==0)){
						activeTab = {id: id, tab: $(id), listItem: $(listItem)};
						$(listItem).addClass("active");
					}
				
				});	
			}
			
			$(container).data("maxHeight", 0);
			var tabLength = $(container).find(".tab").length;
			
			$(container).find(".tab").each(function(index){
				var tab = $(this);
				var id = $(tab).attr("id");
				var title = "";
				
				if($(container).hasClass("inlineText")){
					title = $(tab).find("h4").text();
				} else {
					title = $(tab).find("h2").text();
				}
				
				var activeIsSet = ($(container).find(".tab.active").length > 0);
				var activeTab = ((activeIsSet && $(tab).hasClass("active")) || !activeIsSet && index == 0) ? true : false;
				
				//hide h2
				if($(container).hasClass("inlineText")){
					$(tab).find("h4").hide();
					
					$(navigation).append("<li><h4><a href=\"#"+id+"\">"+title+"</a></h4></li>");
				} else {
					$(tab).find("h2").hide();
					
					$(navigation).append("<li><h2><a href=\"#"+id+"\">"+title+"</a></h2></li>");
				}
				
				var tabHeight = $(tab).height();
				$(tab).data("tabHeight", tabHeight);
				
				if(tabHeight > $(container).data("maxHeight")){
					$(container).data("maxHeight", tabHeight);	
				}
				
				if(!activeTab){
					$(tab).addClass("offscreen").animate({"opacity": 0}, 0);
				}
				
				if(index==tabLength-1){
					tabActions();
	
					$(navigation).find("li:first-child").addClass("first");
					$(navigation).find("li:last-child").addClass("last");
				}
			});		
		}); 	
	}

// Display prompt by creating a span over the top
	function init_hintText(){
		$(".fn_hint").each(function(i){
                 $(this).addClass('input-prompt-' + i);
                var promptSpan = $('<span class="input-prompt text hint"/>');
                $(promptSpan).attr('id', 'input-prompt-' + i);
                $(promptSpan).append($(this).attr('title'));
                $(promptSpan).click(function(){
                    $(this).hide();
                    $('.' + $(this).attr('id')).focus();
                });
                if($(this).val() != ''){
                    $(promptSpan).hide();
                }
                $(this).before(promptSpan);
                $(this).focus(function(){
                    $('#input-prompt-' + i).hide();
                });
                $(this).blur(function(){
                    if($(this).val() == ''){
                    $('#input-prompt-' + i).show();
                    }})
            });
        }

//			if($(this).attr("title")){
//				$(this).data("hintText", $(this).attr("title"));
//				
//				if($(this).attr("value")=="" || $(this).attr("value")==$(this).data("hintText")){
//					$(this).attr("value", $(this).data("hintText")).addClass("hint");	
//				}
//				
//				$(this).focusin(function(){
//					if ($(this).attr("value") == $(this).data("hintText")) {
//						$(this).attr("value", "").removeClass("hint");
//					}
//				}).focusout(function(){
//					if ($.trim($(this).attr("value")) == "" || $(this).attr("value")==$(this).data("hintText")) {
//						$(this).attr("value", $(this).data("hintText")).addClass("hint");
//					}
//				});
//			}
//		});	
//	}
	
	function init_leftNavigation(){
		$("#leftColumn li.active > a").append(document.createElement("div"));	
	}
	
	function init_loginNav(){
		var $panel = $("#login");
		var $button = $(".fn_nav_login");
		
		$panel.data("open", false).data("animating", false);
		
		$panel.bind("panel.open", function(){
			$button.parent().addClass("open");
			
			if($("html").hasClass("ie7")){
				$panel.removeClass("offscreen");
				$panel.find("button span").css("zoom", 0);
				$panel.data("animating", false).data("open", true);
			} else {
				$panel.hide().removeClass("offscreen").slideDown(250, function(){
					$panel.find("button span").css("zoom", 0);
					$panel.data("animating", false).data("open", true);
				});
			}
		});
		
		$panel.bind("panel.close", function(){
			if($("html").hasClass("ie7")){
				$panel.find("button span").css("zoom", 0);
				$panel.data("animating", false).data("open", false).addClass("offscreen");
				
				$button.parent().removeClass("open");
				$button.trigger("blur");
			} else {
				$panel.slideUp(250, function(){
					$panel.find("button span").css("zoom", 0);
					$panel.data("animating", false).data("open", false).addClass("offscreen").show();
					
					// this is a really silly display bug, but haven't been able to resolve any other way
					if($("html").hasClass("webkit")){
						var size = $("#contentHeader h1").css("font-size");
						$("#contentHeader h1").css("font-size", 0);
						setTimeout(function(){
							$("#contentHeader h1").css("font-size", size);
						}, 1);
					}
					
					$button.parent().removeClass("open");
					$button.trigger("blur");
				});
			}
		});
		
		$panel.bind("panel.toggle", function(){
			//only allow the button to be enabled if it isn't currently animating
			if($panel.data("animating")==false){
				$panel.data("animating", true);
				
				if($panel.data("open")){
					$panel.trigger("panel.close");
				} else {
					$panel.trigger("panel.open");
				}
			}
		});
		
		$button.bind("click", function(){
			$panel.trigger("panel.toggle");
				
			return false;
		});	
	}
	
	function init_shareViaEmail(){
		$(".fn_shareViaEmail").each(function(){
			var $link = $(this);
			var id = $link.attr("href");
			var $panel = $(id);
			
			$panel.data("open", false).data("animating", false).wrap("<div id='"+id.replace("#", "panelcontainer_")+"' />");
			$panelContainer = $panel.parent();
			
			if($panelContainer.find(".errors li, .success").length>0){
				$panel.data("open", true);
			} else {
				$panelContainer.addClass("offscreen");
				$panel.animate({"opacity": 0}, 0); 
			}
			
			$panel.bind("panel.open", function(){
				$panelContainer.hide().removeClass("offscreen").slideDown(250, function(){
					$panel.animate({"opacity": 1}, 250, function(){
						$panel.data("animating", false).data("open", true);
					});
				});
			});
			
			$panel.bind("panel.close", function(){
				$panel.animate({"opacity": 0}, 250, function(){
					$panelContainer.slideUp(250, function(){
						$panel.data("animating", false).data("open", false);
						$panelContainer.addClass("offscreen").show();
					});
				});
			});
			
			$panel.bind("panel.toggle", function(){
				//only allow the button to be enabled if it isn't currently animating
				if($panel.data("animating")==false){
					$panel.data("animating", true);
					
					if($panel.data("open")){
						$panel.trigger("panel.close");
					} else {
						$panel.trigger("panel.open");
					}
				}
			});
			
			$panel.find(".fn_close").bind("click", function(){
				if($panel.data("animating")==false){
					$panel.data("animating", true);
					
					$panel.trigger("panel.close");
				}
				
				return false;
			});
			
			$link.bind("click", function(){
				$panel.trigger("panel.toggle");
				
				return false;
			});
		});
	}
	
	function init_scrollTo(){
		$(".fn_scrollTo").bind("click", function(){
			$.scrollTo($(this).attr("href"), {
				duration: 100	
			});	
			
			$(this).trigger("blur");
			
			return false;
		});
		
		$(".backToTop").bind("click", function(){
			$.scrollTo("0", {
				duration: 100	
			});	
			
			$(this).trigger("blur");
			$("#accessibleLinks").trigger("focus");
			
			return false;	
		});
	}
	
	function init_modulesHeight(){
		$(".fn_modules_height").each(function(){
			var maxheight = 0;
			var $modules = $(this).find(".module");
		
			$modules.each(function(){
				var $module = $(this);
				maxheight = ($module.height() > maxheight) ? $module.height() : maxheight;
			});
			
			$modules.height(maxheight);	
		});	
	}
	
	function init_rotatingTile(){
		$(".fn_rotatingTile_homepage").each(function(){
			var $this = $(this);
			$this.removeClass("fn_rotatingTile_homepage"); //removed functional class so it doesn't run again
			
			//init controls buttons
			var $nextBtn = $this.find(".controls .next");
			var $prevBtn = $this.find(".controls .previous");
			
			var currentIndex = 0;
			
			var $container = $this.find(".controls + ul");
			var $items = $container.find("li:not(li li)");
			var numItems = $items.length;
			
			if(!BASIC_ANIMATION){
				$items.each(function(i){
					if(i>0){
						$(this).stop().animate({"opacity": 0.2}, 1);	
					}
				});
			}
			
			if(numItems>1){
				//init container and overall width, so we can use percentages to adjust location
				
				$container.width(numItems * $this.width());	
				//bind rotating tile functionality
				$this.bind("tile.next", function(){
					var $prevItem = $($items[currentIndex]);
					currentIndex = (currentIndex + 1 >= numItems) ? 0 : currentIndex + 1;
					var $nextItem = $($items[currentIndex]);
					
					$this.trigger("tile.animate", [$prevItem, $nextItem]);
				});
				
				$this.bind("tile.prev", function(){
					var $prevItem = $($items[currentIndex]);
					currentIndex = (currentIndex - 1 < 0) ? numItems-1 : currentIndex - 1;
					var $nextItem = $($items[currentIndex]);
					
					$this.trigger("tile.animate", [$prevItem, $nextItem]);
				});
				
				$this.bind("tile.animate", function(event, $prevItem, $nextItem){
					if(!BASIC_ANIMATION){
						$prevItem.stop().animate({"opacity": 0.2}, 150);
						$nextItem.stop().delay(200).animate({"opacity": 1}, 150);
					}
					
					//using percentage so we can use the index to simply adjust the left margin
					$container.stop().animate({"margin-left": (-currentIndex * 100) + "%"}, 300);
				});
				
				$nextBtn.bind("click", function(){
					$this.trigger("tile.next");
					return false;	
				});
				
				$prevBtn.bind("click", function(){
					$this.trigger("tile.prev");
					return false;	
				});
			} else {
				$this.find(".controls").hide();	
			}
		});	
	}
	
	function init_carousel(){
		$(".fn_carousel").each(function(){
			var NUM_DISPLAYED = 4;
			var SPEED = 300;
			
			var $this = $(this);
			$this.removeClass("fn_carousel"); //removed functional class so it doesn't run again
			
			var num = $this.data("carousel-display");
			if(num!=null && isNaN(parseInt(num))==false){
				NUM_DISPLAYED = parseInt(num);	
			}
			
			var speed = $this.data("carousel-speed");
			if(speed!=null && isNaN(parseFloat(speed))==false){
				SPEED = parseFloat(speed)*1000;	
			}
			
			//init controls buttons
			var $nextBtn = $this.find(".controls .next");
			var $prevBtn = $this.find(".controls .previous");
			
			var currentIndex = 0;
			
			var $container = $this.find(".controls + .carousel > ul");
			var $items = $container.find("li:not(li li)");
			var numItems = $items.length;
			
			if(numItems>NUM_DISPLAYED){
				//init container and overall width
				var $secondItem = $this.find(".controls + .carousel > ul > li:nth-child(2)");
				$items.width($secondItem.width());
				
				$container.width((numItems * $secondItem.width()) + (numItems * parseInt($secondItem.css("margin-left").replace("px", ""))));
				
				var amountToMove = $secondItem.width() + parseInt($secondItem.css("margin-left").replace("px", ""));
					
				//bind rotating tile functionality
				$this.bind("tile.next", function(){
					var $prevItem = $($items[currentIndex]);
					currentIndex = (currentIndex + 1 >= numItems - (NUM_DISPLAYED-1)) ? 0 : currentIndex + 1;
					var $nextItem = $($items[currentIndex]);
					
					$this.trigger("tile.animate", [$prevItem, $nextItem]);
				});
				
				$this.bind("tile.prev", function(){
					var $prevItem = $($items[currentIndex]);
					currentIndex = (currentIndex - 1 < 0) ? numItems-(NUM_DISPLAYED) : currentIndex - 1;
					var $nextItem = $($items[currentIndex]);
					
					$this.trigger("tile.animate", [$prevItem, $nextItem]);
				});
				
				$this.bind("tile.animate", function(event, $prevItem, $nextItem){
					$container.stop().animate({"margin-left": (-currentIndex * amountToMove) + "px"}, SPEED, function(){
						$this.trigger("tile.animate.complete");
					});
				});
				
				$nextBtn.bind("click", function(){
					$this.trigger("tile.next");
					$this.data("carousel-direction", "next");
					return false;	
				});
				
				$prevBtn.bind("click", function(){
					$this.trigger("tile.prev");
					$this.data("carousel-direction", "prev");
					return false;	
				});
			} else {
				$this.find(".controls").hide();	
			}
			
			var delay = $this.data("carousel-delay");
			if(delay!=null && isNaN(parseFloat(delay))==false){
				delay = parseFloat(delay);
				
				$this.data("carousel-direction", "next");
				
				var AUTOPLAY_TIMEOUT;
				
				var viewNext = function(){
					resetNext();
					
					AUTOPLAY_TIMEOUT = setTimeout(function(){
						$this.trigger("tile."+$this.data("carousel-direction"));	
					}, delay*1000);
				}
				
				var resetNext = function(){
					try{
						clearTimeout(AUTOPLAY_TIMEOUT);
						AUTOPLAY_TIMEOUT = null;
					}catch(e){}	
				}
				
				$this.bind("tile.animate.complete", viewNext);
				$this.bind("tile.animate", resetNext);
				
				viewNext();
			}
		});	
	}
	
	/* ########################################################################### *
	/* ##### ROTATING BANNER
	/* ########################################################################### */
	
	function init_rotatingBanner(){
		$(".fn_rotatingBanner").rotatingBanner({
			showPlayPause: false,
			fadeTimer: 500
		});
	}
	
	function init_awards(){
		$(".fn_awards").each(function(){
			var AWARDS_TIMEOUT;
			var AWARDS_TIMER_WAIT = 5000;
			var AWARDS_TIMER_ANIMATE = 500;
			
			var $container = $(this);
			
			var $list = $container.find("ul");
			var $items = $list.find("li");
			
			var width = 0;
			var maxheight = 0;
			
			var groups = [];
			var groupIndex = 0;
			
			if($items.length>2){
			
				$items.each(function(i){
					var $item = $(this);
					
					width += $item.width() + parseInt($item.css("margin-left").replace("px", ""));
					
					if(i%2==0){
						groups.push([$item, $item.next()]);
					}
					
					if(i>1){
						$item.animate({"opacity": 0}, 0).addClass("offscreen");
					}
					
					maxheight = ($item.height() > maxheight) ? $item.height() : maxheight;
				});
				
				$list.width(width);
				
				$container.height(maxheight);
				
				var animateOutAwards = function(){
					if($list.find("li:not(.offscreen)").length>0){
						$list.find("li:not(.offscreen)").each(function(){
							$(this).animate({"opacity": 0}, AWARDS_TIMER_ANIMATE, function(){
								$(this).addClass("offscreen");	
							});
						});
						
						setTimeout(animateInAwards, AWARDS_TIMER_ANIMATE);
					} else {
						animateInAwards();
					}	
				}
				
				var animateInAwards = function(){
					var arr = groups[groupIndex];
					for(var i in arr){
						var $award = $(arr[i]);
						$award.removeClass("offscreen").animate({"opacity": 1}, AWARDS_TIMER_ANIMATE);
					}
					
					groupIndex = (groupIndex==(groups.length-1)) ? 0 : groupIndex + 1;
					
					waitToAnimateAwards();
				}
				
				var waitToAnimateAwards = function(){
					try{
						clearTimeout(AWARDS_TIMEOUT);
						AWARDS_TIMEOUT = null;
					} catch(e){}
					
					AWARDS_TIMEOUT = setTimeout(animateOutAwards, AWARDS_TIMER_WAIT);
				}
				
				animateInAwards();
			}
		});	
	}
	
	function init_videoThumbnail(){
		$(".fn_videoThumbnail").each(function(){
			var $this = $(this);
			$this.removeClass("fn_videoThumbnail");
			
			$this.wrap("<div class=\"videoThumbnail\"></div>");
			
			var $videoThumbnail = $this.parent();
			$videoThumbnail.prepend(document.createElement("div"));	
		
			var floatType = $this.css("float");
			$this.css("float", "none");
			$videoThumbnail.css({"float": floatType});
			
			var margin = $this.css("margin-top")+" "+$this.css("margin-right")+" "+$this.css("margin-bottom")+" "+$this.css("margin-left");
			$this.css("margin", "0 0 0 0");
			$videoThumbnail.css({"margin": margin});
			
			var $parentLink = $videoThumbnail.parent("a");
			
			
			if($this.hasClass("large")){
				$videoThumbnail.addClass("large");
				
				$parentLink.hover(function(){
					$parentLink.find("img").stop().fadeTo(100, 0.8);
				}, function(){
					$parentLink.find("img").stop().fadeTo(100, 1);
				});	
			}
		});
		
		//regex script to split out the variables from the URL query string
		var getQuery = function(s) {
		  var query = {};
		
		  s.replace(/\b([^&=]*)=([^&=]*)\b/g, function (m, a, d) {
			if (typeof query[a] != 'undefined') {
			  query[a] += ',' + d;
			} else {
			  query[a] = d;
			}
		  });
		
		  return query;
		}

		$(".fn_inlineVideo").each(function(){
			var $this = $(this);
			
			var videoQuery = $this.attr("href");
			if(videoQuery.indexOf("?v=") > -1 || videoQuery.indexOf("&v=") > -1){
			
				videoQuery = getQuery(videoQuery.substring(videoQuery.indexOf("?")))
				
				$this.bind("click", function(){
					$this.removeAttr("href").removeClass("fn_inlineVideo");
					
					var w = $this.find("img").width();
					var h = $this.find("img").height();
					
					$this.css("display", "block").width(w).height(h).children().fadeOut(250, function(){
						$this.html("<iframe class=\"youtube-player\" type=\"text/html\" width=\""+w+"\" height=\""+h+"\" src=\"http://www.youtube.com/embed/"+videoQuery.v+"?autoplay=1\" frameborder=\"0\"></iframe>");
					});
					
					return false;
				});
			
			}
			
			
		});
	}
	
	function init_filters(){
		$(".fn_filters").each(function(){
			$(this).removeClass("fn_filters");
			
			var $container = $(this);
			var $filters = $container.find(".filter");
			var $selectbox = $container.find(".controls select");
			
			var maxHeight = 0;
			
			$filters.each(function(){
				var $filter = $(this);
				
				var title = $filter.find("h2").text();
				$filter.data("title", title);
				
				var $option = $(document.createElement("option"));
				$option.attr("value", title).text(title);
				$selectbox.append($option);
				
				maxHeight = ($filter.height() > maxHeight) ? $filter.height() : maxHeight;
			});
			
			maxHeight = maxHeight + 20;
			$container.css("min-height", maxHeight);
			
			$selectbox.bind("change", function(){
				var selected = $(this).find("option:selected").attr("value");
				
				if(selected=="all"){
					$filters.hide().removeClass("offscreen").fadeIn(200);	
				} else {
					$filters.each(function(){
						var $filter = $(this);
						
						if($filter.data("title")==selected){
							$filter.delay(250).hide().removeClass("offscreen").fadeIn(200);
						} else {
							$filter.fadeOut(200, function(){
								$filter.addClass("offscreen").show().css("filter", null);	
							});	
						}
					});	
				}
			});
		});	
	}
	
	function init_expandcollapse(){
		$(".fn_expandcollapse").each(function(){
			$(this).removeClass("fn_expandcollapse");
			
			var $container = $(this);
			var $sections = $container.find(".section");
			
			$sections.each(function(){
				var $section = $(this);
				var title = $section.find("h2").wrapInner("<a href=\"#\"></a>");
				
				$section.data("animating", false);
				
				$section.children().not("h2").wrapAll("<div class=\"container\"></div>");
				
				var $container = $section.find(".container");
				
				if($section.hasClass("active")==false){
					$container.animate({"opacity": 0}, 1).addClass("offscreen");	
				}
				
				$section.bind("panel.open", function(){
					$section.addClass("active");
					$container.hide().removeClass("offscreen").stop().slideDown(200, function(){
						$container.animate({"opacity": 1}, 150, function(){
							$section.data("animating", false);	
						});	
					});
				});
				
				$section.bind("panel.close", function(){
					$section.removeClass("active");
					$container.stop().animate({"opacity": 0}, 150, function(){
						$container.slideUp(200, function(){
							$container.addClass("offscreen").show();
							$section.data("animating", false);	
						});
					});
				});
				
				$section.find("h2 a").bind("click", function(){
					if($section.data("animating")==false){
						$section.data("animating", true);
						
						if($section.hasClass("active")){
							$section.trigger("panel.close");
						} else {
							$section.trigger("panel.open");
						}
					}
					
					return false;
				});
				
			});	
		});		
	}
	
	function init_togglePanels(){
		var simpleAnimation = ($("html").hasClass("ie8") || $("html").hasClass("ie7") || $("html").hasClass("ie6"));
		
		$(".fn_toggle").each(function(i){
			var $this = $(this);
			$this.removeClass(".fn_toggle");
			
			var $controls = $this.find(".fn_toggle_controls");
			
			var groupName = "toggle_group_"+i;
			
			//create controls
			$controls.append('<div class="ctrlHolder fn_toggle_items"><span class="label">View as</span><ul class="options horizontal"></ul></div>');
			
			var togglePanel = function(containerId){
				var $notItem = $this.find(".fn_toggle_container > div:not(#"+containerId+")");
				var $item = $("#"+containerId);
				
				if(simpleAnimation){
					$notItem.addClass("offscreen");
					$item.removeClass("offscreen");
				} else {
					$notItem.stop().animate({"opacity": 0}, 150, function(){
						$notItem.addClass("offscreen");	
						
						$item.removeClass("offscreen").stop().animate({"opacity": 1}, 150);			
					});
				}
			}
			
			var $items = $this.find(".fn_toggle_container > div");
			$items.each(function(j, el){
				var $item = $(el);
				var containerId = $item.attr("id");
				
				var label = $item.data("toggle-label");
				var itemId = groupName + "_item_"+j;
				
				var checked = (j==0) ? 'checked="checked"' : '';
				
				$controls.find(".fn_toggle_items ul.options").append('<li><input type="radio" name="'+groupName+'" id="'+itemId+'" '+checked+' /><label for="'+itemId+'">'+label+'</label></li>');
				
				$controls.find("#"+itemId).bind("change", function(){
					togglePanel(containerId);	
				});
				
				if(j>0){
					if(simpleAnimation){
						$item.addClass("offscreen");
					} else {
						$item.addClass("offscreen").animate({"opacity": 0}, 0);	
					}
				}
			});	
		});
	}
	
	function init_highlightTable(){
		$(".fn_highlightTable").tableHover({
			rowClass: 'hover',
			colClass: 'hover',
			cellClass: 'hovercell',
			ignoreCols: [1]
		}); 
	}
	
	function init_searchAutocomplete(){
		var boldRegExp = new RegExp('<strong>(.*)</strong>');
		var urlRegExp = new RegExp('href="([^"]*)"');

		if (window.fb_completion && window.fb_completion.enabled == 'enabled' ) {
			jQuery('.fn_autocomplete_search').autocomplete( {
				source: function (request, response) {
					jQuery.ajax({
						type:       'GET',
						url:        window.fb_completion.program
										+ '?collection=' + window.fb_completion.collection
										+ '&partial_query=' + request.term.replace(/ /g, '+')
										+ '&show=' + window.fb_completion.show
										+ '&sort=' + window.fb_completion.sort
										+ '&alpha=' + window.fb_completion.alpha
										+ '&fmt=json'
						,
						dataType:   'json',
						success:    function(data) {
							// Suggestions from padre-qs
							var dynamics = new Array();
							// Suggestions from a static list
							var statics = new Array();

							var regex = new RegExp(request.term, 'i');

							// Boldicize search term
							var replacement = '<strong>' + request.term + '</strong>';
		 
							for (var i=0; i<data.length; i++) {
								var out;
								var suggestion = data[i];

								if (suggestion.u) {
									// Has URL field, static suggestion
									var word = suggestion.s.replace(regex, replacement);
									if (suggestion.t) { word = suggestion.t; } 
									out = '<a class="url" href="' + suggestion.u + '">' + word + '</a>';

									if (suggestion.d) { out += '<a class="description"><span>' + suggestion.d + '</span></a>'; }

									statics.push(out);
								} else {
									// Dynamic suggestion
									out = suggestion.replace(regex, replacement);
									dynamics.push(out);
								}
							}
							response (dynamics.concat(statics));
						}
					});
				},

				delay: window.fb_completion.delay,

				minLength: window.fb_completion.length,

				focus: function(evt, ui) {
					// Don't replace input value if suggestion contains an URL
					if (ui.item.value.search(/href/) > -1) { return false; }
					// Un-boldicize
					ui.item.value = ui.item.value.replace(boldRegExp, '$1');
				},

				select: function(evt, ui) {
					if (ui.item.value.search(/href/) > -1) {
						// If suggestion contains an URL, navigate to it
						document.location.href = ui.item.value.match(urlRegExp)[1];
						return false;
					}
					// Un-boldicize
					jQuery(this).attr('value', ui.item.value.replace(boldRegExp, '$1'));
					// Submit the form on select
					jQuery(this).context.form.submit();
				}
			});
		}
	}
	
	/* ########################################################################### *
	/* ##### PLUGINS
	/* ########################################################################### */
	
	jQuery.isIE = jQuery.fn.isIE = function(version, lessThan){
		version = (version==undefined) ? 6 : version;
		lessThan = (lessThan==undefined) ? false : lessThan;
		
		if(lessThan){
			if (($.browser.msie) && (parseInt($.browser.version)<=version)){
				return true;
			}
		} else {
			if (($.browser.msie) && (parseInt($.browser.version)==version)){
				return true;
			}
		}
		
		return false;	
	}
	
	jQuery.log = jQuery.fn.log = function (msg) {  
		  try{
			  if (window.console){  
				 console.log("%s: %o", msg, this);  
			  }  
		  } catch(e){
			//pokemon - gotta catch em all  
		  }
		  return this;  
	};
	
	/* ########################################################################### *
	/* ##### ROTATING BANNER
	/* ########################################################################### */
	
	/**
	 * jQuery.rotatingBanner - Accessible Rotating Images Banner Plugin.
	 * Copyright (c) 2009-2011 Damian Keeghan - dkeeghan@deloitte.com.au
	 * Date: 02/02/2010
	 * @author Damian Keeghan
	 * @version 1.5
	 *
	 */
	
	(function($){
		$.fn.rotatingBanner = function(options){
			var defaults = {
				fadeTimer: 1000,
				displayTimer: 7000,
				disabledTimer: 250,
				showPlayPause: true,
				showControls: true
			}
	
			var options = $.extend(defaults, options);
			
			return this.each(function(){
				var BANNER = $(this);
				var CONTAINER_ID = $(BANNER).attr("id");
				var BANNER_ID_PREFIX = CONTAINER_ID+"_banner_";
				
				var timeout;
				
				$.fn.rotatingBanner.currentBanners.push({id: CONTAINER_ID, banner: BANNER, timeout: timeout});
				
				$(BANNER).data("animationDisabled", false);
				$(BANNER).data("currentlyAnimating", false);
				
				var container = $(this).find(".fn_rotatingBanner_container");
				$(container).parent().append("<ul id=\""+CONTAINER_ID+"_controls\" class=\"bannerControls fn_rotatingBanner_controls clearfix\"></ul>");
				var controls = $(container).parent().find("ul.fn_rotatingBanner_controls");
				
				var NUM_BANNERS = $(container).find("li").length;
				
				if(NUM_BANNERS>0){
					
					if(NUM_BANNERS==1){
						$(controls).hide();
					}
					
					if(options.showControls==false){
						$(controls).hide();
					}
					
					var nextBannerId;
					
					$(controls).prepend("<li class=\"bannerControls_playPause\"><a href=\"#\" class=\"fn_rotatingBanner_playPause\"><span class=\"invisible\">?</span><span class=\"offscreen\">Toggle Banner Animation</span></a></li>");
					
					if(options.showPlayPause==false){
						$(controls).find(".bannerControls_playPause").hide();	
					}
					
					var i = NUM_BANNERS;
					$(container).find("li").each(function(){
						var bannerId = BANNER_ID_PREFIX+i;
						$(this).attr("id", bannerId);
						
						var controlClass = (i==1) ? "active " : "";
						
						if(i==1){
							$(this).addClass("active");
						}
						
						if(i==2){
							nextBannerId = "#"+bannerId;	
						}
						
						$(controls).prepend("<li class=\""+controlClass+"\"><a class=\"fn_rotatingBanner_updateBanner\" href=\"#\" rel=\"#"+bannerId+"\"><span class=\"offscreen\">Banner: </span>"+i+"</a></li>");
						
						i--;
					});
					
					var fn_enableControls = function(state){
						$(BANNER).data("currentlyAnimating", !state); 
						
						var opacity = (state) ? 1 : options.disabledAlpha;
						$(controls).animate({"opacity": opacity}, options.disabledTimer);	
					}
					
					var fn_getNextBanner = function(){
						var currentBannerIndex = Number(nextBannerId.replace("#"+BANNER_ID_PREFIX, ""));
						currentBannerIndex = (currentBannerIndex+1<=NUM_BANNERS) ? currentBannerIndex+1 : 1;
						
						nextBannerId = "#"+BANNER_ID_PREFIX+currentBannerIndex;
						
						if($(BANNER).data("animationDisabled")==false){
							timeout = setTimeout(fn_bannerAnimation, options.displayTimer);
						}
					}
					
					//Banner Animation Login
					var fn_bannerAnimation = function(){
						clearTimeout(timeout);
						
						if($(controls).find("li.active a").attr("rel")!=nextBannerId){
							$(controls).find("li.active").removeClass("active");
							$(controls).find("a[rel=\"#"+$(nextBannerId).attr("id")+"\"]").parent("li").addClass("active");
							
							fn_enableControls(false);
							
							var thisBanner = $(container).find("li.active");
			
							var nextBannerHTML = $(nextBannerId).outerHTML();
							$(nextBannerId).remove();
							$(thisBanner).before(nextBannerHTML);
							
							$(nextBannerId).removeClass("offscreen");
							
							$(thisBanner).animate({"opacity": 0}, options.fadeTimer, function(){
								//indicate that this banner is active
								$(nextBannerId).addClass("active");
								
								//swap DOM location of the current banner
								var thisBannerHTML = $(thisBanner).addClass("offscreen").animate({"opacity": 1}, 0).removeClass("active").clone();
								$(thisBanner).remove();
								$(container).prepend(thisBannerHTML);
								
								fn_enableControls(true);
								
								fn_getNextBanner();
							});
						}
					};
					
					//Banner Controls
					$(controls).find("a.fn_rotatingBanner_updateBanner").unbind("click").bind("click", function(){
						if($(this).hasClass("active")==false){
							if($(BANNER).data("currentlyAnimating")==false){
								nextBannerId = $(this).attr("rel");
								$(BANNER).data("animationDisabled", true);
								
								var playPause = $(controls).find("a.fn_rotatingBanner_playPause");
								if($(playPause).hasClass("play")==false){
									$(playPause).addClass("play");
								}
								
								fn_bannerAnimation();
							}
						}
						
						return false;					   
					});
					
					$(controls).find("a.fn_rotatingBanner_playPause").unbind("click").bind("click", function(){
						if($(this).hasClass("play")==false){
							if($(BANNER).data("currentlyAnimating")==false){
								$(this).addClass("play");
								
								clearTimeout(timeout);
								
								$(BANNER).data("animationDisabled", true);
							}
						} else {
							if($(BANNER).data("currentlyAnimating")==false){
								$(this).removeClass("play");
								
								$(BANNER).data("animationDisabled", false);
								fn_bannerAnimation();
							}
						}
						
						return false;											   
					});
					
					$(container).find("li:not(:last-child)").addClass("offscreen");
					$(container).find("li:last-child").addClass("active");
					
					if(NUM_BANNERS>1){
						timeout = setTimeout(fn_bannerAnimation, options.displayTimer);
					}
				}					  
			});
		}
		
		$.fn.rotatingBanner.currentBanners = [];
		
		$.fn.rotatingBanner.stopAnimation = function(){
			var bannersLength = $.fn.rotatingBanner.currentBanners.length;
			
			for(var i = 0; i<bannersLength; i++){
				var obj = $.fn.rotatingBanner.currentBanners[i];
				
				var playPause = $("#"+obj.id).find("ul.fn_rotatingBanner_controls a.fn_rotatingBanner_playPause");
				if($(playPause).hasClass("play")==false){
					$(obj.banner).data("currentlyAnimating", false);
					$(playPause).trigger("click");
				}
			}
		}
		
		$.fn.rotatingBanner.startAnimation = function(){
			var bannersLength = $.fn.rotatingBanner.currentBanners.length;
			
			for(var i = 0; i<bannersLength; i++){
				var obj = $.fn.rotatingBanner.currentBanners[i];
				var playPause = $("#"+obj.id).find("ul.fn_rotatingBanner_controls a.fn_rotatingBanner_playPause");
				if($(playPause).hasClass("play")==true){
					$(obj.banner).data("currentlyAnimating", false);
					$(playPause).trigger("click");
				}					
			}
		}
		
		//Gets the entire HTML container, including the selector
		$.fn.outerHTML = function() {
			return $('<div>').append( this.eq(0).clone() ).html();
		};
	})(jQuery);
	
	/* ########################################################################### *
	/* ##### ACCESSIBLE TOOLTIPS (WCAG LEVEL AAA)
	/* ########################################################################### */
	
	/**
	 * jQuery.accessibleTooltip - Accessible Tooltip Plugin.
	 * Copyright (c) 2009-2010 Damian Keeghan - dkeeghan@deloitte.com.au
	 * Date: 02/02/2010
	 * @author Damian Keeghan
	 * @version 1.0
	 *
	 */
	
	(function($){
		//creates an accessibleTooltip from an A tag
		$.fn.accessibleTooltip = function(options){
			var defaults = {
				speed: 250,
				associateWithLabel: true,
				labelText: function(btn){
					return $(btn).parent().find("label, .label").text().replace("*", "");	
				},
				helpPrefix: "Help text for",
				leftOffset: 15,
				topOffset: 3,
				preContent: "",
				buttonStyle: "tooltip",
				tooltipStyle: "tooltip",
				isAbbr: false,
				onShow: function(btn, tooltipDiv){
					$(tooltipDiv).animate({opacity: 1}, 0);	
				}
			};
			
			var options = $.extend(defaults, options);
	
			return this.each(function(){
				var aTooltip = $(this);
				
				var label = (options.associateWithLabel) ? options.labelText($(aTooltip)) : "";
	
				var helpText = $(aTooltip).attr("title");
				
				if(helpText==""){
					$(aTooltip).remove();
				} else {
					var tooltip;
					
					if(options.isAbbr){
						$(aTooltip).removeAttr('title');
						tooltip = $(aTooltip);
					} else {
						$(aTooltip).after("<button type=\"button\" class=\""+options.buttonStyle+"\">"+options.helpPrefix+" "+label+"</button>");
						tooltip = $(aTooltip).parent().find("button."+options.buttonStyle);	
						
						$(aTooltip).remove();
					}
					
					$(tooltip).data("isClicked", false);
					
					var tooltipContent = "<div class=\""+options.tooltipStyle+"\" style=\"display: none\">";
						tooltipContent += options.preContent;
						tooltipContent += "<div class=\"content\">";
							tooltipContent += (options.associateWithLabel) ? "<h3 style=\"position: absolute; left: -99999px\">Help for "+label+"</h3>" : "";
							tooltipContent += "<p>"+helpText+"</p>";
							tooltipContent += (options.associateWithLabel) ? "<div style=\"position: absolute; left: -99999px\">End help</div>" : "";
						tooltipContent += "</div>";
					tooltipContent += "</div>";
					
					$(tooltip).after(tooltipContent);
					
					var tooltipDiv = $(tooltip).parent().find("div."+options.tooltipStyle);
		
					$(tooltip).unbind("click").bind("click", function(e){
						e.preventDefault();
						
						if($(tooltip).data("isClicked")==false){
							$(tooltip).data("isClicked", true);
							setPosition(tooltip, tooltipDiv);
							
							if(options.speed==0){
								$(tooltipDiv).show();
								options.onShow($(aTooltip), $(tooltipDiv));
							} else {
								$(tooltipDiv).fadeIn(options.speed, function(){
									options.onShow($(aTooltip), $(tooltipDiv));										 
								});
							}
						} else {
							if(options.speed==0){
								$(tooltipDiv).hide();
								$(tooltip).data("isClicked", false);
							} else {
								$(tooltipDiv).fadeOut(options.speed, function(){
									$(tooltip).data("isClicked", false);
								});
							}
						}
						
						return false;
					});
					
					$(tooltip).bind("focus mouseover", function(){
						if($(tooltip).data("isClicked")==false){
							setPosition(tooltip, tooltipDiv);
							
							if(options.speed==0){
								$(tooltipDiv).show();
								options.onShow($(aTooltip), $(tooltipDiv));
							} else {
								$(tooltipDiv).stop().fadeIn(options.speed, function(){
									options.onShow($(aTooltip), $(tooltipDiv));
									setPosition(tooltip, tooltipDiv);								   
								});
							}
						}
					});
					
					$(tooltip).bind("blur mouseout", function(){
						if($(tooltip).data("isClicked")==false){
							if(options.speed==0){
								$(tooltipDiv).hide();
							} else {
								$(tooltipDiv).stop().fadeOut(options.speed);
							}
						}
					});	
					
					$(window).resize(function(){
						if($(tooltip).data("isClicked")==true){
							setPosition(tooltip, tooltipDiv);	
						}
					});
				}
			});
			
			function setPosition(tooltip, tooltipDiv){
				var tooltipDimensions = {top: $(tooltip).position().top, left: $(tooltip).position().left, width: $(tooltip).width(), height: $(tooltip).height()}
				
				var tooltipDivHeight = $(tooltipDiv).height();
				
				var tooltipDivLeftPos = (tooltipDimensions.left + tooltipDimensions.width + options.leftOffset);
				var tooltipDivTopPos = tooltipDimensions.top + options.topOffset + $(tooltip).parents(".resultsWindow").scrollTop();
				
				$(tooltipDiv).css({top: tooltipDivTopPos, left: tooltipDivLeftPos});
			}
		};
		
		$.fn.resetAccessibleTooltip = function(options){
			var defaults = {
				speed: 250,
				tooltipStyle: "tooltip"
			};
			
			var options = $.extend(defaults, options);
			
			return this.each(function(){
				var tooltip = $(this);
	
				var tooltipDiv = $(tooltip).parent().find("div."+options.tooltipStyle);
				
				if(options.speed==0){
					$(tooltipDiv).hide();
					$(tooltip).data("isClicked", false);
				} else {
					$(tooltipDiv).fadeOut(options.speed, function(){
						$(tooltip).data("isClicked", false);
					});
				}						   
			});	
		}
	})(jQuery);
	
	/**
	 * jQuery.ScrollTo - Easy element scrolling using jQuery.
	 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
	 * Dual licensed under MIT and GPL.
	 * Date: 5/25/2009
	 * @author Ariel Flesler
	 * @version 1.4.2
	 *
	 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
	 */
	;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

	/**
	* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
	* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
	* 
	* @param  f  onMouseOver function || An object with configuration options
	* @param  g  onMouseOut function  || Nothing (use configuration options object)
	* @author    Brian Cherne brian(at)cherne(dot)net
	*/
	(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
	
	/**
	* http://jquery.thewikies.com/browser/
	*/
	(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);

	/*
	 * jQuery tableHover plugin
	 * Version: 0.1.4a (Modified by Damian Keeghan - Deloitte's Online practice, May 2010)
	 *
	 * Copyright (c) 2007 Roman Weich
	 * http://p.sohei.org
	 *
	 * Dual licensed under the MIT and GPL licenses 
	 * (This means that you can choose the license that best suits your project, and use it accordingly):
	 *   http://www.opensource.org/licenses/mit-license.php
	 *   http://www.gnu.org/licenses/gpl.html
	 *
	 * Changelog: 
	 * v 0.1.4a - 2011-05-05
	 *	- new: use the ignoreHover class to disable the hover functionality on a row/column
	 * v 0.1.4 - 2007-12-17
	 *	- fix: clicking on a link or child element inside a cell did not set the clickClass on the rows/columns.
	 * v 0.1.3 - 2007-09-04
	 *	- fix: highlight did not work when the hovered table cell had child elements inside
	 * v 0.1.2 - 2007-08-13
	 *	- fix/change: changed event binding routine, as is got really slow with jquery 1.1.3.1
	 *	-change: added new option "ignoreCols", through which columns can be excluded from the highlighting process
	 * v 0.1.1 - 2007-06-05
	 *	- fix: errors when using the plugin on a table not having a theader or tfoot
	 * v 0.1.0 - 2007-05-31
	 */
	
	(function($)
	{
		/**
		 * Calculates the actual cellIndex value of all cells in the table and stores it in the realCell property of each cell.
		 * Thats done because the cellIndex value isn't correct when colspans or rowspans are used.
		 * Originally created by Matt Kruse for his table library - Big Thanks! (see http://www.javascripttoolbox.com/)
		 * @param {element} table	The table element.
		 */
		var fixCellIndexes = function(table) 
		{
			var rows = table.rows;
			var len = rows.length;
			var matrix = [];
			for ( var i = 0; i < len; i++ )
			{
				var cells = rows[i].cells;
				var clen = cells.length;
				for ( var j = 0; j < clen; j++ )
				{
					var c = cells[j];
					var rowSpan = c.rowSpan || 1;
					var colSpan = c.colSpan || 1;
					var firstAvailCol = -1;
					if ( !matrix[i] )
					{ 
						matrix[i] = []; 
					}
					var m = matrix[i];
					// Find first available column in the first row
					while ( m[++firstAvailCol] ) {}
					c.realIndex = firstAvailCol;
					for ( var k = i; k < i + rowSpan; k++ )
					{
						if ( !matrix[k] )
						{ 
							matrix[k] = []; 
						}
						var matrixrow = matrix[k];
						for ( var l = firstAvailCol; l < firstAvailCol + colSpan; l++ )
						{
							matrixrow[l] = 1;
						}
					}
				}
			}
		};
	
		/**
		 * Sets the rowIndex of each row in the table. 
		 * Opera seems to get that wrong using document order instead of logical order on the tfoot-tbody part.
		 * @param {element} table	The table element.
		 */
		var fixRowIndexes = function(tbl) 
		{
			var v = 0, i, k, r = ( tbl.tHead ) ? tbl.tHead.rows : 0;
			if ( r )
			{
				for ( i = 0; i < r.length; i++ )
				{
					r[i].realRIndex = v++;
				}
			}
			for ( k = 0; k < tbl.tBodies.length; k++ )
			{
				r = tbl.tBodies[k].rows;
				if ( r )
				{
					for ( i = 0; i < r.length; i++ )
					{
						r[i].realRIndex = v++;
					}
				}
			}
			r = ( tbl.tFoot ) ? tbl.tFoot.rows : 0;
			if ( r )
			{
				for ( i = 0; i < r.length; i++ )
				{
					r[i].realRIndex = v++;
				}
			}
		};
	
		/**
		 * Highlights table rows and/or columns on mouse over.
		 * Fixes the highlight of the currently highlighted rows/columns on click.
		 * Works on tables with rowspans and colspans.
		 *
		 * @param {map} options			An object for optional settings (options described below).
		 *
		 * @option {boolean} allowHead		Allow highlighting when hovering over the table header.
		 *							Default value: true
		 * @option {boolean} allowBody		Allow highlighting when hovering over the table body.
		 *							Default value: true
		 * @option {boolean} allowFoot		Allow highlighting when hovering over the table footer.
		 *							Default value: true
		 *
		 * @option {boolean} headRows		If true the rows in the table header will be highlighted when hovering over them.
		 *							Default value: false
		 * @option {boolean} bodyRows		If true the rows in the table body will be highlighted when hovering over them.
		 *							Default value: true
		 * @option {boolean} footRows		If true the rows in the table footer will be highlighted when hovering over them.
		 *							Default value: false
		 * @option {boolean} spanRows		When hovering over a cell spanning over more than one row, highlight all spanned rows.
		 *							Default value: true
		 *
		 * @option {boolean} headCols		If true the cells in the table header (matching the currently hovered column) will be highlighted.
		 *							Default value: false
		 * @option {boolean} bodyCols		If true the cells in the table body (matching the currently hovered column) will be highlighted.
		 *							Default value: true
		 * @option {boolean} footCols		If true the cells in the table footer (matching the currently hovered column) will be highlighted.
		 *							Default value: false
		 * @option {boolean} spanCols		When hovering over a cell spanning over more than one column, highlight all spanned columns.
		 *							Default value: true
		 * @option {array} ignoreCols		An array of numbers. Each column with the matching column index won't be included in the highlighting process.
		 *							Index starting at 1!
		 *							Default value: [] (empty array)
		 *
		 * @option {boolean} headCells		Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table header only).
		 *							Default value: false
		 * @option {boolean} bodyCells		Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table body only).
		 *							Default value: true
		 * @option {boolean} footCells		Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table footer only).
		 *							Default value: false
		 *
		 * @option {string} rowClass			The css class set to the currently highlighted row.
		 *							Default value: 'hover'
		 * @option {string} colClass			The css class set to the currently highlighted column.
		 *							Default value: '' (empty string)
		 * @option {string} cellClass			The css class set to the currently highlighted cell.
		 *							Default value: '' (empty string)
		 * @option {string} clickClass		The css class set to the currently highlighted row and column on mouse click.
		 *							Default value: '' (empty string)
		 *
		 * @example $('#table').tableHover({});
		 * @desc Add simple row highlighting to #table with default settings.
		 *
		 * @example $('#table').tableHover({rowClass: "someclass", colClass: "someotherclass"});
		 * @desc Add row and columnhighlighting to #table and set the specified css classes to the highlighted cells.
		 *
		 * @example $('#table').tableHover({clickClass: "someclickclass"});
		 * @desc Add simple row highlighting to #table and set the specified css class on the cells when clicked.
		 *
		 * @example $('#table').tableHover({allowBody: false, allowFoot: false, allowHead: true, colClass: "someclass"});
		 * @desc Add column highlighting on #table only highlighting the cells when hovering over the table header.
		 *
		 * @example $('#table').tableHover({bodyCols: false, footCols: false, headCols: true, colClass: "someclass"});
		 * @desc Add column highlighting on #table only for the cells in the header.
		 *
		 * @type jQuery
		 *
		 * @name tableHover
		 * @cat Plugins/tableHover
		 * @author Roman Weich (http://p.sohei.org)
		 */
		$.fn.tableHover = function(options)
		{
			var settings = $.extend({
					allowHead : true,
					allowBody : true,
					allowFoot : true,
	
					headRows : false,
					bodyRows : true,
					footRows : false,
					spanRows : true,
	
					headCols : false,
					bodyCols : true,
					footCols : false,
					spanCols : true,
					ignoreCols : [],
	
					headCells : false,
					bodyCells : true,
					footCells : false,
					//css classes,,
					rowClass : 'hover',
					colClass : '',
					cellClass : '',
					clickClass : ''
				}, options);
	
			return this.each(function() 
			{
				var colIndex = [], rowIndex = [], tbl = this, r, rCnt = 0, lastClick = [-1, -1];
	
				if ( !tbl.tBodies || !tbl.tBodies.length )
				{
					return;
				}
	
				/**
				 * Adds all rows and each of their cells to the row and column indexes.
				 * @param {array} rows		An array of table row elements to add.
				 * @param {string} nodeName	Defines whether the rows are in the header, body or footer of the table.
				 */
				var addToIndex = function(rows, nodeName)
				{
					var c, row, rowI, cI, rI, s;
					//loop through the rows
					for ( rowI = 0; rowI < rows.length; rowI++, rCnt++ )
					{
						row = rows[rowI];
						//each cell
						for ( cI = 0; cI < row.cells.length; cI++ )
						{
							c = row.cells[cI];
							//add to rowindex
							if ( (nodeName == 'TBODY' && settings.bodyRows) 
								|| (nodeName == 'TFOOT' && settings.footRows) 
								|| (nodeName == 'THEAD' && settings.headRows) )
							{
								s = c.rowSpan;
								while ( --s >= 0 )
								{
									rowIndex[rCnt + s].push(c);
								}
							}
							//add do colindex
							if ( (nodeName == 'TBODY' && settings.bodyCols)
									|| (nodeName == 'THEAD' && settings.headCols) 
									|| (nodeName == 'TFOOT' && settings.footCols) )
							{
								s = c.colSpan;
								while ( --s >= 0 )
								{
									rI = c.realIndex + s;
									if ( $.inArray(rI + 1, settings.ignoreCols) > -1 )
									{
										break;//dont highlight the columns in the ignoreCols array
									}
									if ( !colIndex[rI] )
									{
										colIndex[rI] = [];
									}
									colIndex[rI].push(c);
								}
							}
							//allow hover for the cell?
							if ( (nodeName == 'TBODY' && settings.allowBody) 
									|| (nodeName == 'THEAD' && settings.allowHead) 
									|| (nodeName == 'TFOOT' && settings.allowFoot) )
							{
								c.thover = true;
							}
						}
					}
				};
	
				/**
				 * Mouseover event handling. Set the highlight to the rows/cells.
				 */
				var over = function(e)
				{
					var p = e.target;
					while ( p != this && p.thover !== true )
					{
						p = p.parentNode;
					}
					if ( p.thover === true && !$(p).hasClass("ignoreHover") )
					{
						highlight(p, true);
					}
				};
	
				/**
				 * Mouseout event handling. Remove the highlight from the rows/cells.
				 */
				var out = function(e)
				{
					var p = e.target;
					while ( p != this && p.thover !== true )
					{
						p = p.parentNode;
					}
					if ( p.thover === true )
					{
						highlight(p, false);
					}
				};
				
				/**
				 * Mousedown event handling. Sets or removes the clickClass css style to the currently highlighted rows/cells.
				 */
				var click = function(e)
				{
					var t = e.target;
					while ( t && t != tbl && !t.thover ) //search the real target
						t = t.parentNode;
					if ( t.thover && settings.clickClass != '' )
					{
						var x = t.realIndex, y = t.parentNode.realRIndex, s = '';
						//unclick
						$('td.' + settings.clickClass + ', th.' + settings.clickClass, tbl).removeClass(settings.clickClass);
						if ( x != lastClick[0] || y != lastClick[1] )
						{
							//click..
							if ( settings.rowClass != '' )
							{
								s += ',.' + settings.rowClass;
							}
							if ( settings.colClass != '' )
							{
								s += ',.' + settings.colClass;
							}
							if ( settings.cellClass != '' )
							{
								s += ',.' + settings.cellClass;
							}
							if ( s != '' )
							{
								$('td, th', tbl).filter(s.substring(1)).addClass(settings.clickClass);
							}
							lastClick = [x, y];
						}
						else
						{
							lastClick = [-1, -1];
						}
					}
				};
				
				/**
				 * Adds or removes the highlight to/from the columns and rows.
				 * @param {element} cell	The cell with the mouseover/mouseout event.
				 * @param {boolean} on		Defines whether the style will be set or removed.
				 */
				var highlight = function(cell, on)
				{
					if ( on ) //create dummy funcs - dont want to test for on==true all the time
					{
						$.fn.tableHoverHover = $.fn.addClass;
					}
					else
					{
						$.fn.tableHoverHover = $.fn.removeClass;
					}
					//highlight columns
					var h = colIndex[cell.realIndex] || [], rH = [], i = 0, rI, nn;
					if ( settings.colClass != '' )
					{
						while ( settings.spanCols && ++i < cell.colSpan && colIndex[cell.realIndex + i] )
						{
							h = h.concat(colIndex[cell.realIndex + i]);
						}
						$(h).tableHoverHover(settings.colClass);
					}
					//highlight rows
					if ( settings.rowClass != '' )
					{
						rI = cell.parentNode.realRIndex;
						if ( rowIndex[rI] )
						{
							rH = rH.concat(rowIndex[rI]);
						}
						i = 0;
						while ( settings.spanRows && ++i < cell.rowSpan )
						{
							if ( rowIndex[rI + i] )
							{
								rH = rH.concat(rowIndex[rI + i]);
							}
						}
						$(rH).tableHoverHover(settings.rowClass);
					}
					//highlight cell
					if ( settings.cellClass != '' )
					{
						nn = cell.parentNode.parentNode.nodeName.toUpperCase();
						if ( (nn == 'TBODY' && settings.bodyCells)
								|| (nn == 'THEAD' && settings.headCells)
								|| (nn == 'TFOOT' && settings.footCells) )
						{
							$(cell).tableHoverHover(settings.cellClass);
						}
					}
				};
	
				fixCellIndexes(tbl);
				fixRowIndexes(tbl);
	
				//init rowIndex
				for ( r = 0; r < tbl.rows.length; r++ )
				{
					rowIndex[r] = [];
				}
				//add header cells to index
				if ( tbl.tHead )
				{
					addToIndex(tbl.tHead.rows, 'THEAD');
				}
				//create index - loop through the bodies
				for ( r = 0; r < tbl.tBodies.length; r++ )
				{
					addToIndex(tbl.tBodies[r].rows, 'TBODY');
				}
				//add footer cells to index
				if ( tbl.tFoot )
				{
					addToIndex(tbl.tFoot.rows, 'TFOOT');
				}
				$(this).bind('mouseover', over).bind('mouseout', out).click(click);
			});
		};
	})(jQuery); 

	// Funnelback link preview jquery plugin
	// Author: Nicolas Guillaumin, Matt Sheppard
	// Copyright Funnelback, 2010
	(function($) {
	 
		$.fn.fbcompletion = function(settings) {
			var config = {
				'collection'  : 'funnelback_documentation',
				'show'        : 10,
				'sort'        : 0,
				'delay'       : 0,
				'length'      : 3,
				'program'     : 'padre-qs.cgi',
				'source'      : 'internal',
				'format'      : 'simple',
				'enabled'     : 'disabled',
				'tmplId'      : 'fb-completion-tmpl'
			};
	   
			if (settings) $.extend(config, settings);
		
			if (config.enabled != 'enabled' ) {
				return;
			}
		
			this.each(function() {
				var targetElement = this;

				// Compile jQuery template
				var compiledTmpl;
				if (jQuery().template) {
					if (jQuery('#'+config.tmplId).length > 0) {
						compiledTmpl = jQuery('#'+config.tmplId).template();
					} else {
						compiledTmpl = jQuery('<script>[Error: Template <tt>'+config.tmplId+'</tt> not found]</script>').template();
					}
				}
				
				$(targetElement).autocomplete( {
					source: function (request, response) {
						jQuery.ajax({
							type:     'GET',
							url:      config.program
										+ '?collection=' + config.collection
										+ '&partial_query=' + request.term.replace(/ /g, '+')
										+ '&show=' + config.show
										+ '&sort=' + config.sort
										+ '&alpha=' + config.alpha
										+ '&autoc=' + ((config.source == 'internal') ? 0 : 2)
										+ '&fmt=' + ((config.format == 'simple') ? 'json' : 'json++')
							,
							dataType: 'json',
							success:  function(data) {
								var responses = new Array();
								var categorized = new Array();
		
								for (var i=0; i<data.length; i++) {
									var out;
									var suggestion = data[i];
		
									if (suggestion == null) {
										continue;
									}

									if (typeof(suggestion) == 'string') {
										// Single string suggestion
										responses.push({
											label: suggestion,
											matchOn: request.term
										});
									} else if (typeof(suggestion) == 'object') {
										if (suggestion.cat) {
											if ( ! categorized[suggestion.cat]) {
												categorized[suggestion.cat] = new Array();
											}
											categorized[suggestion.cat].push({
												label: (suggestion.disp) ? suggestion.disp : suggestion.key,
												value: (suggestion.action_t == 'Q') ? suggestion.action: suggestion.key,
												extra: suggestion
											});
										} else {
											responses.push({
												label: (suggestion.disp) ? suggestion.disp : suggestion.key,
												value: (suggestion.action_t == 'Q') ? suggestion.action : suggestion.key,
												extra: suggestion
											});
										}
									}
								}

								// Add categorized suggestions, with category header
								for(var i in categorized) {
									responses.push({
										label: i,
										category : true
									});
									for (var j in categorized[i]) {
										responses.push(categorized[i][j]);
									}
								}
								response (responses);
							}
						});
					},
		
					delay: config.delay,
		
					minLength: config.length,
		
					// focus: function(evt, ui) {}
		
					select: function(evt, ui) {
						if (ui.item.extra) {
							switch(ui.item.extra.action_t) {
								case 'C':
									eval(ui.item.extra.action);
									break;
								case 'U':
									document.location = ui.item.extra.action;
									break;
								case undefined:
								case '':
									jQuery(this).attr('value', ui.item.value);
									jQuery(this).context.form.submit();
									break;
								case 'Q':
								default:
									jQuery(this).attr('value', ui.item.extra.action);
									jQuery(this).context.form.submit();
							}
						} else {
							// Submit the form on select
							jQuery(this).attr('value', ui.item.value);
							jQuery(this).context.form.submit();
						}
						return false;
					}
				}).data( "autocomplete" )._renderItem = function( ul, item ) {
					var label;

					if ( item.category ) {
						// Category header
						return jQuery('<li><h2>' + item.label + '</h2></li>').appendTo(ul);
					} else if ( item.extra ) { // Complex suggestion
						switch (item.extra.disp_t) {
							case 'J':   // Json data
								if (compiledTmpl) {
									label = jQuery.tmpl(compiledTmpl, item.extra.disp).appendTo('<p></p>').parent().html();
								} else {
									label = '[Error: jQuery template plugin is unavailable]';
								}
								break;
							case 'C':   // JS callback
								label = eval(item.extra.disp);
								break;
							case 'T':   // Plain text
							case 'H':   // HTML
							default:
								label = item.label;
						}
					} else {
						// Single string suggestion
						label = item.label.replace(new RegExp('('+item.matchOn+')', 'i'), '<strong>$1</strong>');
					}
					return jQuery('<li></li>')
						.data( 'item.autocomplete', item)
						.append( '<a>' + label + '</a>' )
						.appendTo(ul);
				};
			});
			return this;
		};
	 
	 })(jQuery);



})(jQuery);
