function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function closePhoto(){
	var o = MM_findObj('LargeImageDIV');
	o.style.visibility = 'hidden';
}

function openPhoto(s, w, h){
	var o = MM_findObj('LargeImageDIV');
	o.innerHTML = '<img src=\"' + s + '\" alt="Full size image" />';
	o.style.width = w + 'px';
	o.style.height = h + 'px';
	
	if( typeof( window.innerWidth ) == 'number' ) {
		intTop = window.pageYOffset;
		intLeft = window.innerWidth;
	} else {
		if(document.body.scrollTop) {
			//IE4
			intTop = document.body.scrollTop;
			intLeft = document.body.clientWidth;
		} else {
			//IE6
			intTop = document.documentElement.scrollTop;
			intLeft = document.documentElement.clientWidth;
			//intLeft = self.screen.availWidth;
		}
	}

	intTop = intTop+45;
	intLeft = ((intLeft-w)*.5);

	o.style.top = intTop+'px';
	o.style.left = intLeft+'px';
	o.style.visibility = 'visible';
}


/* 
	twitterCallback2 and relative_time were pulled from http://twitter.com/javascripts/blogger.js
	
	Added the in_reply_to_status_id/in_reply_to_screen_name link 5/12/09
	
	Added the code to linkify #tags 9/17/09 
*/

function twitterCallback2(C) {
	/*
		For the page to validate as XHMTL 1.0 Strict, there must be a <li> within every <ul>
		so twitter_update_list is rendered with <li>&nbsp;</li> as it's sole child element,
		which should be removed before adding the <li>s for each tweet
	*/
	$("#twitter_update_list_li_remove_me").remove();
	
	var A=[];
	for(var D=0;D<C.length;D++) {
		var E=C[D].user.screen_name;
		var G=C[D].in_reply_to_status_id;
		var H=C[D].in_reply_to_screen_name;
		var profile_image=C[D].user.profile_image_url;
		var I='';
		if(G!=null) {
			I=' <a style="font-size:85%" href="http://www.twitter.com/'+H+'/statuses/'+G+'">in reply to '+H+'</a>';
		}
		var B=C[D].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'">'+F+"</a>"}).replace(/#([^\s]+)/g,function(F){return'<a href="http://twitter.com/#search?q='+escape(F)+'">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return F.charAt(0)+'<a href="http://www.twitter.com/'+F.substring(1)+'">'+F.substring(1)+"</a>"});
		A.push('<li><span class="gtweetnews_tweet">'+B+'</span> <a style="font-size:85%" href="http://twitter.com/'+E+"/statuses/"+C[D].id+'">'+relative_time(C[D].created_at)+'</a>'+I+'</li>')
	}
	document.getElementById("twitter_update_list").innerHTML=A.join("")
	//$("#twitter_profile_image").attr("src", profile_image);
	
	if(window.console && window.console.firebug){
		console.log(profile_image); //the api seems to lag behind updates to the profile image. it still points to the old image even after the old image is unavailable
	}
}
		
function format_date(C) {
	var B=C.split(" ");
	return C=B[1]+" "+B[2]+", "+B[5]; //+" "+B[3];		
}

function relative_time(C) {
	var B=C.split(" ");
	C=B[1]+" "+B[2]+", "+B[5]+" "+B[3];
	var A=Date.parse(C);
	var D=(arguments.length>1)?arguments[1]:new Date();
	var E=parseInt((D.getTime()-A)/1000);
	E=E+(D.getTimezoneOffset()*60);
	if(E<60){
		return"less than a minute ago"
	} else {
		if(E<120){
			return"about a minute ago"
		} else {
			if(E<(60*60)){
				return(parseInt(E/60)).toString()+" minutes ago"
			} else {
				if(E<(120*60)){
					return"about an hour ago"
				} else {
					if(E<(24*60*60)){
						return"about "+(parseInt(E/3600)).toString()+" hours ago"
					} else {
						if(E<(48*60*60)){
							return"1 day ago"
						} else {
							return(parseInt(E/86400)).toString()+" days ago"
						}
					}
				}
			}
		}
	}	
}