/**
 * @author Justin Paul Silva
 */

$(function() {
	$("section").fadeTo('slow', 0.75);
	
	$("section").hover(
		function(){
			$(this).fadeTo('slow', 1);
		}, 
		function(){
			$(this).fadeTo('slow', 0.75);
		});
	
	$('#blog aside a').click(function() {
		$('#current_post').html($('#current_post').data($(this).attr('rel')));
		/*$.getJSON("http://simplymattd.tumblr.com/api/read/json?callback=?", {id:$(this).attr('rel')}, function(data) {
			//alert(dumpObj(data));
			output = "";
			switch (data.posts[0]['type']) {
				case 'regular':
					if (data.posts[0]['regular-title'] != "") output = '<h3>' + data.posts[0]['regular-title'] + '</h3>';
					output += data.posts[0]['regular-body'];
					break;
				case 'photo':
					output = '<img src=' + data.posts[0]['photo-url-500'] + ' alt=' + data.posts[0]['photo-caption'] + ' />';
					break;
				case 'quote':
					output = '<q>' + data.posts[0]['quote-text'] + '</q>';
					if (data.posts[0]['quote-source'] != "") output += "<cite>{data.posts[0]['quote-source']}</cite>";
					break;
			}
			$('#current_post').html(output);
		});*/
		return false;
	});
	
	$('a').click(function() {
		if ($(this).attr('href').substr(0,1) != '#' && !$(this).hasClass('tumblr') && !$(this).hasClass('ical') && !$(this).hasClass('press-kit')) {
			var target = $(this).attr('href');
			$('body').fadeOut(1000, function(){
				window.location = target;
			});
			return false;
		}
	});
	
	$(window).scroll(function () {
		if ($(window).scrollTop() == 0)
			$("a[href='#top']").fadeOut();
		else
			$("a[href='#top']").fadeIn();
    });
});

function load_post(data) {
	$('#current_post').html('<p>' + data[1][0]['@url'] + '</p>');
}

var MAX_DUMP_DEPTH = 10;
      
function dumpObj(obj, name, indent, depth) {
      if (depth > MAX_DUMP_DEPTH) {
             return indent + name + ": <Maximum Depth Reached>\n";
      }
      if (typeof obj == "object") {
             var child = null;
             var output = indent + name + "\n";
             indent += "\t";
             for (var item in obj)
             {
                   try {
                          child = obj[item];
                   } catch (e) {
                          child = "<Unable to Evaluate>";
                   }
                   if (typeof child == "object") {
                          output += dumpObj(child, item, indent, depth + 1);
                   } else {
                          output += indent + item + ": " + child + "\n";
                   }
             }
             return output;
      } else {
             return obj;
      }
}
