var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function readTwitter() {
	$.getJSON("http://twitter.com/statuses/user_timeline/mtabini.json?callback=?&count=5", function(data) {
		$("#twitterFeed").html("");
		
		$.each(data, function(i, item) {
			var now = new Date();
			var dateDiff = (now - Date.parse(item.created_at)) / 1000;
			var time = "";
			
			if (dateDiff < 10) {
				time = "Just now";
			} else if (dateDiff <= 60) {
				time = "Less than a minute ago";
			} else if (dateDiff < 3600) {
				time = (dateDiff / 60).toFixed() + " minutes ago";
			} else if (dateDiff < 86400) {
				time = (dateDiff / 3600).toFixed();
				
				if (time > 1) {
					time += " hours ago";
				} else {
					time += " hour ago";
				}
			} else {
				time = (dateDiff / 86400).toFixed();
				
				if (time > 1) {
					time += " days ago";
				} else {
					time += " day ago";
				}
			}
			
			var str = "<li>" + 
				item.text + 
				" — <span class='twitterTime'>" +
				time +
				"</span></li>";
			
			$("#twitterFeed").append(str);
		});
		
		$("#twitterFeed > li:last").addClass("last");
		$("#twitterWait").fadeOut(function() {
			$("#twitterFeed").fadeIn();
		});
	});
}

$(document).ready(function() {
    $('.needsShadow').load(function() {
        $(this).shadow({
    		offset:  4,
    		opacity: 0.2,
    		color:   "#000",
    		monitor: false
        });
    });
    
    $('#sidePanel li').hover (function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

	$("#sidePanel li").click (function() {
		document.location.href = $("a", this)[0].href;
	});

	$("#container").width($("#container").width() + $("#sponsorBar").width());

	var body = $("#body");
	var position = body.position();
	$("#sponsorBar").css("left", position.left + body.width() + 50 + "px");
	$("#sponsorBar").css("top", "5px");
	
	
	if ($(window).width() < 1025) {
		$(".container").css('margin-left', 0);
	}

	$("tr:even").addClass("alt");
	
	readTwitter();
});
