var $images;
var $currentRow = 1, $oldRow = 0;
var $imageCount = 6;
var $pause;
var $weighting = 6;


$(function() {
	$("#slides").jCarouselLite({
		circular: false
    });
	$images = $("#slides li");
	$("#text_block").hide();
	$("#caption").hide();
	for (i=1; i< ($images.length+1); i++) {
		$("#image"+i).hide();
	}
});







$(document).ready(function(){
      $("#caption").customFadeIn("slow", function () {$("#image1").customFadeIn("slow", function () {$("#image2").customFadeIn("slow", function () {$("#text_block").customFadeIn("slow", function() {$pause = setTimeout(imageRotate, 3000); } );} );} );} );


var imageRotate = function() {

	$currentRow = ($oldRow + 1) % $imageCount;
	$("#image"+$currentRow).hide();
	$("#image"+($currentRow+1)).hide();
	$pause = setTimeout(imageRotate, 8000);
	$oldRow = ($currentRow+1) % $imageCount;

	if ($oldRow == 0) {
		$oldRow = $weighting-6;	
	}

	$("#image"+($oldRow+1)).customFadeIn("slow", function () {$("#image"+($oldRow+2)).customFadeIn("slow");} );
}



	$(".credits_label").click(function () {	
			
		clearTimeout($pause);

		$("#image"+($oldRow+1)).hide();
		$("#image"+($oldRow+2)).hide();

		$imageCount = 12;
		$weighting = 12;
		$oldRow = 6;	
			
		$("#image"+($oldRow+1)).customFadeIn("slow", function () {$("#image"+($oldRow+2)).customFadeIn("slow");} );							
										
		$pause = setTimeout(imageRotate, 8000);															
										
		$("#clients").hide();
		$("#downloads").hide();
		$(this).css({'color': '#000000', 'cursor': 'text'});
		$(".clients_label").css({'color': '#f37324', 'cursor': 'pointer'});
		$(".downloads_label").css({'color': '#f37324', 'cursor': 'pointer'});
      	$("#credits").customFadeIn("slow");
    });
	
	
	

	
	$(".clients_label").click(function () {

		clearTimeout($pause);

		$("#image"+($oldRow+1)).hide();
		$("#image"+($oldRow+2)).hide();

		$imageCount = 6;
		$weighting = 6;
		$oldRow = 0;	
			
		$("#image"+($oldRow+1)).customFadeIn("slow", function () {$("#image"+($oldRow+2)).customFadeIn("slow");} );							
										
		$pause = setTimeout(imageRotate, 8000);								
																		
      $("#credits").hide();
	  $("#downloads").hide();
	  	$(this).css({'color': '#000000', 'cursor': 'text'});
		$(".credits_label").css({'color': '#f37324', 'cursor': 'pointer'});
		$(".downloads_label").css({'color': '#f37324', 'cursor': 'pointer'});
	  $("#clients").customFadeIn("slow");
	  
    });
	
	
	$(".downloads_label").click(function () {
										  
		clearTimeout($pause);

		$("#image"+($oldRow+1)).hide();
		$("#image"+($oldRow+2)).hide();

		$imageCount = 18;
		$weighting = 18;	
		$oldRow = 12;	
			
		$("#image"+($oldRow+1)).customFadeIn("slow", function () {$("#image"+($oldRow+2)).customFadeIn("slow");} );							
										
		$pause = setTimeout(imageRotate, 8000);								
																	  
      $("#clients").hide();
	  $("#credits").hide();
	  	$(this).css({'color': '#000000', 'cursor': 'text'});
		$(".clients_label").css({'color': '#f37324', 'cursor': 'pointer'});
		$(".credits_label").css({'color': '#f37324', 'cursor': 'pointer'});
	  $("#downloads").customFadeIn("slow");
	  
    });
});