﻿// JScript File
$(document).ready(function(){
	//set zebra striping (odd/even bg coloring) for all results lists 
	$(".om-zebra div.om-item:odd").addClass("om-even");
	$("table tr:odd").addClass("om-odd");
	$("table tr:even").addClass("om-even");
	
	//set dropdowns
	$("#secondaryNav li").hover(function(){ 
		    $(this).addClass("hover"); 
		},function(){ 
		      $(this).removeClass("hover"); 
	});
	
}); 
var isEnabled=true;
function initLeaders(){
	
	//set collapsable panels
	$(".expandGroup .title").click(function(){
		expandPanel(this);
	});
	
	//open first panel of accordian group for leaders
	var allTitleElements=$(".leaders .expandGroup .title");
	if(allTitleElements.length>0){
		expandPanel(allTitleElements[0]);
	}
	$(allTitleElements).hover(function(){ 
		    $(this).addClass("titlehover"); 
		    },function(){ 
		      $(this).removeClass("titlehover"); 
	});
	
	//make the leaders boxes clickable in the side nav
	$(".leadersNavContainer .leadersList li").hover(function(){ 
			$(this).addClass("selected"); 
		},function(){ 
			$(this).removeClass("selected"); 
	});
	//extract link url and use it if li is clicked
	$(".leadersNavContainer .leadersList li").click(function(){ 
		var linkUrl=$(this).find("a").attr("href");
		if(linkUrl!="#"){
			window.location=linkUrl;
		}
	});
	
	$("#leaderScrollerUp").addClass("disabled");
	
	createLeaderNav();
}
function expandPanel(titleBarElement){
	var parentContainer=$(titleBarElement).parent("div.expandGroup");
	var collapsableContentContainer=$(parentContainer).find(".content");
	collapsableContentContainer.slideToggle(500);
		
	if($(parentContainer).hasClass("expanded")){
		$(parentContainer).removeClass("expanded");
	} else {
		$(parentContainer).addClass("expanded");
	}
	return false;
}
function createLeaderNav(){
	var allLeaders=$(".leadersList li");
	if(allLeaders.length>4){ //then the area needs some scrolling
		$(".navScroller").show();
		$("#leaderScrollerUp").click(function(){
			
		
			var currentTop=$(".leadersList").css("top");
			currentTop=currentTop.replace("px","");
			currentTop=currentTop-0;
			
			
			var liHeight=$(allLeaders[0]).height();
			liHeight=currentTop+liHeight+20;
			
			$("#leaderScrollerDown").removeClass("disabled");	
			if ((liHeight-1) < 0 && isEnabled) {
				isEnabled=false;
				
				$(".leadersList").animate({top:liHeight},300,function(){
					//reenable
					isEnabled=true;
					
				});
			} else {
				$("#leaderScrollerUp").addClass("disabled");
			}
		});
		$("#leaderScrollerDown").click(function(){
			
			var currentTop=$(".leadersList").css("top");
			currentTop=currentTop.replace("px","");
			currentTop=currentTop-0;
			
			var originalLiHeight=$(allLeaders[0]).height();
			var liHeight=originalLiHeight+20;
			liHeight=currentTop-liHeight;
			
			var listHeight=$(".leadersList").height();
			var adjustedListHeight=(listHeight-(originalLiHeight*4));
			adjustedListHeight=0-adjustedListHeight;

			
			$("#leaderScrollerUp").removeClass("disabled");	
			
			
			if(liHeight>adjustedListHeight && isEnabled){
				isEnabled=false;
				$(".leadersList").animate({top:liHeight},300,function(){
					//reenable
					isEnabled=true;
				});
			}else {
				$("#leaderScrollerDown").addClass("disabled");
			}
		});
	}
}

