$(document).ready(init);

var EMPTY_HTML_LENGTH = 5;

function init(){
	styleMainNav();
	addMainNavFunc();
	styleFloatNav();
	addFloatNavFunc();
	styleSubNav();
	addSubNavFunc();
	styleFooterNav();
	
	removeBlankBoxes();
}
//-------------------------------------------------------------------------------------------------
function removeBlankBoxes(){
	var greenOn = true;
		
	if(String($("div.greenBox").html()).length <= EMPTY_HTML_LENGTH){
		$("div.greenBox").remove();
		greenOn = false;
	}
	
	if(String($("div.whiteBox").html()).length <= EMPTY_HTML_LENGTH){
		$("div.whiteBox").remove();
		
		if(greenOn){
			$("div#islandCap").css("background-image", "url('/images/islandCap_green.png'");
			
			if($.browser.msie && $.browser.version=="6.0"){
				$("div#islandCap").css("background", "none");
				$("div#islandCap").css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/islandCap_green.png', sizingMethod='fixed'");
			}

		}
	}
}
//-------------------------------------------------------------------------------------------------
//NAV
//-------------------------------------------------------------------------------------------------
function styleMainNav(){
	 $("ul.mainNav li.mainNavOff").after("<li class='navPipe'>|</li>");
	 $("ul.mainNav li.mainNavOn").after("<li class='navPipe'>|</li>");
	 $($("ul.mainNav li")[$("ul.mainNav li").length-1]).remove();
}
//-------------------------------------------------------------------------------------------------
function addMainNavFunc(){
	$("ul.mainNav li.mainNavOff").hover(hoverInHand, hoverOutHand);
	$("ul.mainNav li.mainNavOff").click(clickHand);
	$("ul.mainNav li.mainNavOn").hover(hoverInHand, hoverOutHand);
	$("ul.mainNav li.mainNavOn").click(clickHand);
	
	setPipes($("ul.mainNav li.mainNavOn"), "display", "none");
}
//-------------------------------------------------------------------------------------------------
function styleFloatNav(){
	$("ul.mainNav ul li.subNavOn a").css("background-color", "#45a53e");
	var navs = $("ul.mainNav li ul");
	
	navs.css("visibility", "hidden");
	
	for(var i=0; i<navs.length; i++){
		if($("li", navs[i]).length <= 1){
			$(navs[i]).remove();
		}else{
			addFloatStripes($("li", navs[i]));
		}
	}
}
//-------------------------------------------------------------------------------------------------
function addFloatStripes(navLis){
	for(var i=2; i<navLis.length; i++){
		$(navLis[i]).css("border-top", "solid 2px #b1d333");
	}
}
//-------------------------------------------------------------------------------------------------
function addFloatNavFunc(){
	$("ul.mainNav ul li.subNavOff a").hover(subHoverInHand, subHoverOutHand);
	$("ul.mainNav ul li.subNavOff a").click(subClickHand);
}
//-------------------------------------------------------------------------------------------------
function addSubNavFunc(){
	var navs = $("ul.subNav li a");
	
	for(var i=0; i<navs.length; i++){
		
		if($(navs[i]).parent().hasClass("subNavOff")){
			$(navs[i]).hover(subHoverInHand, subHoverOutHand);
			$(navs[i]).click(subClickHand);
		}
	}
}
//-------------------------------------------------------------------------------------------------
function styleFooterNav(){
	var as = $("div.footerNav a");
	for(var i=0; i<as.length-1; i++){
		$(as[i]).after("<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>");
	}
}
//-------------------------------------------------------------------------------------------------
function setPipes(button, cssProp, state){
	$(button).next().css(cssProp, state);
	$(button).prev().css(cssProp, state);
}
//-------------------------------------------------------------------------------------------------
function hoverOutAction(button){
	$(button).css("background-color", "");
	$("a", button).css("color", "");
	
	$("ul", button).css("visibility", "hidden");

	setPipes(button, "visibility", "visible");
}
//-------------------------------------------------------------------------------------------------
function subHoverOutAction(button){
	$(button).css("background-color", "");
}
//-------------------------------------------------------------------------------------------------
function styleSubNav(){
	var header = $("div.subNav div#parentHeader").text();
	
	if(header.length > 0){
		header = trimWhiteSpace(header);
		header = header.replace(/\s/g, "<br /><br />");
		$("div.subNav div#parentHeader").html(header);
	}
}
//-------------------------------------------------------------------------------------------------
function trimWhiteSpace(text) {
	return text.replace(/^\s+|\s+$/g,"");
}
//-------------------------------------------------------------------------------------------------
function popupLinkClick(url) {
    var window_dimensions = "toolbars=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=yes";
    window.opener = self;
    window.close();
    window.open(url, "_blank", window_dimensions);
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height - 100);
    return false;
}  
//-------------------------------------------------------------------------------------------------
//HANDLERS
//-------------------------------------------------------------------------------------------------
function clickHand(){
	hoverOutAction($(this));
}
//-------------------------------------------------------------------------------------------------
function hoverInHand(){
	$(this).css("background-color", "#8cc63f");
	$("a", this).css("color", "#FFFFFF");
	
	$("ul", this).css("visibility", "visible");
	
	setPipes($(this), "visibility", "hidden");
}
//-------------------------------------------------------------------------------------------------
function hoverOutHand(){
	hoverOutAction($(this));
}
//-------------------------------------------------------------------------------------------------
function subClickHand(){
	subHoverOutAction($(this));
}
//-------------------------------------------------------------------------------------------------
function subHoverInHand(){
	$(this).css("background-color", "#53c74a");
}
//-------------------------------------------------------------------------------------------------
function subHoverOutHand(){
	subHoverOutAction($(this));
}
//-------------------------------------------------------------------------------------------------
