// AUTHOR: ALEX STOMP
// FILE: EXTERNAL.JS
// FOR Trinity Site

// GALLERY VIEW HOVER SLIDING EFFECT -- GALLERY

$(function(){

	$('#top-nav li a.wr').hover(function(){
		$('.drop-down').hide();
		$('#more-wr').show().hover(function(){
			}, function(){
				$('.drop-down').hide();
			});
	}, function(){		
	});
	
	$('#top-nav li a.con').hover(function(){
		$('.drop-down').hide();
		$('#more-con').show().hover(function(){
		
			}, function(){
				$('.drop-down').hide();
			});
	}, function(){
	});
	
	$('#top-nav li a.who').hover(function(){
		$('.drop-down').hide();
		$('#more-who').show().hover(function(){
			}, function(){
				$('.drop-down').hide();
			});
	}, function(){
	});
	
	$('#right-side-list li a.to-twit').click(function(){
		$('.drop-down').hide();
		$('#more-twit').show().hover(function(){
			}, function(){
				$('.drop-down').hide();
			});
	});
	
	$('#drop-down-wrap').hover(function(){
	
	}, function(){
		$('.drop-down').hide();
	});

});

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 twitterCallback(obj) 
{
var twitters = obj;
var statusHTML = "";
var username = "";
for (var i=0; i<twitters.length; i++)
{
username = twitters[i].user.screen_name
// Check to see if there is a link in the tweet
splitTweet = twitters[i].text.split(" ");
for (tp in splitTweet)
{
linkChk = splitTweet[tp].search("http://");
personChk = splitTweet[tp].search("@");
if (linkChk != -1)
{
splitTweet[tp] = "<a href='" + splitTweet[tp] + "'>" + splitTweet[tp] + "</a>";
}
if (personChk != -1)
{ 
splitTweet[tp] = "<a href='http://www.twitter.com/" + splitTweet[tp].substr(1) + "'>" + splitTweet[tp] + "</a>";
}
}
tweetText = "";
for (tp in splitTweet)
{
tweetText = tweetText + splitTweet[tp] + " ";
}
statusHTML += ('<div><p>' + tweetText + '<a class="time_posted" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at) + '</a></p></div>');
}
document.getElementById('tweets').innerHTML = "";
document.getElementById('tweets').innerHTML = statusHTML;
}