(function($, undefined) {
	$(document).ready(function() {
    setTimeout(function() {  
	    $(".red-flash").each(function() {
	      var _this = $(this);
	      var colors = ["#AA2A20","#000000"];
	      var time = 150;
	      var flash = 2;
	      var i = 0;
	      var f = function() {
	        if (++i > flash) {
	          _this.hover(function() {
        	    $(this).animate({
        	      backgroundColor: colors[0]
        	    }, time);
        	  }, function() {
        	    $(this).animate({
        	      backgroundColor: colors[1]
        	    }, time);
        	  });
        	  $(".navigation div").hover(function() {
        	    $(this).animate({
        	      backgroundColor: colors[0]
        	    }, time);
        	  }, function() {
        	    $(this).animate({
        	      backgroundColor: colors[1]
        	    }, time);
        	  });
        	  return;
	        }
	        
	        _this.animate({
	          backgroundColor: colors[0]
	        }, time, function() {
	          _this.animate({
	            backgroundColor: colors[1]
	          }, time, f);
	        });
	      };
	      f();
	    });
	  }, 2000);
	  
	  
	  // feature slider
	  $(".slider").huffslider();
		$(".next-arrow").click(function(e) {
			e.preventDefault();
			$(this).closest(".slider").huffslider('next');
		});
		$(".prev-arrow").click(function(e) {
			e.preventDefault();
			$(this).closest(".slider").huffslider('prev');
		});
		if ($(".feature-slider li").size() < 2) {
			$(".feature-slider .next").add('.feature-slider .prev').remove();
		}
		
		
		// do thank you page transition
		$("#content.thank-you-page").each(function() {
			function get_current_header() {
				return div.find("li h3").eq(slider.huffslider('get_current')).html()
			}
			function swap_header_with_current() {
				h1.animate({top:h1_negative_height_px}, header_change_speed, "easeInExpo", function() {
					h1.html(get_current_header()).animate({top:"0px"}, header_change_speed, "easeOutExpo")
				});
			}
			
			var header_change_speed = 375;
			var div = $(this);
			var h1 = div.find("h1");
			var h1_negative_height_px = "-"+h1.height()+"px";
			var slider = div.find(".slider");
			h1.css({
				top : h1_negative_height_px
			});
			h1.html(get_current_header()).animate({top:"0px"}, header_change_speed, "easeOutExpo");
			
			slider.find("a[class*='-arrow']").click(function() {
				swap_header_with_current();
			});
		});
	});
})(jQuery);
