function twitterCallback2(twitters) {
    var statusHTML = [];
    for (var i = 0; i < twitters.length; i++) {
        var username = twitters[i].user.screen_name;
        var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function (url) {
            return '<a style="text-decoration: none;color: #321d27;" target="_blank" href="' + url + '">' + url + '</a>';
        }).replace(/\B@([_a-z0-9]+)/ig, function (reply) {
            return reply.charAt(0) + '<a style="text-decoration: none;color: #321d27;" href="http://twitter.com/' + reply.substring(1) + '">' + reply.substring(1) + '</a>';
        });
        statusHTML.push('<li><span>' + status + '</span> <span style="text-decoration: none;display: block;font-weight: bold;margin-top: 10px;">' + relative_time(twitters[i].created_at) + '</span></li>');
    }
    document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value) {
    var values = time_value.split(" ");
    time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
    var parsed_date = Date.parse(time_value);
    var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
    var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
    delta = delta + (relative_to.getTimezoneOffset() * 60);
    if (delta < 60) {
        return 'less than a minute ago';
    } else if (delta < 120) {
        return 'about a minute ago';
    } else if (delta < (60 * 60)) {
        return (parseInt(delta / 60)).toString() + ' minutes ago';
    } else if (delta < (120 * 60)) {
        return 'about an hour ago';
    } else if (delta < (24 * 60 * 60)) {
        return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
    } else if (delta < (48 * 60 * 60)) {
        return '1 day ago';
    } else {
        return (parseInt(delta / 86400)).toString() + ' days ago';
    }
}(function ($, window) {
    window.showLightbox = function (url, startIndex) {
        var startIndex = startIndex == null ? 1 : startIndex;
        var temp = new Array();
        $.each(url.split(","), function () {
            var player = "img";
            var content = $.trim(this);
            if (content.indexOf(".swf") != -1) {
                player = "swf";
            }
            temp.push({
                content: content,
                player: player,
                options: {
                    continuous: true
                }
            });
        });
        Shadowbox.open(temp, startIndex);
    }
    $(function () {
        $("#index").each(function () {
            $("#side-bar").append('<div class="article" id="follow-us" style="display: none;margin-top: 80px;background-color: #CCCCCC;padding-left: 11px;width: 107px;padding-right: 13px;padding-top: 13px;padding-bottom: 11px;"><div class="header"><h2><a href="http://twitter.com/PhilCoffey/" target="_blank" style="background: url(images/text/follow-us.png) no-repeat;width: 72px;height: 14px;text-indent: -1000px;display: block;">follow us:</a></h2></div><div class="body" style="margin-top: 13px;overflow: hidden;"><ul id="twitter_update_list"><li></li></ul></div></div>');
            $.getScript("http://twitter.com/statuses/user_timeline/PhilCoffey.json?callback=twitterCallback2&count=1", function () {
                $("#follow-us").fadeIn(500).find("a");
            });
        });
        $("#project-menu a").each(function () {
            $a = $(this);
            $li = $a.parent();
            var cls = $li.attr("className");
            if (cls.indexOf(" ") != -1) {
                cls = cls.split(" ")[1];
            }
            $a.css({
                backgroundImage: "url(images/text/" + cls + "-btn.png)"
            });
            var id = $("body").attr("id");
            if (id == cls) {
                $a.css({
                    backgroundPosition: "0px -21px"
                });
            }
        });
        $("#inspiration").each(function () {
            var $textWrapper = $("#image-text");
            var $viewport = $("#viewport", this);
            $("#thumbs .selected img").animate({
                opacity: 0.5
            }, 100);
            $("#thumbs a", this).bind("click", function (e) {
                e.preventDefault();
                var $this = $(this);
                var $sel = $("#thumbs .selected");
                $sel.removeClass("selected")
                $("img", $sel).animate({
                    opacity: 1
                }, {
                    duration: 100
                });
                $sel = $this.closest(".article").addClass("selected");
                $("h3", $textWrapper).text($("h3", $sel).text());
                $(".body", $textWrapper).html($(".body", $sel).html());
                var href = $this.attr("href").substr(1);
                $(".selected", $viewport).css({
                    display: "none"
                }).removeClass("selected");
                var $li = $("#" + href, $viewport).css({
                    display: "block"
                }).addClass("selected");
                $("img", $li).css({
                    opacity: 0
                }).animate({
                    opacity: 1
                }, {
                    duration: 500
                });
            }).bind("mouseenter", function () {
                var $img = $("img", this);
                $img.animate({
                    opacity: 0.5
                }, {
                    duration: 100
                });
            }).bind("mouseleave", function () {
                var $img = $("img", this);
                if (!$img.closest(".article").hasClass("selected")) {
                    $img.stop().css({
                        opacity: 1
                    });
                }
            });
        });
        $("#banner").each(
			function()
			{
            	var $this = $(this);
				if(swfobject.hasFlashPlayerVersion("8.0.0")) {
					
					$(window).bind("resize",
						function ()
						{
		                	$this = $("#banner");
			                $this.css({
			                    width: "100%",
			                    overflow: "hidden"
			                });
			                var w = Math.max(995, $(window).width());
			                var h = Math.round(w * 0.2733) + 30 + 26;
			                $this.width(w);
			                $this.height(h);
			                $("#content, #side-bar").css({
			                    marginTop: h
			                });
		            	}
					).trigger("resize");
				} else {
					$this.css(
						{
							width: "965px",
							position: "static",
							height: "330px"
						}
					);
					$("#content, #side-bar").css(
						{
							marginTop: 0
						}
					);
				}
	            
        });
    });
})(jQuery.noConflict(), this);
