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/phparch.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();
		});
	});
}

function resizeBody() {
	var winWidth = $(window).width();

	var leftMargin = Math.floor((winWidth - 1000) / 2) + 180 + "px";
	
	$("#header").css('margin-left', leftMargin);
	$("#body").css('margin-left',   leftMargin)
	$("#body").css('margin-right', "0px")
}

$(document).ready(function() {
    $('.needsShadow').load(function() {
        $(this).shadow({
    		offset:  4,
    		opacity: 0.2,
    		color:   "#000",
    		monitor: false
        });
    });
    
    $('.headerTab').hover (function() {
        this.src = this.src.replace(/.png/, '_over.png');                            
    }, function() {
        this.src = this.src.replace(/_over.png/, '.png');
    });

    $('#sidePanel li').hover (function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

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

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

$(window).resize(resizeBody);
