// ALERT USER
function alertuser(){
 alert('Sorry, this feature is temporarily unavailable. Please check back soon.')
}
// LAUNCH GALLERY VIEWER
function popGallery(imgid) {
window.open('gallery.asp?imgid=' + imgid + '','galleryviewer','width=585,height=556,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}
// CHANGE GALLERY
function jumpTo(URL_List) {
var URL = URL_List.options[URL_List.selectedIndex].value;
window.location.href = URL;
}
// OPEN SHOP WINDOW
//function openShop() {
//window.open('http://www.offshorechallenges.com/showshop.asp?page=list','showshop','width=700,height=400,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no')
//}

// SEND MAIL THANK YOU
function thankmail() {
 alert('Thank you for your email.')
}

// OPEN UPDATES WINDW
function updates() {
window.open('updates.asp','updates','width=580,height=215,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

// OPEN SHOWREEL
function openshowreel() {
window.open('choosemovie.asp','movie','width=620,height=325,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}


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 getTwitterInfo(user) {
	var twitUrl = "http://twitter.com/statuses/user_timeline/" +user+".json?callback=?&amp;count=1"
	var results="";
	
	$.getJSON(twitUrl, function(data){ 
		$("#twittering").html("");
		
		var status = data[0].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			return '<a href="'+url+'">'+url+'</a>';
		});
		var status2 = data[1].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			return '<a href="'+url+'">'+url+'</a>';
		});
		//var mydate = $.datepicker.formatDate('yy-mm-dd', data[0].created_at);
		
		results=results +"<p>" + status + "<a href=\"http://twitter.com/"+user+"/status/" + data[0].id + "\" title=\"\" class=\"tweet_time\">" + relative_time(data[0].created_at) + "</a></p>\n";
		results=results +"<p>" + status2 + "<a href=\"http://twitter.com/"+user+"/status/" + data[1].id + "\" title=\"\" class=\"tweet_time\">" + relative_time(data[1].created_at) + "</a></p>\n";	
		results=results +"<p class=\"bold\"> Follow me: <a href=\"http://twitter.com/SidneyGavignet\">@SidneyGavignet</a></p>";
		$("#twittering").html("" + results);
	});
}

jQuery(document).ready(function(){
	getTwitterInfo("SidneyGavignet");
});
