/*

FILE LAST UPDATED:  23Nov09

* @author Rich Bongiorno
* Paths holds paths. It's a simple object/hash centered at providing the jsp developers a simple way
* to specify the file paths for various includes. It contains some defaults, but feel free to overwrite
* them and add more.
*/
/* imgBasePath: When used inside the portal, imgBasePath is defined in head.jspf to point to the images path within the theme */

Paths = {
	"carouselControlImages": typeof imgBasePath=="undefined" ? "images/" : imgBasePath,
	"carouselLargePreview": typeof imgBasePath=="undefined" ? "images/" : imgBasePath
};

/*
* @author Jeremy Flores
* Beyond the saucy name, inputStripper prevents certain values from being entered into an input field
* It traps for letters, numbers, symbols and spaces or any combination you like (need numbers and spaces but no symbols or
* letters? We can do that!). The only option it accepts is an array detailing the *invalid* types. When the user presses
* a key on one of the affected elements, inputStripper checks it against the list of disallowed types (via regular expression)
* and if it fails any one of the tests, the event is not allowed to bubble.
*
* This plugin could be easily extended by simple introducing more stripper names and stripper regexes. Don't like the letter
* R when used next to a number or backslash? Write a regex to match that pattern and add its stripper name to the switch
* statement.
*/
$.fn.inputStripper = function(options) {
  var defaults = {
    strippers: ['letters','numbers','symbols','spaces'] //which items to strip
	}
	var options = $.extend(defaults, options);
	$(this).each(function() {
	  var $this = $(this);
	  $this.keypress(function(e) {
	    var press = String.fromCharCode(e.which);
	    if (e.charCode == 0) return true; //a control character like backspace
	    
	    var valid = true;
	    $.map(options.strippers,function(element) {
	      if (valid) {
	        switch(element) {
  	        case "letters":
  	          valid = press.match(/[a-zA-Z]+/) ? false : true;
  	        break;
  	        case "numbers":
  	          valid = press.match(/\d+/) ? false : true;
  	        break;
  	        case "symbols":
  	          valid = press.match(/[^a-zA-Z\d\s]+/) ? false : true;
  	        break;
  	        case "spaces":
  	          valid = press.match(/\s+/) ? false : true;
  	        break;
  	      }
	      }
	    });
	    return valid;
	  });
	});
};

