if (typeof GKAINDLCHYRP == 'undefined') {
	var GKAINDLCHYRP = new Object();
}

GKAINDLCHYRP.SafariSearchField = {
	defaultText	: "Search this site...",
	autosaveUrl	: "com.yoursite.yoursubdomain",
	numResults	: "10",
	focusClass	: "search_focused",
	
	makeSafariSearchFields : function () {		
		var isSafari = ((parseInt(navigator.productSub) >= 20020000) &&
								(navigator.vendor.indexOf('Apple') != -1));
		
		var inputs = document.getElementsByTagName("input");
		for (var i=0; i<inputs.length; i++) {
			if ((/(^|\s)search($|\s)/).test(inputs[i].className)) {
				var el = inputs[i];
				
				if (isSafari) {
					el.setAttribute('type', 'search');
					el.setAttribute('placeholder', GKAINDLCHYRP.SafariSearchField.defaultText);
					el.setAttribute('autosave', GKAINDLCHYRP.SafariSearchField.autosaveUrl);
					el.setAttribute('results', GKAINDLCHYRP.SafariSearchField.numResults);
				}
			
				el.onblur =	function () {
					if (!isSafari && (/^\s*$/).test(this.value)) {
						this.value = GKAINDLCHYRP.SafariSearchField.defaultText;
					}
					
					this.className =
						this.className.replace(new RegExp(GKAINDLCHYRP.SafariSearchField.focusClass),
							"search");
				};
				
				el.onfocus = function () {
					if (!isSafari && GKAINDLCHYRP.SafariSearchField.defaultText == this.value) {
						this.value = '';
					}
					
					this.className =
						this.className.replace(/search/, GKAINDLCHYRP.SafariSearchField.focusClass);
				};
				
				el.onblur();
				
			}
		}
	}
};

function summizeTweetLoad(json) {
	if (json.results && json.results.length > 0 && json.results[0].text) {
	   var ago = '';
	   if (json.results[0].created_at) {
	      var n = new Date();
	      var e = Math.floor((n.getTime() - Date.parse(json.results[0].created_at))/1000);
	      if (1 == e)
	         ago = "1 second ago";
	      else if (60 > e)
	         ago = e + " seconds ago";
	      else if (120 > e)
	         ago = "1 minute ago";
	      else if (60 > e/60)
	         ago = Math.floor(e/60) + " minutes ago";
	      else if (120 > Math.floor(e/60))
	         ago = "1 hour ago";
	      else if (24 > Math.floor(e/3600))
	         ago = Math.floor(e/3600) + " hours ago";
	      else if (2 > Math.floor(e/(3600*24)))
	         ago = "1 day ago";
	      else
	         ago = Math.floor(e/(3600*24)) + " days ago";
	   }
	   
		var t = json.results[0].text;
		t = t.replace(/(http:\/\/[^\s]*)/g, "<a href=\"$1\" title=\"$1\">$1</a>");
		t = t.replace(/(^|\s)\@([^\s]+)/, "$1<a href=\"http://twitter.com/$2\" title=\"$2 on twitter.com\">@$2</a>");
		$('ul#twitter_update_list > li').html(t);
		$('h3.latest_tweet').html($('h3.latest_tweet').html() + " <span class=\"ago\">(" + ago + ")</span>");
	}
}

$(function(){
	$(".notice, .warning, .message").
		append("<span class=\"sub\">(click to hide)</span>").
		click(function(){
			$(this).fadeOut("fast")
		})
		.css("cursor", "pointer")
});