//GLOBAL JAVASCRIPT VARS FOR SLIDING WORDS
var word_slider_counter = 0;
var current_word_slide = 0;

/*******************************************************/
/*** ON LOAD *******************************************/
/*******************************************************/
$(function(){
	//RSS FEEDS
	$('#feed1').rssfeed('http://www.districtadministration.com/feeds/dailynews.aspx', {
		limit: 5
	});
	$('#feed2').rssfeed('http://feeds.feedburner.com/SchoolBusFleet', {
		limit: 5
	});
	$('#feed3').rssfeed('http://stnonline.com/component/jlord_rss/feed/15', {
		limit: 5
	});
	
	
	
	//ADD LAST CLASS TO DYNAMIC LISTS
	$(".left_nav li:last").addClass("last");
	
	//SHOW OPEN SUBNAV ITEMS
	$(".subpage .opening_list li").each(function(){
		if($(this).hasClass("open"))
		{
			$(".hidden_text", this).show();
		}
		$(this).css("min-height",$(".opener", this).height());
	});
	
	//ARROW BULLET LISTS
	$(".subpage .opening_list a.opener").click(function(){
		//CLOSE IF OPEN
		if($(this).parent().hasClass("open"))
		{
			$(this).siblings(".hidden_text").slideUp(500);
			$(this).parent().removeClass("open");
		}
		//OPEN IF CLOSE
		else
		{
			$(".subpage .opening_list li").removeClass("open")
			$(".subpage .opening_list li .hidden_text").slideUp(500);
			
			$(this).siblings(".hidden_text").slideDown(500, function(){$(window).scrollTo($(this).siblings(".opener"),{duration:500});});
			$(this).parent().addClass("open");
			
		}
		
	});

	//COUNT LI'S IN PHRASE LIST
	$("#word_slider li").each(function(){word_slider_counter++;});
	//ADJUST FOR 0 BASE
	word_slider_counter--;
	//CALL ANIMATION ON LOAD
	//changeWordSlider();
	//CALL PHRASE LIST ANIMATION ON INTERVAL
	//setInterval("changeWordSlider()", 15000);
	
	
	//CLICK PRINT IN BOTTOM LEFT CORNER OF PAGE
	$("#share_print li:eq(1) a").click(function(){
		window.print();
		return false;
	});
	
	//YOUR ROUTE OPENING FUNCTIONALITY
	var pathHeight = $(".site_path ul").height()
	$(".site_path ul").height("14px");
	$(".site_path p").click(function(){
		if($(this).hasClass("open"))
		{
			$(".site_path ul").animate({height:14},250);
			$(this).removeClass("open");
			$("img",this).attr("src","images/separating_arrow_right.gif");
		}
		else
		{
			$(".site_path ul").animate({height:pathHeight},250);
			$(this).addClass("open");
			$("img",this).attr("src","images/separating_arrow_down.gif");
		}
	});
	
	
	//HOMEPAGE FEATURE BOXES OPENING FUNCTIONALITY
	var teamsPodTitleHeight = $("#teams_list .title").height();
	var teamsPodHeight = $("#teams_list .teaser").height();
	var newsPodTitleHeight = $("#news_list .title").height();
	var newsPodHeight = $("#news_list .teaser").height();
	//$("#teams_list .teaser,#news_list .teaser,#teams_list .title,#news_list .title").height("13px");
	$("#teams_list .title img,#news_list .title img").attr("src","images/black_arrow_down.gif");
	$("#teams_list .title,#news_list .title").addClass("open");
	
	$("ul li.title").click(function(){
		if($(this).hasClass("open"))
		{
			$(this).siblings(".teaser").animate({height:13},250);
			$(this).animate({height:13},250);
			$(this).removeClass("open");
			$("img",this).attr("src","images/black_arrow.gif");
		}
		else
		{
			if($(this).parent("ul").attr("id") == "news_list")
			{
				$(this).animate({height:newsPodTitleHeight},250);
				$(this).siblings(".teaser").animate({height:newsPodHeight},250);
			}
			else
			{
				$(this).animate({height:teamsPodTitleHeight},250);
				$(this).siblings(".teaser").animate({height:teamsPodHeight},250);
			}
			$(this).addClass("open");
			$("img",this).attr("src","images/black_arrow_down.gif");
		}
	});
	
	//TOP NAVIGATION OPENING FUNCTIONALITY
	var navTimeout;
	$("#nav_wrapper>li").each(function(){
		var theNavHeight = $("ul", this).height();
		$("ul", this).height(0).hide();
		
		$(this).mouseover(function(){
			clearTimeout(navTimeout);
			var theCurrentNavElm = $("ul",this)
			$("#nav_wrapper>li>ul").stop(true,true).not(theCurrentNavElm).animate({height:0},200,function(){
				$("#nav_wrapper>li>ul").not(theCurrentNavElm).hide();
				
			});
			$("ul",this).show();
			$("ul",this).stop(true,true).animate({height:theNavHeight},200);
		}).mouseout(function(){
			navTimeout = setTimeout('closeNav('+$(this).index()+')',50);
		});
	});
	
	
	var theHash = window.location.hash;
	//alert(theHash);
	if(theHash != "")
	{
		$(".opening_list .opener").each(function(){
			//alert("The hash is: "+ theHash + "\n The HTML is: " + $(this).html());
			// alert($(this).html())
			if (theHash == $(this).attr("href"))
			{
				//alert("MADE IT IN")
				$(this).click();
				$(window).scrollTo($(this),{duration:500});
			}
		});
	}
	
});
/*******************************************************/
/*******************************************************/

/*******************************************************/
/*** CLOSE TOP NAVIGATION ******************************/
/*******************************************************/

function closeNav(el)
{
	$("#nav_wrapper>li>ul").eq(el).animate({height:0},300,function(){
				$("#nav_wrapper>li>ul").hide();
			});
}
/*******************************************************/
/*******************************************************/

/*******************************************************/
/*** CHANGE WORDS AT TOP OF PAGE ***********************/
/*******************************************************/
function changeWordSlider()
{
	//ANIMATE RED WORD TO LEFT
	$("#word_slider li.red_word").animate({left:"0"},300, function(){
		//HIDE NON CURRENT PHRASES
		$("#word_slider li").not(this).hide();
		//SHOW CURRENT PHRASE
		$("#word_slider li").eq(current_word_slide).show();
		//INCRIMENT COUNTER
		if(current_word_slide < word_slider_counter-1)
		{
			current_word_slide++;
		}
		//RESET COUNTER
		else
		{
			current_word_slide=0;
		}
	});
	//ANIMATE RED WORD TO RIGHT EDGE OF CURRENT PHRASE
	$("#word_slider li.red_word").animate({left:$("#word_slider li").eq(current_word_slide).width()},300);
}
/*******************************************************/
/*******************************************************/