/*
* @author Jeremy Flores
* Simple function to pop the spinner and disable the primary search form in the application header
*/
$.fn.disableOnSubmit = function(options){
	imgBasePath=typeof imgBasePath=="undefined" ? "images/" : imgBasePath;
	var defaults = {
	  selectors: 'input,button,textarea,select', //selectors for fields to disable
	  top: 0, //move the spinner's pop spot up and down
	  left: 0, //move the spinner's pop spot left and right,
	  spinnerPath: imgBasePath+"lightbox/lightbox-ico-loading.gif" //path to the spinner image
		//spinnerPath: "images/lightbox/lightbox-ico-loading.gif" //path to the spinner image
	}
	var options = $.extend(defaults, options);
	
	// Makes sure button is enabled at start
	$(this).find(options.selectors).removeAttr('disabled');
	
	$(this).submit(function() {
	  var $this = $(this);
	  $this.find(options.selectors).attr('disabled','disabled'); //disable the form
	  var offset = $this.offset(); //get the position of the form
	  
	  //pop the spinner in the middle of the form
	  var xPos = Math.floor(offset.left + ($this.width()/2)) - 19 + 'px';
	  var yPos = offset.top - 11 + 'px';
  	//$('body').prepend('<div id="searchSpinner" style="display: none; top: ' + yPos + '; left: ' + xPos + ';">'
  	//+ '<img src="' + options.spinnerPath + '" alt="Please Wait"></div>');
  	$this.parent().fadeTo('fast', .5, function() {
  	  $('#searchSpinner').css({"left": xPos, "top": yPos}).fadeIn('fast'); //fade the spinner in so the user knows the system is working
  	}); //fade the form to indicate it's disabled status
	  //return false; //this needs to be removed in production - it prevents the form from submitting
	});
	return this;
};
function setClipping(){
	$("#headerLink").width($("#headerLink").next().width());
	$("#searchLayout .specialInformation").width($("#searchContent").width()-34);
}
function setStage(){
	$("#stage").width(Math.max($(window).width(), 989));
	setClipping();
}
// Load up the spinner from the image server and position it out of view:
$(document).ready(function(){
	imgBasePath=typeof imgBasePath=="undefined" ? "images/" : imgBasePath;
	if($(window).width()<989){
	setStage();
	}
	setClipping();
	$(window).resize(setStage);
	$('body').prepend('<div id="searchSpinner" style="display: block; top: 0px; left: -2000px;">' + '<img src="'+imgBasePath+'lightbox/lightbox-ico-loading.gif" alt="Please Wait" id="spinnerpic"></div>');
  if($("#searchForm").length) {
		$("#searchForm select, #searchForm input, #searchForm button").removeAttr('disabled');
		document.getElementById("searchForm").reset();
	}
	$("#searchForm").submit(function(){
		return false;
	});
	// Set up the tooltip for the CRU:
	$('#countryInfo a.tooltipWrapper').click(function(){
		$(this).blur();
		return false;
	}).toolTip({
		top: 30,
		left: -370
	});
});
function sendSearch(){
	var $this=$("#searchForm");
	var offset = $this.offset(); //get the position of the form
  //pop the spinner in the middle of the form
  var xPos = Math.floor(offset.left + ($this.width()/2)) - 19 + 'px';
  var yPos = offset.top - 11 + 'px';
	$this.parent().fadeTo('fast', .5, function() {
		$('#searchSpinner').css({"left": xPos, "top": yPos}).fadeIn('fast');
		$("#spinnerpic").attr("src", $("#spinnerpic").attr("src"));
		document.getElementById("searchForm").submit();
		$("#searchForm select, #searchForm input, #searchForm button").attr('disabled','disabled');
		$("#spinnerpic").attr("src", $("#spinnerpic").attr("src"));
	});
}
/*
* @author Jeremy Flores
* Simple image preloader for use with the thumbBigMaker below. In short, throw it a selector that pulls the
* anchors containing the path to the larger images you're wanting to pre-load and it'll pre-load them. Handy.
*/
jQuery.preloadImages = function(options) {
  var defaults = {
    selector: 'a.thumber', //the selector that pulls the elements containing the path to the large image
    attribute: 'href' //attribute of the element that has our path.
  }
  var options = $.extend(defaults, options);

  $(options.selector).each(function() {
    //for each item in the iteration, make (and then discard) an image element. Then, the image
    //is sitting in cache when you need it - no need to make a new request
    jQuery("<img />").attr("src",$(this).attr(options.attribute));
  });
}

