willow.fixPodiumNav();

willow.ready(function($) {
	// Podium Search 
	$('#search').pdSearch({showButton:true, showButtonClass:'searchBtn', showButtonText:''}); 
	$(".searchBtn").css("margin","0");
	
	willow.getMenu("138086|138087|138089|138088|138090",function(data){
		var $sitemap = $(".sitemap");
		if($sitemap.length > 0){
			$sitemap.sitemap(data);
			//uncomment this if you want to expand all by default $("#expand").click();
		}
		// Adding Left Column Menu via jQuery Template
		$("#navTmpl").tmpl(data.menu,{
			len : willow.len
		}).prependTo("#leftColMenu");

		$("#footNavTmpl").tmpl(data.menu).prependTo("#footerNav");// Footer nav
		willow.menuActions(); // After menu completely built out add events 
		willow.openMenu(pdGlobal.currentPages[0].id); // Open current L1 menu
		
		$("#sitemapBtn").click(function(e){
			e.preventDefault();
			$("#footerNav").slideToggle(1000,function(){
				window.scrollTo(0, document.body.scrollHeight);
			});
			$("#footer").toggleClass("smOpen");
			$("#sitemapBtn").toggleClass("open");
		});
	});
	
	$("#Form1").bulletin({data:[{type:"news",id:12602}]});// EM bulletin
	if($(".annualFund").length > 0){$(".annualFund").annualfund();} // Annual Fund
	
	// jQuery template self managed links
	willow.getLinks(14831,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		$("#linksTmpl").tmpl(links,{
			target : willow.checkTarget,
			img : willow.checkImg
		}).appendTo("#socialMedia");
	});
	
	if(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id === 138905){
		$("body").addClass("homepage");
	}
	if(pdGlobal.loginBoxMode === "Collapsed"){
		$("#lcMenuHeader").css("display","none");
		$(".u1h").css("background","url(http://loucol/ftpimages/552/podium/style796/images/schNavHeaderTall.png) bottom left no-repeat");
	}
	
	// Financial Assisstance Calculator Data
	if($(".faCalc").length > 0){
		willow.calcTable = new Array(42); // Build array
		for (var i = 0; i < 42; i++) {
			willow.calcTable[i] = [' ', ' ', ' ']; 
		}
		
		// Add data
		// Family size 7
		willow.calcTable[0][0] = '7'; willow.calcTable[0][1] = '< $50,000';				willow.calcTable[0][2] = '$1,000';
		willow.calcTable[1][0] = '7'; willow.calcTable[1][1] = '$50,000 - $80,000';		willow.calcTable[1][2] = 'N/A';
		willow.calcTable[2][0] = '7'; willow.calcTable[2][1] = '$80,001 - $110,000';	willow.calcTable[2][2] = 'N/A';
		willow.calcTable[3][0] = '7'; willow.calcTable[3][1] = '$110,001 - $140,000';	willow.calcTable[3][2] = 'N/A';
		willow.calcTable[4][0] = '7'; willow.calcTable[4][1] = '$140,001 - $170,000';	willow.calcTable[4][2] = 'N/A';
		willow.calcTable[5][0] = '7'; willow.calcTable[5][1] = '$170,001+';				willow.calcTable[5][2] = '$5,500';
		// Family size 6
		willow.calcTable[6][0] = '6'; willow.calcTable[6][1] = '< $50,000';				willow.calcTable[6][2] = '$1,500 - $3,000';
		willow.calcTable[7][0] = '6'; willow.calcTable[7][1] = '$50,000 - $80,000';		willow.calcTable[7][2] = '$3,500 - $4,000';
		willow.calcTable[8][0] = '6'; willow.calcTable[8][1] = '$80,001 - $110,000';	willow.calcTable[8][2] = 'N/A';
		willow.calcTable[9][0] = '6'; willow.calcTable[9][1] = '$110,001 - $140,000';	willow.calcTable[9][2] = '$3,500 - $14,000';
		willow.calcTable[10][0] = '6'; willow.calcTable[10][1] = '$140,001 - $170,000';	willow.calcTable[10][2] = '$10,000';
		willow.calcTable[11][0] = '6'; willow.calcTable[11][1] = '$170,001+';			willow.calcTable[11][2] = '$10,000';
		// Family size 5
		willow.calcTable[12][0] = '5'; willow.calcTable[12][1] = '< $50,000';			willow.calcTable[12][2] = '$1,200 - $10,000';
		willow.calcTable[13][0] = '5'; willow.calcTable[13][1] = '$50,000 - $80,000';	willow.calcTable[13][2] = '$4,000 - $10,000';
		willow.calcTable[14][0] = '5'; willow.calcTable[14][1] = '$80,001 - $110,000';	willow.calcTable[14][2] = '$2,500 - $40,000';
		willow.calcTable[15][0] = '5'; willow.calcTable[15][1] = '$110,001 - $140,000';	willow.calcTable[15][2] = '$3,500 - $10,000';
		willow.calcTable[16][0] = '5'; willow.calcTable[16][1] = '$140,001 - $170,000';	willow.calcTable[16][2] = '$7,000 - $8,000';
		willow.calcTable[17][0] = '5'; willow.calcTable[17][1] = '$170,001+';			willow.calcTable[17][2] = '$2,500 - $17,000';
		// Family size 4
		willow.calcTable[18][0] = '4'; willow.calcTable[18][1] = '< $50,000';			willow.calcTable[18][2] = '$2,500 - $13,700';
		willow.calcTable[19][0] = '4'; willow.calcTable[19][1] = '$50,000 - $80,000';	willow.calcTable[19][2] = '$2,000 - $8,500';
		willow.calcTable[20][0] = '4'; willow.calcTable[20][1] = '$80,001 - $110,000';	willow.calcTable[20][2] = '$3,000 - $14,700';
		willow.calcTable[21][0] = '4'; willow.calcTable[21][1] = '$110,001 - $140,000';	willow.calcTable[21][2] = '$2,200 - $10,000';
		willow.calcTable[22][0] = '4'; willow.calcTable[22][1] = '$140,001 - $170,000';	willow.calcTable[22][2] = '$6,250 - $17,700';
		willow.calcTable[23][0] = '4'; willow.calcTable[23][1] = '$170,001+';			willow.calcTable[23][2] = '$4,500 - $17,700';
		// Family size 3
		willow.calcTable[24][0] = '3'; willow.calcTable[24][1] = '< $50,000';			willow.calcTable[24][2] = '$2,000 - $12,000';
		willow.calcTable[25][0] = '3'; willow.calcTable[25][1] = '$50,000 - $80,000';	willow.calcTable[25][2] = '$4,000 - $8,900';
		willow.calcTable[26][0] = '3'; willow.calcTable[26][1] = '$80,001 - $110,000';	willow.calcTable[26][2] = '$10,000 - $15,000';
		willow.calcTable[27][0] = '3'; willow.calcTable[27][1] = '$110,001 - $140,000';	willow.calcTable[27][2] = '$10,000 - $13,000';
		willow.calcTable[28][0] = '3'; willow.calcTable[28][1] = '$140,001 - $170,000';	willow.calcTable[28][2] = 'N/A';
		willow.calcTable[29][0] = '3'; willow.calcTable[29][1] = '$170,001+';			willow.calcTable[29][2] = 'N/A';
		// Family size 2
		willow.calcTable[30][0] = '2'; willow.calcTable[30][1] = '< $50,000';			willow.calcTable[30][2] = '$2,000 - $15,000';
		willow.calcTable[31][0] = '2'; willow.calcTable[31][1] = '$50,000 - $80,000';	willow.calcTable[31][2] = '$3,000 - $11,000';
		willow.calcTable[32][0] = '2'; willow.calcTable[32][1] = '$80,001 - $110,000';	willow.calcTable[32][2] = '$5,000';
		willow.calcTable[33][0] = '2'; willow.calcTable[33][1] = '$110,001 - $140,000';	willow.calcTable[33][2] = '$14,000';
		willow.calcTable[34][0] = '2'; willow.calcTable[34][1] = '$140,001 - $170,000';	willow.calcTable[34][2] = 'N/A';
		willow.calcTable[35][0] = '2'; willow.calcTable[35][1] = '$170,001+';			willow.calcTable[35][2] = '$10,000';
		// Family size 1
		willow.calcTable[36][0] = '1'; willow.calcTable[36][1] = '< $50,000';			willow.calcTable[36][2] = '$10,000';
		willow.calcTable[37][0] = '1'; willow.calcTable[37][1] = '$50,000 - $80,000';	willow.calcTable[37][2] = 'N/A';
		willow.calcTable[38][0] = '1'; willow.calcTable[38][1] = '$80,001 - $110,000';	willow.calcTable[38][2] = 'N/A';
		willow.calcTable[39][0] = '1'; willow.calcTable[39][1] = '$110,001 - $140,000';	willow.calcTable[39][2] = 'N/A';
		willow.calcTable[40][0] = '1'; willow.calcTable[40][1] = '$140,001 - $170,000';	willow.calcTable[40][2] = 'N/A';
		willow.calcTable[41][0] = '1'; willow.calcTable[41][1] = '$170,001+';			willow.calcTable[41][2] = 'N/A';
	}
});

