setMenu = {
	
	ul_id: "mainMenu",
	
	initialize: function() {
		var i,j,node,a,navRoot;
		setMenu.navRoot=navRoot = document.getElementById(setMenu.ul_id);
		if (!navRoot) return;
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				//setting child li events
				var childLi=node.getElementsByTagName("LI");
				for (j=0; j<childLi.length; j++) {
					childLi[j].onmouseover=function(){setMenu.hover2(this)};
				}
				//setting top level a events
				for (j=0; j<node.childNodes.length; j++) {
					if (node.childNodes[j].nodeName=="A") {
						a=node.childNodes[j];
						a.onmouseover=function(){setMenu.hover(this)};
					}
				}
			}
		}
		
		//display active menu items on load
		$("#mainMenu .activeparent > ul").show();
		$("#nav").mouseleave(function(){
		$("#mainMenu .activeparent  ul").hide();
		$("#mainMenu .active  ul").hide();
		$("#mainMenu .active").removeClass("active");
		$("#mainMenu .activeparent > ul").show();
	});
	},
	hover: function(a)
	{
		var navRoot,i,node,ul;
		navRoot=setMenu.navRoot;
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				ul=node.getElementsByTagName("ul");
				if (ul && ul.length>0) {
					if (node==a.parentNode) //reveal
					{
						$(ul[0].parentNode).addClass("active");
						ul[0].style.display="block";
					}
					else //hide
					{
						$(ul[0].parentNode).removeClass("active");
						ul[0].style.display="none";
					}
				}
			}
		}
	},
	hover2: function(li)
	{
		var parentul=li.parentNode,ul,node;
		for (i=0; i<parentul.childNodes.length; i++) 
		{
			node = parentul.childNodes[i];
			if (node.nodeName=="LI") {
				ul=node.getElementsByTagName("ul");
				if (ul && ul.length>0) {
					ul[0].style.display=(node==li)? "block":"none";
					//ul[0].parentNode.className =(node==a.parentNode)? " active":" inactive";
				}
			}
		}
		
	}
};
var enlargeShrink={
	
	onload: function()
	{
		$("#slideshowControls a.swapLink").click(function(){enlargeShrink.click(this); return false;});	
	},
	click: function(controller)
	{
		var enlarge=(controller.id=="enlargeBtn");  //true if enlarging, false if not
		//document.getElementById("galleryWrapper").className= (enlarge==true)? "enlarged" : "shrunk";
		var currentSlide=slideshow.currentSlide+1;
		if (enlarge)
		{
			document.getElementById("galleryWrapper").className="enlarged";
			$("#slideshowContent .imageSlide").each(function(){this.style.display="";});
			$("#pane-"+currentSlide+" .shortImage").show().fadeOut("slow");
			$("#pane-"+currentSlide+" .fullImage").hide().fadeIn("slow");
		}
		else
		{
			$("#slideshowContent .imageSlide").each(function(){this.style.display="";});
			$("#pane-"+currentSlide+" .shortImage").hide().fadeIn("slow");
			$("#pane-"+currentSlide+" .fullImage").show().fadeOut("slow",function(){document.getElementById("galleryWrapper").className="shrunk";});
		}

	}
};
var anchorLink={
	
	onload: function() {
		
		if (window.location.hash) {
			var classname = window.location.hash.substring(1);
			var anchor = $(".section a[name="+classname+"]");	
			var extendedDiv = anchor[0].parentNode;
			var sectionDiv = extendedDiv.parentNode;
			
			if (sectionDiv.className == "extendedContent") {
				$(sectionDiv.parentNode).addClass("highlighted");
				$(extendedDiv.parentNode).show();
			} else if (sectionDiv.className == "leftColumn") {
				$(sectionDiv.parentNode.parentNode).addClass("highlighted");
				$(extendedDiv.parentNode.parentNode).show();
			} else {
				$(sectionDiv).addClass("highlighted");
				$(extendedDiv).show();
			}
		}

	}
};
function initOverLabels () {
  if (!document.getElementById) return;      

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // labels with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      } 

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to label elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
      return true;
    }
  }
};
configurePopUpBox={ 
 
	load: function() {
	$("#videoWrapper a.boxBtn ").click(function(){
			var url = $(this).attr('href');
			var hash = url.split("#");
			var vidName = hash[1];
			
			configurePopUpBox.click(vidName); 
			return false;
	});
	$(".boxForm a.close ").click(function(){
		$(".boxForm").hide();$("#overlay").hide();
		return false;
	}); 
	},
	click: function(vidName) {
 		$("#"+vidName).show();
 		$("#overlay").show();
	}
};
configMapSwap={

	load: function(){
	var map_swap = $("#mapSwap div");
	var swap_link = $("#mapSwap a.swapLink");
	
	if (map_swap.length>1){
	
		map_swap.each(function(i){
			this.img_index=i;
         swap_link[i].img_index=i;
			if (i>0){
				this.style.display="none";
			}
		});
      swap_link.click(function(){
				var imgs=$("#mapSwap div");
				var img_length=imgs.length;
				var this_img_index=this.img_index;
				var next_img_index=this_img_index+1;

				if (next_img_index>=img_length){
					next_img_index=0;
				}

				imgs.each(function(j){
					if (j==next_img_index){
						$(this).fadeIn("fast");
					}else{
						$(this).fadeOut("fast");
					}
				});
		});
	}
	}
};

$(window).load(function(){	
	setMenu.initialize();
	enlargeShrink.onload();	
	anchorLink.onload();
	initOverLabels();
	configurePopUpBox.load();
	configMapSwap.load();
});