/*
* @author Jeremy Flores
* Don't laugh at the name. You had to be there. It was hilarious.
* thumbBigMaker, employed primarily in search results, creates a simple floating div that contains a larger
* version of a thumbnailed image. the div pops when the user clicks on the img
* (which is wrapped in an anchor with an href pointing at the larger image).
*/
$.fn.thumbBigMaker = function (options) {
  var defaults = {
    left: 0, //how far to shove the thumbBigMaker past the left edge of the element that triggered it
    top: 0, //how far to shove the thumbBigMaker below the top of the element that triggered it
    attribute: 'href', //which attribute of the triggering element contains the path to the larger image
    captionAttribute: 'title' //the attribute containing the caption, if any.
  };
  var options = $.extend(defaults, options);
  
  // Creates the code to display the thumbBigMaker
	getTip = function () {
		var tip = '<div id="thumbBig" style="display: none;">' +
      '<div class="closer"><a href="#" onclick="$(\'#thumbBig\').hide(); return false;">Close</a></div>' + 
      '<div class="inner"></div>' +
      '<div class="caption"></div>' +
		'</div>';
		return tip;
	};

	// Append div to body
	// Append tooltip to body, if doesn't exist (RB 01/26/2010)
	if ($('#thumbBig').length == 0) {
		$('body').prepend(getTip());
	}

	
	// Apply the hover event listener to each element in the set
	$(this).each(function() {
		var $this = $(this);
		var thumbBigger = $('#thumbBig');
		imgBasePath=typeof imgBasePath=="undefined" ? "images/" : imgBasePath;
		//grab the path for the larger image. If it's an anchor, and it should be most of the time,
		//we want it to be the href (for graceful degredation).
		var imagePath = $this.attr(options.attribute);
		var caption = $this.attr(options.captionAttribute);
		$this.click(function() {
		  thumbBigger.hide(); //if it's already showing, hide it for updating before showing it again.
		  // Calculate Offset  
      var offset = $(this).offset();
	    var xTip = (offset.left+options.left)+"px";  
		  var yTip = (offset.top+options.top)+"px";
		  thumbBigger.children('.inner').html('<img src="' + imagePath + '"/>');
		   var imgError =false;
		   thumbBigger.children('.inner').children('img').error(function(){
		   	var cameraImgPath= imgBasePath+"icons/camera.gif";
		    $(this).unbind("error").attr("src",cameraImgPath);
		    imgError=true;
		    });
		  thumbBigger.children('.caption').html(caption);
		  thumbBigger.css({
		    'position': 'absolute',
		    'top': yTip,
		    'left': xTip,
		    'z-index': 9999
		  });
		  thumbBigger.show(1,function() {
		    var $this = $(this);
		    var imageWidth = $this.children('.inner').children('img').width();
				if(imageWidth<61){
					$this.width(180);
				} else {
					$this.width(imageWidth+20);
				}
		  });
		  return false; //prevent bubbling
		});
	});
};


/*
 * Globally override jQuery Tab implementation default value
 */
jQuery.ui.tabs.defaults.panelTemplate = '<div class="content tab-area"><div class="wrapper"></div></div>';
/** RB **/
/* jQuery.ui.tabs.defaults.tabTemplate = '<li><h3><a href="#{href}">#{label}</a></h3></li>'; */
jQuery.ui.tabs.defaults.tabTemplate = '<li><h3><a href="#{href}" id="#{id}">#{label}</a></h3></li>';

/*
 * @author Jon Hartman
 * Handles the display of hidden HTML tool tips on hover of containing elements.
 * Based on tool-tip code at http://net.tutsplus.com/tutorials/javascript-ajax/build-a-better-tooltip-with-jquery-awesomeness/
 * RB - 03-23-2010 - cleaned up formatting
 */
$.fn.toolTip = function (options) {
	/* Setup the options for the tooltip that can be  accessed from outside the plugin */  
	var defaults = { 
		top: 30,    /* Vertical offset for the tool tip */
		left: 90    /* Horizontal offset for the tool tip */
		};  
	var options = $.extend(defaults, options);
	/* Creates the code to display the tooltip */
	getTip = function () {
		return '<div id="toolTip"><div class="wrap"><div class="inner"></div></div><div class="bottom">&nbsp;</div></div>';
		};
	/* Append tooltip to body, if doesn't exist (RB 01/26/2010) */
	if ($('#toolTip').length == 0) {
		$('body').prepend(getTip());
	}
	/* Apply the hover event listener to each element in the set */
	$(this).each(
		function() {
			var $this = $(this);
			var toolTip = $('#toolTip');
			// Hover
			$this.hover(
				function() {
					var offset = $(this).offset();  /* Calculate Offset */
				    var tLeft = offset.left;  
				    var tTop = offset.top;
					/* Copy hidden HTML into the tool tip element */
					toolTip.find('.inner').html($this.find('.tooltip').html());
					/* Move the tool tip to the hovered element */
					setTip(tTop, tLeft);
					toolTip.show();	/* Show the tool tip */
				},   
				function() {
					toolTip.hide(); /* Hide the tool tip */
				}
			); /* end $this.hover */
			/* Position the tooltip relative to the class associated with the tooltip */  
			setTip = function(top, left) {
				var toolTip = $('#toolTip');  
				var xTip = (left+options.left)+"px";  
				var yTip = (top+options.top)+"px";  
				toolTip.css({'top' : yTip, 'left' : xTip, 'z-index' : 9999});  
				}  /* end setTip function */
		}
	);	/* end $(this).each function */
}	/* end tooltip function */

