function faderInner(selector){
	var animImages = 250;
	var elems = $(selector), count = elems.length;
	$(selector).each(function(index){
		$(this).delay(animImages*index).fadeIn(animImages,function(){
			if(--count == 0) {
				
			}
		});
	});	
	
}

	var arrTypes = ["#sk_list ol li",".fade-in img", ".fade-in p", ".fade-in div, .case-studies .case"];
	
	var durShort = 150;
	var durMed = 250;
	var durLong = 500;
	var durXLong = 750; 
	var endReached = false;
	
	var ieDefaultFadeClasses = arrTypes;
	var ieDefaultFadeIds = arrTypes; 

	function setVisibleElements() {
		// populate array with unique values corresponding to each element box
		var d = new Date();
		$.each(arrTypes, function(i, val) {
			$(val).each(function() {
				if ( !$(this).attr("data-unique-id") ) {
					$(this).attr("data-unique-id", parseInt(d.getTime()) + Math.floor(Math.random() * 100000));
				};
				evalVis($(this));
			});
		});
	} 
	
	function evalVis(el) {
		var elTop = $(el).offset().top - $(window).scrollTop();
		var elHeight = $(el).height();
		// if between top of footer and top of window
		if (elTop + elHeight > 40 && elTop < $(window).height()) {
			if ($.inArray($(el).attr("data-unique-id"), elementsInView) < 0) {
				addToView(el);
			}
		} else {
			if ($.inArray($(el).attr("data-unique-id"), elementsInView) >= 0) {
				removeFromView(el);
			}
		}
	};
	
	function addToView(el) {
		elementsInView.push($(el).attr("data-unique-id"));
		revealElements(el);
	};
	function removeFromView(el) {
		hideElements(el);
		elementsInView = $.grep(elementsInView, function(val) { return val != $(el).attr("data-unique-id"); });
	};
	
	var prevElTime, newElTime;
	
	function revealElements(el) {
		if ( $(el).attr("id") && ($(el)[0].id.indexOf("swf") > -1) ) {
			return;
		}
		// IE 7, 8 -- do not delete
		/*@cc_on
		@if(@_jscript_version < 5.9)
			var useDefaultFade = false;
			$("img", el).stop().delay(200).animate({opacity: 1.0}, durLong);
			$(".info-panel-wrap", el).stop().delay(200).animate({opacity: 1.0}, durLong);
			if (el[0].className == "reel") {
				$("embed", el).css("opacity", "1.0");
			}
			if ($.inArray(el[0].id, ieDefaultFadeIds) > -1 || $.inArray(el[0].className, ieDefaultFadeClasses > -1)) {
				useDefaultFade = true;
			}
			if (el[0].className == "case-study-images" || el[0].className == "locations") {
				$("a", el).stop().delay(200).animate({opacity: 1.0}, durLong, function() { removeIEFilter(this); });
				useDefaultFade = true;
			}
			if (el[0].id == "about-contact") {
				$("#about-contact h3").delay(200).animate({opacity: 1.0}, durLong, function() { removeIEFilter(this); });
			};
			if (!useDefaultFade) {
				return;
			}
		@end
		@*/
		$(el).stop().delay(200).animate({opacity: 1.0}, durLong, function() { removeIEFilter(this); });
	};
	function hideElements(el) {
		if ( $(el).attr("id") && ($(el)[0].id.indexOf("swf") > -1) ) {
			return;
		}
		// IE 7, 8 -- do not delete
		/*@cc_on
		@if(@_jscript_version < 5.9)
			$("img", el).css("opacity", "0.0");
			$(".info-panel-wrap", el).css("opacity", "0.0");
			if ($.inArray(el[0].id, ieDefaultFadeIds) > -1 || $.inArray(el[0].className, ieDefaultFadeClasses > -1)) {
				$(el).css("opacity", "0.0");
			}
			if (el[0].className == "case-study-images" || el[0].className == "locations") {
				$(el).css("opacity", "0.0");
				$("a", el).css("opacity", "0.0");
			}
			return;
		@end
		@*/
		$(el).css("opacity", "0.0");
	};
	
	function removeIEFilter(el) {
		el.style.filter = null;
	}
	
	function fadeWork() {
		// IE 7, 8 -- do not delete
		/*@cc_on
		@if(@_jscript_version < 5.9)
			$(".large .info-panel-wrap").animate({opacity: 0.0}, durLong);
			$(".large img").animate({opacity: 0.0}, durLong, function() {
				$(this).parent().parent().remove();
				if($(".large").length == 0) {
					//trace("Danny")
					// not sure anything needs to be done here
				}
			});
			return;
			@end
		@*/
		$(".large").animate({opacity: 0.0}, durLong, function() {
			$(this).remove()
			if($(".large").length == 0) {

			}
		});
	};
	
function showTheEnd() {
	var theEnd = $("#the-end-of-the-interwebs");

	var i = Math.floor(Math.random() * 3);
	var offsetY = i * -120;
	$(theEnd).css("background-position", "0 " + offsetY + "px");
	bottomY = $(window).scrollTop() + $(window).height() - 135;
	$(theEnd).css("top", bottomY);
	$('#the-end-of-the-interwebs').fadeIn(durMed);
	endReached = true;

} 

function hideTheEnd() {
	endReached = false;

	$('#the-end-of-the-interwebs').fadeOut(durMed);
}

function checkLoad() {
	// don't endless-load about or contact sections
	if ($("#about").length || $("#contact").length) {
		return;
	}
	if ( !loadRequested && $("#content").height() - $(window).scrollTop() - $(window).height() <= 0) {
		loadRequested = true;
		//trace('Danny, load new content, filter_by: ' + filter_by)
		loadRequested = true;
		var pointer = $("#pointer").attr("value");
		var blogPointer = $("#blogPointer").attr("value");
		
		if($(".grid").last().attr("class")){
			var nextGrid = $(".grid").last().attr("class").split(" ")[1];
		}
		trace("Next Grid: " + nextGrid);
		var params = 'nextGrid=' + nextGrid+"&pointer="+pointer+"&blogPointer="+blogPointer;

	}
} 

// update subnav when scrolling
function scrollUpdateSubnav() {
	if (arrSubNav.length) {
		$.each(arrSubNav, function(i, id) {
			var elTop = $(id).offset().top - $(window).scrollTop();
			var elHeight = $(id).height();
			//trace($("#philosophy").offset().top - $(window).scrollTop())
			if (elTop < $(window).height() / 2 && elTop > -300) {
				//trace(elTop + " id: " + id + " window.height: " + $(window).height() / 2)
				//if (elTop < $(window).height() / 2 && elTop > 0) {
				$("#subnav a").each(function() {
					if ($(this).attr("href") != id) {
						$(this).removeClass("selected");
					} else {
						$(this).addClass("selected");
					}
				});
			}
		});
	}
}; 
	
var elementsInView = [];
	
function loadScrollFade(){
	setVisibleElements();
	$(window).scroll(function() {
		setVisibleElements();
		//checkLoad();
		if ($("#about").length || $("#contact").length && $("#contact.careers").length == 0) {
			scrollUpdateSubnav();
		};
		if ($(window).scrollTop() + $(window).height() == $(document).height()) {
			showTheEnd();
		}
		else if (endReached) {
			hideTheEnd();
		};
	}); 
	
}

