// JavaScript Document
 //<![CDATA[
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//													Function to display news articles												//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() { 		
	
	//Checks if a get varible exsists
	// if false laods first article
	if ($.getURLParam("ID")!=null) {
	 
		id = $.getURLParam("ID");
		//id = str_replace("#", "", id);
		$(".containerimage").load("loadimages.php?id="+id);
	  	$("#greenarrow"+id).fadeIn();
		$("#moreinfo"+id + " a").html("Close <img src='images/closearrow.jpg' alt='close' style='padding-left:5px; padding-top:3px;' />");	
	}	
	$(".worktext a").click(function () 
	{			
		$(".greenarrow").each(function()
		{
			$(".greenarrow").css("display", "none");
		});
		
		$("#worktexthidden").each(function()
		{
			$("#worktexthidden").slideIp();
		});
		$(".workmaincontainer").each(function()
		{
			$(".workmaincontainer").hide();
		});
		
		$(".scrolltext").css("top", "0px");
		$("#movenewup").fadeIn();
		$("#movenewdown").fadeIn();
		
		currentID = $(this).attr("id");	
		$(".containerimage").load("loadimages.php?id="+currentID);	
		$("#workmaincontainer"+currentID).show();
		display = $("#worktexthidden"+currentID).css("display");
		
		if (display != "none")
		{
			$("#worktexthidden"+currentID).slideUp('', function () {
			  $("#moreinfo"+currentID+ " a").html("More Information<img src='images/arrowdown.jpg' alt='close' style='padding-left:5px; padding-top:3px;' />");
			});
			
			$("#worktexthidden"+currentID).css("padding-bottom", "10px");
			$("#worktexthidden"+currentID).css("padding-top", "10px");
			$(".workmaincontainer").each(function()
			{
				$(".workmaincontainer").show();
			});
			$("#move_up").show();
			$("#move_down").show();
		}
		else
		{			
			$("#worktexthidden"+currentID).slideDown();
			$("#worktexthidden"+currentID).css("padding-bottom", "20px");
			$("#worktexthidden"+currentID).css("padding-top", "20px");
			$("#moreinfo"+currentID+ " a").html("Close <img src='images/closearrow.jpg' alt='close' style='padding-left:5px; padding-top:3px;' />");			
		}
		$("#greenarrow"+currentID).fadeIn();
		$("#movenewup").fadeIn();
		$("#movenewdown").fadeIn();
		
		$(".newslisttitle a").livequery('click', function(event)
		{
		if ($('#newscrool').innerHeight() < $(".newscontainer").height()) 
			{
				
				$("#movenewdown").fadeTo(0 , 1);
				dontmove = true;
			}
			else
			{
				$("#movenewdown").fadeTo(1 , 1);
				dontmove = false;
			}		
		});	
		
	});
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//													Scrol Bars											//
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var moving = false;
	var dontmove = false;
	//$("#move_up").css("display", "none");
	$("#move_up").fadeTo(0 , 1);
		
	
	
	$("#move_down").mousehold(function(){							   
		if (dontmove == false) {
			var top = $("#scrolltext").css("top");		
			//var display = $("#move_up").css("display");
			var display = $("#move_up").fadeTo(0 , 1);
			var height = $('#scrolltext').innerHeight();	
			var containerHeight = $("#hometextcontainer").css("height");			
			top = top.replace("px","")
			containerHeight = containerHeight.replace("px","")
				
			top = parseInt(top)
			containerHeight = parseInt(containerHeight)
			
			var maxTop = height - containerHeight;
				
			maxTop = maxTop - (maxTop*2);
				
			var nextTop = top - 80;
		
			if (nextTop < maxTop) {			
				nextTop = maxTop;
			}
			
			if (display == "none") {		
				//$("#move_up").css("display","inline");
				$("#move_up").fadeTo(0 , 1);
			}
	
			
			if (moving == false) {	
				moving = true;
				$("#scrolltext").animate({"top": nextTop}, 300, "linear", function(){
					 moving = false;
					 if (nextTop == maxTop) {
						$("#move_down").css("display","none");
					 }
				});
			}
		}
	});	
	
	$("#move_up").mousehold(function(){
		if (dontmove == false) {							 
			var top = $("#scrolltext").css("top");	
			var display = $("#move_down").css("display");	
			top = top.replace("px","")	
			top = parseInt(top)
				
			maxTop = 0;
			
			var nextTop = top + 80;
			
			if (nextTop > maxTop) {		
				nextTop = maxTop;	
			}
			
			if (display == "none") {		
				$("#move_down").css("display","inline");
			}
	
			
			if ((top < 0) && (moving == false)) {
				moving = true;
				$("#scrolltext").animate({"top": nextTop}, 300, "linear", function(){
					 moving = false;	
					if (nextTop == maxTop) {
						//$("#move_up").css("display","none");
						$("#move_up").fadeTo(0 , 1);
					}
				});
			}
		}
	});	
});	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//]]>