// NORMAL RULES



// LOGO CYCLE FUNCTION

function logo_cycle() {
	if ($('#client_list img:last').hasClass('active_logo')) {
		$('.active_logo').fadeToggle("slow", "linear", function() {
		$(this).removeClass('active_logo');
		$('#client_list img:first').addClass('active_logo');
		$('#client_list img:first').fadeIn("slow", "linear");
	   });
	}
	else {
	$('.active_logo').fadeToggle("slow", "linear", function() {
		$(this).removeClass('active_logo');
		$(this).next('#client_list img').addClass('active_logo');
		$(this).next('#client_list img').fadeIn("slow", "linear");
	   });
	}
};

$(document).ready(function() {



	// INTIAL FADE IN
	
	function sliderInitialContentFadeIn (delay) {
		$(".eye_candy_overlay").delay(delay).fadeIn(1500, function(){
			$("#showcase_container h2, #showcase_container ul, #showcase_container p, #showcase_navigation").delay(delay).fadeIn(500);
		});
	}	

	sliderInitialContentFadeIn(500);
	
	
	//LOGO CYCLE
	
	$('#client_list img:first').css('display', 'block').addClass('active_logo');
	setInterval(logo_cycle, 4000);
	
	
	// DROP DOWN
	
	drop_down = $("#navigation_container div");
	
	$('#navigation li a').mouseenter(
	function() {
		$('#navigation li a').css({backgroundPosition: '0px 0px'});
		$(this).css({backgroundPosition: '0px -77px'});	
		drop_down.stop(true, true).slideUp(200);
		dd_name = $(this).attr("id");
		dd_name = dd_name.replace("_link","_dd");
		dd_selector = "div#"+dd_name;
		$(dd_selector).stop().slideDown(400);
	}, function() {});	
	
	$("#navigation_container").mouseleave(
		function (){
			drop_down.stop(true, true).slideUp(200);
			$('#navigation li a').css({backgroundPosition: '0px 0px'});			
		}
	);
	

	if($("body").hasClass("home")){

	// HOME PAGE SLIDER STUFF
		
		function sliderContentFadeOut () {
			$(".eye_candy_overlay").fadeOut(50, function(){
				$("#showcase_container div").fadeOut(50, function(){
				});
			});
		}
		
		function sliderContentFadeIn (delay, init_speaed, sec_speed, selector ) {
			$(".eye_candy_overlay").delay(delay).stop(false,true).fadeIn(init_speaed, function(){
				$(selector).delay(delay).stop(false,true).fadeIn(sec_speed);
			});
		}
		
		
		function showCaseNavClick(count) {
			if (count > 4){
				top_val = $("#showcase_navigation").css("top");
				top_val = top_val.replace("px", "");
				top_val = parseInt(top_val) + 453;
				$("#showcase_navigation").css("top",top_val);
				count = count - 3;
			}
			showcase_navigation_position = (((count -1) * -1) * 151) - 61;
			$("#showcase_navigation").addClass('annimating').animate({"top": showcase_navigation_position }, 400, function(){
				$(this).removeClass('annimating');																													   
			});
		}
		
		function showCaseEyeCandyClick(count) {
			if (count > 4){
				top_val = $("#eye_candy").css("top");
				top_val = top_val.replace("px", "");
				top_val = parseInt(top_val) + 1233;
				$("#eye_candy").css("top",top_val);
				count = count - 3;
			}
			eye_candy_position = (((count -1) * -1) * 411);
			$("#eye_candy").addClass('annimating').animate({"top": eye_candy_position}, 400, function(){
				$(this).removeClass('annimating');																													   
			});
		}
		
		showcase_navigation_orig_height = $("#showcase_navigation").height();
		eye_candy_height = $("#eye_candy").height();
		showcase_nav_count = 0;
		
		$("#showcase_navigation").height(showcase_navigation_orig_height * 2);
		$("#showcase_navigation li:lt(3)").clone().appendTo("#showcase_navigation");
	
		$("#eye_candy").height(showcase_navigation_orig_height * 2);
		$("#eye_candy div.eye_candy_repeat:lt(3)").clone().appendTo("#eye_candy");
		
		$("#showcase_navigation li").each(function(){
			showcase_nav_count++;
			$(this).find("a").data("count",showcase_nav_count);
		});
	
		$("#showcase_navigation li a").click(
			function(){
				if(!$("#showcase_navigation").hasClass('annimating')){
					sliderContentFadeOut();
					$("#showcase_navigation li a").removeClass("active trigger_class");
					this_class = $(this).attr("class");
					this_panel_selector = "#"+(this_class.replace("_tab","_showcase"));
					$("."+this_class).addClass("active");
					$("#showcase_navigation li a.active").parent("li").next("li").find("a").addClass("trigger_class");
					count = $(this).data("count")
					showCaseNavClick(count);
					showCaseEyeCandyClick(count);
					sliderContentFadeIn(100, 800, 300, this_panel_selector);
				}
			}
		);
		
		
		$("div#showcase_container").hover(function(){
			clearInterval(rotating);
		},function(){
			rotating = setInterval(function() {
				show_case_slider();
			},8000)
		});
		
		
		function show_case_slider (){
			$(".trigger_class").each(function(){
				if($(this).offset().top < 240){
					$(this).removeClass("trigger_class");
				}
			});
			$(".trigger_class").trigger("click");
		}
			
		rotating = setInterval(function() {
			show_case_slider();
		},8000)

		
		
	// HOME PAGE END
	
	}


	


	// GENERAL FORM RULES							 	
	if ($("form").hasClass("body_form")){
		var count = 10;
		countdown = setInterval(function(){
		$("#timer").html("Please wait " + count + " seconds before you submit!");
		if (count == 0) {
			$('#timer').remove();
			$("#submit_container").html('<a href="#" class="submit_button "><span>Submit</span></a>');
			$(".submit_button").fadeIn('slow');
		}
		count--;
		}, 1000);
		$("a.submit_button").live('click', function() {
			$(this).parents("form").submit();
			return false;
		});
	}
});
