
window.onload = function() {
	var ajax_load = "<img class='loader' src='img/load.gif' alt='Loading...' />";
	var url = 'http://twitter.com/statuses/user_timeline/TrickywebDesign.json?callback=twitterCallback2&count=4';
	var script = document.createElement('script');	
	$("#twitter_feed").html(ajax_load);
	script.setAttribute('src', url);
	document.body.appendChild(script);
}
 
function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, 
	function(url) { return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<div class="tweet_box"><div class="tweet_date"><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at)+'</a></div><div class="tweet_status"><p>'+status+'</p></div></div>');
  }
  document.getElementById('tweets').innerHTML = statusHTML.join('');
}
 
function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + " " + values[5] + " " + values[3];
  var parsed_date = new Date();
  parsed_date.setTime(Date.parse(time_value));  
  var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
	'Sep', 'Oct', 'Nov', 'Dec');
  var m = parsed_date.getMonth();
  var postedAt = '';
  postedAt = months[m];
  postedAt += " "+ parsed_date.getDate();
  postedAt += ","
  postedAt += " "+ parsed_date.getFullYear();
  return postedAt;
}

jQuery( document ).ready( function(){
		var index = 3;
		var cur_elem = ('#w'+index);
		var title = $(cur_elem).attr('title');
		var alt = $(cur_elem).attr('alt');
		$('#cap_title').text(title);
		//$('#cap_alt').text(alt);
        jQuery( '#flip' ).jcoverflip({
          current: 3,
		  beforeCss: function( el, container, offset ){
            return [
              $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 310 - 160*offset + 20*offset )+'px', bottom: '50px' }, { } ),
              $.jcoverflip.animationElement( el.find( 'img' ), { width: Math.max(10,150-20*offset*offset) + 'px' }, {} )
            ];
          },
		  currentCss: function( el, container ){
            return [
              $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 150 )+'px', bottom: '30px' }, { } ),
              $.jcoverflip.animationElement( el.find( 'img' ), { width: '300px' }, { } )
            ];
          },
		  afterCss: function( el, container, offset ){
            return [
              $.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 160 + 160*offset )+'px', bottom: '50px' }, { } ),
              $.jcoverflip.animationElement( el.find( 'img' ), { width: Math.max(10,150-20*offset*offset) + 'px' }, {} )
            ];
          },
          change: function(event, ui){
			  var index = $('#flip').jcoverflip('current');
			  var cur_elem = ('#w'+index);
			  var title = $(cur_elem).attr('title');
			  var alt = $(cur_elem).attr('alt');
				$('#cap_title').text(title);
				//$('#cap_alt').text(alt);
          }
      });
		$('.next').click(function(){
		
			 $('#flip').jcoverflip('next', '1', true);
		});
		
		$('.prev').click(function(){
		
			 $('#flip').jcoverflip('previous', '1', true);
		});
});

//260
