// JavaScript Document

//Clock.
function clock()
{
	var current_time=new Date();
	var hours=current_time.getHours();
	var minutes=current_time.getMinutes();
	var seconds=current_time.getSeconds();
	
//corrects military time
	if(hours > 12) 
		{
		hours = hours - 12;
		ap = "pm";
		}
	else ap="am";
	
	minutes=fixTime(minutes);
	seconds=fixTime(seconds);
	document.getElementById('time').innerHTML=hours+":"+minutes+":"+seconds+" "+ap;
	t=setTimeout('clock()',500);
}


//Adds a zero before single digit numbers.
function fixTime(x)
{
	if (x<10)
		{
			x="0"+x;
		}
	return x;
}

function resizeIframe(iframeHeight)
{
	document.getElementById('iframe_content').style.height=iframeHeight+"px";
	window.scrollTo(0,0);
}

//Content Animation.
$(document).ready(function(){
			
	//Hide the sidenav buttons that are unused.
	for(i=0;i<=5;i++) 
		{
			if ($("#sidenav ul li:eq(" + i + ") p").attr("id")==99)
			{
				$("#sidenav ul li:eq(" + i + ") p").css("display","none");	
			}
		}
	
	//Hide the links buttons that are unused.
	for(i=0;i<=6;i++) 
		{
			if ($("#links ul li:eq(" + i + ") a").attr("href")=="none")
			{
				$("#links ul li:eq(" + i + ") a").css("display","none");	
			}
		}
	
	//Auto select first sidenav item.
	$("#sidenav ul p:first").css("background-image","url(Images/sidenav_button_a.png)");
	
	//Changes sidenav button backgrounds.
	$("#sidenav ul p").mouseover(function(){
		var currentBackgroundImage=$(this).css("background-image").split("/");
		currentBackgroundImage=currentBackgroundImage[4].split('"');
		currentBackgroundImage=currentBackgroundImage[0];
		var mousedownBackgroundImage="sidenav_button_a.png";
		if (currentBackgroundImage!=mousedownBackgroundImage)
		{
			$(this).css("background-image","url(Images/sidenav_button_h.png)");
		}
	});
	
	$("#sidenav ul p").mouseout(function(){
		var currentBackgroundImage=$(this).css("background-image").split("/");
		currentBackgroundImage=currentBackgroundImage[4].split('"');
		currentBackgroundImage=currentBackgroundImage[0];
		var mousedownBackgroundImage="sidenav_button_a.png";
		if (currentBackgroundImage!=mousedownBackgroundImage)
		{
			$(this).css("background-image","url(Images/sidenav_button_l.png)");
		}
	});
	
	$("#sidenav ul p").mousedown(function(){
		for(i=0;i<=5;i++) 
		{
			$("#sidenav ul li:eq(" + i + ") p").css("background-image","url(Images/sidenav_button_l.png)");				
		}
		$(this).css("background-image","url(Images/sidenav_button_a.png)");
	});

	//Animates and changes main content.
	$("#sidenav ul p").click(function(){
		
		//Gets the id of the clicked sidenav button.
		var sidenavId=$(this).attr('id');
				
		//Check if sidenav button has been clicked and is being animated.
		if ($("#iframe_div").is(':animated')) 
		{
			return
		}
		
		$("#iframe_content").attr("src","organizations.php?id="+sidenavId);
	});
});

//Remove items that don't exist.
$(document).ready(function(){
	th1=$("#thumbnail_1").attr("src");		
	th2=$("#thumbnail_2").attr("src");
	th3=$("#thumbnail_3").attr("src");

	if (th1=="none_thumb.jpg"){
		$("#thumbnail_1").css("display","none");
	}
	if (th2=="none_thumb.jpg"){
		$("#thumbnail_2").css("display","none");
	}
	if (th3=="none_thumb.jpg"){
		$("#thumbnail_3").css("display","none");
	}
//Changes the large image inside the image gallery.
	
	$("#thumbnail_1").click(function(){
			var thumb1=$("#thumbnail_1").attr("src");
			thumb1=thumb1.replace("_thumb.jpg",".jpg");
			$("#content_img").attr("src",thumb1);
	});

	
	$("#thumbnail_2").click(function(){
			var thumb2=$("#thumbnail_2").attr("src");
			thumb2=thumb2.replace("_thumb.jpg",".jpg");
			$("#content_img").attr("src",thumb2);
	});
	
	$("#thumbnail_3").click(function(){
			var thumb3=$("#thumbnail_3").attr("src");
			thumb3=thumb3.replace("_thumb.jpg",".jpg");
			$("#content_img").attr("src",thumb3);
	});
//Deactivates more_info_button if there is not a page for it to go to.
	if($("#more_info_button a").exists())
		{
		var moreInfoButton=$("#more_info_button a").attr("href").split("?");
		var moreInfoButton=moreInfoButton[0];
		var moreInfoButtonContent="";
		if (moreInfoButton==moreInfoButtonContent)
			{
			$("#more_info_button").css("background-image","url(Images/more_info_button_inactive.png)");
			$("#more_info_button a").css("color","#999");
			}
		}
	if($("#splash_links").exists())
		{
		innertxt=$('#splash_links').html();
		newstxt="<table align=CENTER><tr>";
		newstxt+="<td><img src='Images/news_burst.png' />";
		if($("#test_page").exists())  //do it with scrolling news reel.
			{
			alert('testing');
			}
		else
			{
			newstxt+="<td id='splash_links_news'><a href='http://www.workforceconnections.biz/?p=negojt_2011' style='width:auto;font-size:24px;'>National Emergency Grant to Assist Local Businesses</a></td>";
			//newstxt+="<td id='splash_links_news' style='color:#008ACC;'> | <td id='splash_links_news'><a href='http://caosciotocounty.org/head_start_news.html' style='width:auto;font-size:24px;'>Head Start Sign-ups</a></td>";
			//newstxt+="<td id='splash_links_news' style='color:#008ACC;'> | <td id='splash_links_news'><a href='http://caosciotocounty.org/summer_food_news.html' style='width:auto;font-size:24px;'>Summer Food Program</a></td>";
			}
		newstxt+="</tr></table>";
		$('#splash_links').html(newstxt + innertxt);
		}

});

//extends jQuery to have an exist function.
jQuery.fn.exists = function(){return jQuery(this).length>0;}