/*
 * @authors Jon Hartmann, Jeremy Flores
 * Plugin to even the height of tabs when one has multiple lines
 */
$.fn.fixTabs = function (options) {
	var defaults = {
		tabSelector : '.ui-state-default'
	};
	
	// Options
	var options = $.extend(defaults, options);
	
	$(this).each(function () {
		var $this = $(this);                      // Get Current Element
		var tabs = $(options.tabSelector, $this); // Get contained tabs
		var maxHeight = 0;                           // Create a default max height that is smaller than any possible tab
		
		// Loop over each tab and find the maximum height
		tabs.each(function () {
			var height = $(this).height();
			if ( height > maxHeight )
			  maxHeight = height;
		});
		// Set all tabs to that height;
		tabs.height(maxHeight);
	});
}

/*
 * @authors Jon Hartmann, Jeremy Flores
 * Plug-in to handle expandable/collapsible sections of HTML
 */
$.fn.expander = function (options, callback) {
  var defaults = {
    speed: 'slow',          // Animation speed for the slideUp/slideDown toggle
    opener: '.expander',    // Selector for the item that is clicked to open the expander, must be child of targeted element
    area: '.area',          // Select for the item that is expanded/collapsed, must be a child of targed element
    openerClass: 'closed'   // Class to be toggled on the opener, used to indicated open/closed state
  }
  var callback = callback;
  var options = $.extend(defaults, options);
  
  /* Apply the event listener to each of the elements in the set */
  $(this).each(function() {
    var $this = $(this);
    var area = $(options.area, $this);
    var opener = $(options.opener, $this);
		
    opener.click(function (event) {
    	event.preventDefault();
    	/** RB **/
    	/* if the expand area has not been filled */
    	if(area.html().length == 0) {
		// fill it using AJAX call to the href of the link inside the opener
    		area.load(this.firstChild.href);
    	}
    	/** RB **/
    	area.slideToggle(options.speed);

		// If the openerClass is declared, apply the openerClass
		if ( options.openerClass )
		 opener.toggleClass(options.openerClass);
		// If the callback is delared, call the callback
		if ( callback ) //throw the opener element to the callback
			callback(opener);
		}) /* end opener.click function */
  });
};

/*
* @author Jeremy Flores
* other_select, when attached to a select box, pops a sibling input field with similar
* attributes. Use it to record user input that falls outside the options provided in a
* select box.
*/
$.fn.other_select = function(options) {
  var defaults = {
    speed: 'normal', //rate at which the alternate input field appears/disappears
    nameSuffix: '_other', //suffix appended to the alternate input's name attribute
    idSuffix: '_other', //suffix appended to the alternate input's id attribute
    title: 'Other', //title text for the alternate input
    className: 'input', //need a specific class on the input? assign it here
    type: 'text', //it doesn't have to be a text field, but it probably should be
    popValue: 'other' //this is the value in the select options that pops the alternate input
  };
  
  var options = $.extend(defaults, options);
  
  $(this).each(function() {
    var $this = $(this);
    $this.bind('change', function() {
      if ( $this.val() == options.popValue ) { //user selected "Other" -> Pop the alternate input
        if( $this.siblings("#" + $this.attr('id') + options.idSuffix).size() == 0 ) {
          //we don't have the sibiling selector built, so lets build it
          var inputString = "<input style='display: none;' id='"
            + $this.attr('id') + options.idSuffix
            + "' type='" + options.type
            + "' name='" + $this.attr('name') + options.nameSuffix
            + "' title='" + options.title
            + "' class='" + options.className + "' />";
          //and now lets insert it after the select box
          $this.parent().append(inputString);
        }
        //show it!
        $this.siblings("#" + $this.attr('id') + options.idSuffix).fadeIn(options.speed);
      } else { //user selected a provided value -> Hide and clear the alternate input, if it exists
        if ($("#" + $this.attr('id') + options.idSuffix)) {
          $("#" + $this.attr('id') + options.idSuffix).fadeOut(options.speed).val('');
        }
      }
    });
  });
};

