var contentLoaded = true;
$(document).ready( function() {
	cycleAjaxLinks();
	processArticleMeta();
	luminescence();
	$("#introduction").fadeTo(10000, 1, function(){
		$("#introduction").fadeTo(5000, .25);
	});
});

var loadContent = function(htmlContent) {
	$('html, body').animate({scrollTop:0}, 2000); 
	$("object, embed").each(function(){
		$(this).css("visibility", "hidden");
	});
	$("#article-content").fadeOut(1000, function() {
		$("#article-content").html(htmlContent);
		$("object, embed").each(function(){
			$(this).css("visibility", "hidden");
		});
		cycleAjaxLinks(); 
		processArticleMeta();
		luminescence();
		$("#article-content").fadeIn(1000, function() { 
			contentLoaded = true; 
			resize();
			$("object, embed").each(function(){
				$(this).css("visibility", "visible");
			});
		});
	});
}

var cycleAjaxLinks = function() {
	$("a.ajax").click(function() {
		if (contentLoaded) {
			contentLoaded = false;
			$.get(this.href+'.ajax', {}, function(data) {
				loadContent(data);
			});
		}
		return false;
	});
}

var processArticleMeta = function() {
	$("#reality-title").hover(
		function() {
			$("#reality-metadata").fadeIn(1000);
		},
		function() {
			$("#reality-metadata").fadeOut(1000);
		}		
	);
}

var luminescence = function() {
	$(".vendor").fadeTo(0, .25);
	$(".vendor").hover(
		function() {
			$(this).fadeTo(1000, 1);
		},
		function() {
			$(this).fadeTo(1000, .25);
		}						
	);
}