// Checks to see if self managed link has the 'open in new tab' flag set 
willow.checkTarget = function(t){
	if(t === 1 || t === true || t === "true"){
		return " target='_blank'";
	}
	return "";
};

// Checks to see if self managed link has an image
willow.checkImg = function(lk){
	if(typeof lk.data.image !== "undefined"){
		if(lk.data.image.height > 0 && lk.data.image.width > 0){
			return "<img src='"+lk.data.image.path+"' height='"+lk.data.image.height+"' width='"+lk.data.image.width+"' alt='"+lk.data.title+"' border='0'/>"
		}else{
			return "<img src='"+lk.data.image.path+"' alt='"+lk.data.title+"' border='0'/>"
		}
	}
	return lk.data.title;
}

// Helper function to determine if an L2 has any L3s for building out menu HTML structure
willow.len = function($obj){
	return $obj.length;
}

willow.menuActions = function(){
	var $allL1 = $(".L1_a"),
		$allL2 = $(".L2"),
		$L2s = $(".L2_a"),
		$L3s = $(".L3_a");
	
	$allL1.click(function(e){ // On click open/close menu
		e.preventDefault();
		var $this = $(this);
			$curL2 = $this.siblings(".L2");
		
		if($this.hasClass("on")){ // Close menu if it was the one clicked on and it's open
			$this.removeClass("on");
			$curL2.slideUp();
			return;
		}
		
		$allL1.removeClass("on"); // Close all menus
		$allL2.slideUp();
		
		if(!$this.hasClass("on")){ // Open menu if closed
			$this.addClass("on");
			$curL2.slideDown()
		}
	});
	
	$(".hasL3").hover(
		function(){ // On hover of L2 with L3 menu stop animation of current menu and animate it out all the way
			$(this).addClass("openFlyout").children(".L3_container").find(".L3").queue("fx", []).stop().animate({"left": 0});
		},
		function(){
			willow.closeMenus(); // Off hover close all flyouts
		}
	);
	
	for(var i = 0; i < $L2s.length; i++){ // Adds on state to proper L2 item
		var L2id = $L2s.eq(i).attr("id").split("_")[1];
		if(pdGlobal.currentPages.length > 1){
			if((L2id == pdGlobal.currentPages[1].id)){
				$L2s.eq(i).addClass("on");
			}
		}
	}
	for(var i = 0; i < $L3s.length; i++){ // Adds on state to proper L3 item
		var L3id = $L3s.eq(i).attr("id").split("_")[1];
		if(pdGlobal.currentPages.length > 2){
			if((L3id == pdGlobal.currentPages[2].id)){
				$L3s.eq(i).addClass("onL3");
			}
		}
	}
}

willow.closeMenus = function(){ // Close all menus, stops flyouts mid animation and animates all them back in
	$(".L3").queue("fx", []).stop().animate({"left": "-217"},function(){
		$(this).parents(".hasL3").removeClass("openFlyout");
	}).queue().dequeue();
}

willow.openMenu = function(id){ // Automatically opens proper menu when under an L1
	var $L1s = $(".L1_a");
	for(var i = 0; i < $L1s.length; i++){
		if($L1s.eq(i).attr("id").split("_")[1] == id){
			var $curL1 = $L1s.eq(i);
			$curL1.addClass("on").siblings(".L2").slideDown(1200);
		}
	}
}

// Display proper award depending on what the user inputed to drop down boxes
willow.calcAid = function(size, income){
	for(var i = 0; i < 42; i++){
		// If family size and income are same, show award with sliding down bottom section
		if(willow.calcTable[i][0] === size && willow.calcTable[i][1] === income){
			$(".faAwardAmount").html(willow.calcTable[i][2]);
			$(".faAward").slideDown();
			return;
		}
	}
}

