//twitter function time
//from twitters blogger badge
//http://twitter.com/javascripts/blogger.js
function relative_time(time_value) {
   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);

   if(delta < 60) {
       return 'less than a minute ago';
   } else if(delta < 120) {
       return 'about a minute ago';
   } else if(delta < (45*60)) {
       return (parseInt(delta / 60)).toString() + ' minutes ago';
   } else if(delta < (90*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';
   }
}


$(document).ready(function(){

	 $(".speach a img").click(function(){
		
		if($(this).parent().attr("href").search(/.jpeg/) > -1 || $(this).parent().attr("href").search(/.gif/) > -1 || $(this).parent().attr("href").search(/.jpg/) > -1 || $(this).parent().attr("href").search(/.png/) > -1)
		{
			$(this).parent().fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayOpacity': 0.7}); 
		}
		
	 });
	 
	 $(".speach a").click(function(){
		
		if($(this).attr("href").search(/.jpeg/) > -1 || $(this).attr("href").search(/.gif/) > -1 || $(this).attr("href").search(/.jpg/) > -1 || $(this).attr("href").search(/.png/) > -1)
		{
			$(this).fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayOpacity': 0.7}); 
		}
		
	 });
	
	$("#boys img").hover(function(){
	  $(this).stop();
		$(this).animate({paddingBottom: "50px"}, 200);
	},function(){
			  $(this).stop();
		$(this).animate({paddingBottom: "0px"}, 200);					  
	});

   $("#boys img").qtip({
	position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
   },
   style: { 
	 padding: 10,
	   border: {
         width: 10
      },
	 tip: true,
      name: 'light'
   }

});

	var compile = "";
	var array = [];

	$("#tweets").hide();
	 $("#tweets").ajaxComplete(function(event,request, settings){
	   $(this).css("opacity", "0");
	   $(this).slideDown("slow");
	   $(this).fadeTo("slow", 1);
	 });



	$.getJSON("http://twitter.com/statuses/user_timeline/drve10.json?count=10&callback=?", function(json){
	
		$.each(json, function(i, val) {
		  
		  tweet = val.text;
		  
		  var patt1 = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/g;
			
		  array = tweet.match(patt1);
		  if(array){
			$.each(array, function(i, val) {
				tweet = tweet.replace(val, "<a href='"+val+"' target='_blank' rel='nofollow'>"+val+"</a>"); 		   
			}); 
		  }
		  
		  var tweet = tweet.replace(/(^|\s)@(\w+)/g, "$1@<a href='http://www.twitter.com/$2'>$2</a>");
		  
		  compile = compile+'<div class="tweet">';
		  
		  compile = compile+'<p>'+tweet+'</p>';
		  compile = compile+'<p class="dateSince">'+relative_time(val.created_at)+'</p>';
		  compile = compile+'</div>';
		  
		  $("#tweets").html(compile);
		  
		});
	
	});
 


});