var expandedHeight = "295px"
var collapsedHeight = "42px"
var timing = 500;
var currentSlide = 1;
var t;
var nextframe = 0;
var nextframedelay = 5000;

$(document).ready(function () {
			
			$("#tab1").click(function(){
  			
			if (!( $("#tab1").is('.expstate') )) {
			
			collapseAllPanelsExceptFor(1);
			
			$("#tab1").animate({ 
   			 height: expandedHeight
			  }, timing );
			$("#tab1").addClass("expstate");
			
			} else {
				$("#tab1").animate({ 
   			 height: collapsedHeight
			  }, timing );
				$("#tab1").removeClass("expstate");
				collapseAllPanels();
			}
			
			});
			
			$("#tab2").click(function(){
  			
			collapseAllPanelsExceptFor(2);
			
			if (!( $("#tab2").is('.expstate') )) {
			
			$("#tab2").animate({ 
   			 height: expandedHeight
			  }, timing );
			$("#tab2").addClass("expstate");
			
			} else {
				$("#tab2").animate({ 
   			 height: collapsedHeight
			  }, timing );
				$("#tab2").removeClass("expstate");
				collapseAllPanels();
			}
			
			});
			$("#tab3").click(function(){
									  
			collapseAllPanelsExceptFor(3);
  			
			if (!( $("#tab3").is('.expstate') )) {
			
			$("#tab3").animate({ 
   			 height: expandedHeight
			  }, timing );
			$("#tab3").addClass("expstate");
			
			} else {
				$("#tab3").animate({ 
   			 height: collapsedHeight
			  }, timing );
				$("#tab3").removeClass("expstate");
				collapseAllPanels();
			}
			
			});
			$("#tab4").click(function(){
  			
			
			
			if (!( $("#tab4").is('.expstate') )) {
			
			collapseAllPanelsExceptFor(4);
			
			$("#tab4").animate({ 
   			 height: expandedHeight
			  }, timing );
			$("#tab4").addClass("expstate");
			
			} else {
				$("#tab4").animate({ 
   			 height: collapsedHeight
			  }, timing );
				$("#tab4").removeClass("expstate");
				collapseAllPanels();
			}
			
			});
		
			//begin animation on home page javascript
			$("#showFrame1").click(function() {
				clearTimeout(t);
				nextframedelay = 7000;
				showFrameAnimation(1);	

			});

			$("#showFrame2").click(function() {
				clearTimeout(t);
				nextframedelay = 7000;
				showFrameAnimation(2);	
			});

			$("#showFrame3").click(function() {
				clearTimeout(t);
				nextframedelay = 7000;
				showFrameAnimation(3);	
			});

			showFrameAnimation(1);
        
});

function collapseAllPanels() {
	for (x=1;x<=4;x=x+1)
	{
		$("#tab" + x).animate({ 
   			 height: collapsedHeight
			  }, timing );
		$("#tab" + x).removeClass("expstate");
		
	}
}

function collapseAllPanelsExceptFor(exceptfor) {
	for (x=1;x<=4;x=x+1)
	{
		if (x!=exceptfor)  {
		
		$("#tab" + x).animate({ 
   			 height: collapsedHeight
			  }, timing );
		$("#tab" + x).removeClass("expstate");
		
		}
		
	}
}

function showFrameAnimation(startframe)
{
	//fadeOut the other items
	for (x=1;x<=3;x=x+1)
	{
		$("#showFrame" + x).removeClass("Hanimbtn");
		$("#slide" + x).fadeOut("slow");
	}

	$("#showFrame" + startframe).addClass("Hanimbtn");

	
	//fade in the next frame, with a delay
	nextframe = startframe + 1;
	if (nextframe == 4) {
             nextframe = 1;
	}

	$("#slide" + startframe).fadeIn("slow");

	t = setTimeout( "showFrameAnimation(nextframe)", nextframedelay);
}

function cycleFrames() {
	showFrame(currentFrame);
}