/*
 * @author Jon Hartmann
 * Max length enforcement for textareas
 */
$.fn.maxlength = function (options) {
	var defaults = {
		length: 4000,
		on: 'keyup'
	};
	var options = $.extend(defaults, options);
	
	$(this).each(function() {
		var $this = $(this);
		
		$this.bind(options.on, function () {
			var text = $this.html().toString();
			
			if ( text.length > options.length ) {
				text = text.substr(0, options.length);
				$this.html(text);
			}
		});
	});
};

/*
* @author Michael Wheatley
* These functions drive navigation
*/
var devKeepMenusOpen=false; // Use to prevent menus from going away.  This line can safely be removed at the end of development.
var thisMenuItem=-1; // Sets the default to an impossible value so function will only fire if overwritten to real value
var flyoutShowing=false;
var allowFade=true;
var maskHeight=0;
var lastPanel0;
var lastPanel1;
var fromPanel1=false;
var fromPanel2=false;
var preventPanel2=true;
var buttonOver=0;
var t; // Used to prevent menu showing when trying to reach search box
var overLink=false; // Used to prevent the "flickering menu" fault in IE
var overDrop=false; // Used to prevent the "flickering menu" fault in IE
var idToClear=""; // Used to prevent the "flickering menu" fault in IE
var menuToLaunch="";
var triggered=false;
var servicesTwoTier=false; // Drives positioning of the Services sub menu
var menuHeightArray=new Array(0, 0, 0);
var menuButtonArray=new Array("link0", "drop0", "drop1", "drop2", "link4", "link5", "link6"); // Used for keeping appropriate menu item illuminated
var htmlBlock="";
// Following gets rid of the z-index problem for form elements in IE6:
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);
$(function(){
	primePage();
});
function calcScreenHeight(){
	maskHeight=($("body").height()-96)+"px";
}
function delayLaunch(){
	launchMenu(menuToLaunch);
}
function primePage(){
	// Get the spinner image ready:
	var cacheImage=document.createElement('img');
	cacheImage.src=typeof imgBasePath=="undefined" ? "images/menu_col1over.gif" : imgBasePath+"menu_col1over.gif";
	if(navigator.userAgent.toLowerCase().indexOf('msie 6') == -1){
		$("#searchContext").wrap('<span id="selectHolder" />');
	} else {
		$(".shadowBox-blue .center").css({"background": "none", "padding-right": "0"});
		$(".shadowBox-blue .start").css({"background": "none"});
	}
	//$(".podContent h5:has('a>img')").css({"padding": "0px"});
	$(".podContent>div>h5>a>img").parent().parent().css({"padding": "0px"});
	$(".podContent>div>h5>img").parent().css({"padding": "0px"});
	$(".podContent>div>p>#wem_flash, .podContent>div>p>#wem_image, .podContent>div>p>#wem_image_text").parent().css({"padding": "0px"});
	$("#menuContainer").bgiframe();
	$('<div id="menuFade"></div>').prependTo("#menuContainer").css("opacity", 0);
	// Create the highlights and menu adds:
	$(".regMenu").mouseover(function(){
		clearTimeout(t);
		overDrop=false;
		$(".regMenu, .dropMenu").removeClass("dropMenuOver").removeClass("menuOver");
		setButton(thisMenuItem);
		$(this).addClass("menuOver");
		dropMenus();
	});
	$(".dropMenu").mouseover(function(){
		$("#selectHolder").html($("#selectHolder").html());
		overDrop=true;
		clearTimeout(t);
		$(".regMenu, .dropMenu").removeClass("dropMenuOver").removeClass("menuOver");
		setButton(thisMenuItem);
		$(this).addClass("dropMenuOver");
		//launchMenu(this.id);
		menuToLaunch=this.id;
		allowFade=false;
		if(!triggered){
			t=setTimeout("delayLaunch()", 400);
		} else {
			launchMenu(this.id);
		}
	});
	// Hide the highlights and menu hides:
	$(".dropMenu").mouseout(function(){
		clearTimeout(t);
		$(this).removeClass("menuOver");
		hideMenus();
	});
	$(".regMenu").mouseout(function(itemid){
		$(this).removeClass("menuOver");
		setButton(thisMenuItem);
	});
	$(".regMenu, .noSub, .hasSub").click(function(){ // Makes whole button act as link without losing SEO
		window.location=this.firstChild;
		return false;
	});
	// Code for the dropdown:
	$("#panel0 div.subHolder div, #panel1 div.subHolder div, #panel2 div.subHolder div").mouseover(function(){
		$("#"+$(this).parent().get(0).id+" div").removeClass("over");
		$(this).addClass("over");
	});
	$("#panel0 div.subHolder div").mouseover(function(){
		if(fromPanel1 && lastPanel0!=this){
			$(lastPanel0).removeClass("over");
			fromPanel1=false;
		}
		lastPanel0=this;
		if($(this).hasClass("hasSub")){
			$("#panel1 .subHolder").hide();
			var subDiv="#sub1_"+this.id.substr(7);
			$(subDiv+" div").removeClass("over");
			$(subDiv).show();
			preventPanel2=false;
			$("#slider1").stop().animate({left: "314px"}, function(){
				$("#menuBottomShadow").stop().css("width", "598px");
			});
		} else {
			preventPanel2=true;
			$("#menuBottomShadow").stop().css("width", "330px");
			$("#slider1").stop().animate({left: "46px"});
		}
		$("#slider2").stop().animate({left: "0px"});
	});
	$("#panel1 div.subHolder div").mouseover(function(){
		if(fromPanel2 && lastPanel1!=this){
			$(lastPanel1).removeClass("over");
			fromPanel2=false;
		}
		lastPanel1=this;
		if($(this).hasClass("hasSub") && !preventPanel2){
			$("#panel2 .subHolder").hide();
			var subDiv="#sub2_"+this.id.substr(7);
			$(subDiv+" div").removeClass("over");
			$(subDiv).show();
			$("#slider2").stop().animate({left: "268px"}, function(){
				$("#menuBottomShadow").stop().css("width", "866px");
			});
		} else {
			$("#menuBottomShadow").stop().css("width", "598px");
			$("#slider2").stop().animate({left: "0px"});
		}
	});
	$("#panel1").mouseover(function(){
		fromPanel1=true;
		$(lastPanel0).addClass("over");
	});
	$("#panel2").mouseover(function(){
		fromPanel2=true;
		$(lastPanel1).addClass("over");
	});
	for(var i=0; i<3; i++){
		menuHeightArray[i]=$("#sub0_"+i).height();
		$("#sub0_"+i+" .hasSub").each(function(){
			var p1Id=this.id.substr(7);
			if(i==2){
				servicesTwoTier=true;
			}
			menuHeightArray[i]=Math.max(menuHeightArray[i], $("#sub1_"+p1Id).height());
			$("#sub1_"+p1Id+" .hasSub").each(function(){
				menuHeightArray[i]=Math.max(menuHeightArray[i], $("#sub2_"+this.id.substr(7)).height());
			});
		});
	}
	$("#menuHolder").hide();
	$("#menuHolder").css("visibility", "visible");
};
function launchMenu(index){
	allowFade=false;
	triggered=true;
	buttonOver=parseInt(index.substr(index.length-1));
	$("#menuContainer").css("height", ($("body").height()-96)+"px"); // Sets the height of the fadeout to real height of page.  Elegent hack for IE5/6
	$("#menuBottomShadow").stop().css({"width": "330px", "top": (menuHeightArray[buttonOver]+44)+"px"});
	$("#panelsHolder, #panel0, #panel1, #panel2").css("height", (menuHeightArray[buttonOver]+27)+"px"); // sets the height of the dropdown menu
	$("#newShadow").css("height", (menuHeightArray[buttonOver]+44)+"px");
	switch(buttonOver){
		case 0:
		case 1:
			$("#menuHolder").css({"left": "86px"});
			break;
		case 2:
			$("#menuHolder").css({"left": servicesTwoTier ? "400px" : "422px"});
			break;
	}
	$("#slider1").stop().css({left: "46px"});
	$("#slider2").stop().css({left: "0px"});
	$("#panel0 div, #panel1 div").removeClass("over");
	$("#menuHolder").slideDown();
	$("#menuFade").stop().animate({"opacity": 0.6});
	$("#panel0 .subHolder, #panel1 .subHolder, #panel2 .subHolder").hide();
	$("#sub0_"+buttonOver).show();
}
function hideMenus(){
	setButton(thisMenuItem);
	allowFade=true;
	setTimeout("performFadeout()", 100);
}
function setButton(index){
	if(index>-1 && index<7){ // Will only happen on pages that have the value set
		$(".regMenu, .dropMenu").removeClass("menuOver");
		$("#"+menuButtonArray[index]).addClass("menuOver");
		thisMenuItem=index;
	}
}
function performFadeout(){
	if(allowFade && !flyoutShowing){
		dropMenus();
	}
}
function dropMenus(){
	if(typeof(devKeepMenusOpen)=="undefined" || !devKeepMenusOpen){
		allowFade=true;
		$("#menuHolder").slideUp(function(){
			if(allowFade){
				// Need this check because it could still get overridden by another call to launchMenus() during the timeout period
				$(".dropMenu").removeClass("dropMenuOver");
				triggered=false;
			}
		});
		$("#slider1").stop().css({left: "46px"});
		$("#slider2").stop().css({left: "0px"});
		$("#panel0 div, #panel1 div").removeClass("over");
		$("#menuFade").stop().animate({"opacity": 0}, (function(){
			$("#menuContainer").css("height", "0px");
		}));
	}
}
function setFlyoutCovered(bool){
	flyoutShowing=bool;
	if(bool){
		$("#drop"+buttonOver).addClass("dropMenuOver");
	} else {
		hideMenus();
	}
}
/////////////
// Following function is for opening popups on the site:
var popUpWin=0;
function newWin(URLStr, left, top, width, height){
	if(popUpWin){
		try{
			bClosed=popUpWin.closed; // For IE bug with "unclosed" windows
		}
		catch(e){
			bClosed=true;
		}
		if(!bClosed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=0,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
// Following is to put Flash on pages without the "double call":
var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;var isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;var isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;function ControlVersion(){var version;var axo;var e;try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version=axo.GetVariable("$version")}catch(e){}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version="WIN 6,0,21,0";axo.AllowScriptAccess="always";version=axo.GetVariable("$version")}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version=axo.GetVariable("$version")}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version="WIN 3,0,18,0"}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");version="WIN 2,0,0,11"}catch(e){version=-1}}return version}function GetSwfVer(){var flashVer=-1;if(navigator.plugins!=null&&navigator.plugins.length>0){if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]){var swVer2=navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"";var flashDescription=navigator.plugins["Shockwave Flash"+swVer2].description;var descArray=flashDescription.split(" ");var tempArrayMajor=descArray[2].split(".");var versionMajor=tempArrayMajor[0];var versionMinor=tempArrayMajor[1];var versionRevision=descArray[3];if(versionRevision==""){versionRevision=descArray[4]}if(versionRevision[0]=="d"){versionRevision=versionRevision.substring(1)}else if(versionRevision[0]=="r"){versionRevision=versionRevision.substring(1);if(versionRevision.indexOf("d")>0){versionRevision=versionRevision.substring(0,versionRevision.indexOf("d"))}}var flashVer=versionMajor+"."+versionMinor+"."+versionRevision}}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6")!=-1)flashVer=4;else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5")!=-1)flashVer=3;else if(navigator.userAgent.toLowerCase().indexOf("webtv")!=-1)flashVer=2;else if(isIE&&isWin&&!isOpera){flashVer=ControlVersion()}return flashVer}function DetectFlashVer(reqMajorVer,reqMinorVer,reqRevision){versionStr=GetSwfVer();if(versionStr==-1){return false}else if(versionStr!=0){if(isIE&&isWin&&!isOpera){tempArray=versionStr.split(" ");tempString=tempArray[1];versionArray=tempString.split(",")}else{versionArray=versionStr.split(".")}var versionMajor=versionArray[0];var versionMinor=versionArray[1];var versionRevision=versionArray[2];if(versionMajor>parseFloat(reqMajorVer)){return true}else if(versionMajor==parseFloat(reqMajorVer)){if(versionMinor>parseFloat(reqMinorVer))return true;else if(versionMinor==parseFloat(reqMinorVer)){if(versionRevision>=parseFloat(reqRevision))return true}}return false}}function AC_AddExtension(src,ext){if(src.indexOf('?')!=-1)return src.replace(/\?/,ext+'?');else return src+ext}function AC_Generateobj(objAttrs,params,embedAttrs){var str='';if(isIE&&isWin&&!isOpera){str+='<object ';for(var i in objAttrs){str+=i+'="'+objAttrs[i]+'" '}str+='>';for(var i in params){str+='<param name="'+i+'" value="'+params[i]+'" /> '}str+='</object>'}else{str+='<embed ';for(var i in embedAttrs){str+=i+'="'+embedAttrs[i]+'" '}str+='> </embed>'}document.write(str)}function AC_FL_RunContent(){var ret=AC_GetArgs(arguments,".swf","movie","clsid:d27cdb6e-ae6d-11cf-96b8-444553540000","application/x-shockwave-flash");AC_Generateobj(ret.objAttrs,ret.params,ret.embedAttrs)}function AC_SW_RunContent(){var ret=AC_GetArgs(arguments,".dcr","src","clsid:166B1BCA-3F9C-11CF-8075-444553540000",null);AC_Generateobj(ret.objAttrs,ret.params,ret.embedAttrs)}function AC_GetArgs(args,ext,srcParamName,classid,mimeType){var ret=new Object();ret.embedAttrs=new Object();ret.params=new Object();ret.objAttrs=new Object();for(var i=0;i<args.length;i=i+2){var currArg=args[i].toLowerCase();switch(currArg){case"classid":break;case"pluginspage":ret.embedAttrs[args[i]]=args[i+1];break;case"src":case"movie":args[i+1]=AC_AddExtension(args[i+1],ext);ret.embedAttrs["src"]=args[i+1];ret.params[srcParamName]=args[i+1];break;case"onafterupdate":case"onbeforeupdate":case"onblur":case"oncellchange":case"onclick":case"ondblclick":case"ondrag":case"ondragend":case"ondragenter":case"ondragleave":case"ondragover":case"ondrop":case"onfinish":case"onfocus":case"onhelp":case"onmousedown":case"onmouseup":case"onmouseover":case"onmousemove":case"onmouseout":case"onkeypress":case"onkeydown":case"onkeyup":case"onload":case"onlosecapture":case"onpropertychange":case"onreadystatechange":case"onrowsdelete":case"onrowenter":case"onrowexit":case"onrowsinserted":case"onstart":case"onscroll":case"onbeforeeditfocus":case"onactivate":case"onbeforedeactivate":case"ondeactivate":case"type":case"codebase":case"id":ret.objAttrs[args[i]]=args[i+1];break;case"width":case"height":case"align":case"vspace":case"hspace":case"class":case"title":case"accesskey":case"name":case"tabindex":ret.embedAttrs[args[i]]=ret.objAttrs[args[i]]=args[i+1];break;default:ret.embedAttrs[args[i]]=ret.params[args[i]]=args[i+1]}}ret.objAttrs["classid"]=classid;if(mimeType)ret.embedAttrs["type"]=mimeType;return ret};
var MM_contentVersion=9;var MM_FlashCanPlay;var plugin=(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"])?navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin:0;if(plugin){var words=navigator.plugins["Shockwave Flash"].description.split(" ");for(var i=0;i<words.length;++i){if(isNaN(parseInt(words[i]))){continue}var MM_PluginVersion=words[i]}MM_FlashCanPlay=MM_PluginVersion>=MM_contentVersion}else if(navigator.userAgent&&navigator.userAgent.indexOf("MSIE")>=0&&(navigator.appVersion.indexOf("Win")!=-1)){document.write('<SCR'+'IPT LANGUAGE=VBScript\> \n');document.write('on error resume next \n');document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');document.write('</SCR'+'IPT\> \n')};
function flashLink(linkToGet){
	window.location=linkToGet;
}
