// JavaScript Document
  	$(document).ready(function() {
	
		$("a#single_img").fancybox({
			'titlePosition'		: 'outside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition':'over',
			'showCloseButton'	: true
		});
		$("a#single").fancybox({
			'titlePosition'		: 'outside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition':'over',
			'showCloseButton'	: true
		});		
		$(".gallery").fancybox({
			'titlePosition'		: 'outside',
			'title' 			: 'To view full screen click the double arrows on bottom right corner',
			'autoDimensions'    : true,
			'scrolling'			: 'no',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'showCloseButton'	: true,
			'hideOnOverlayClick': false,
			'modal'				: false	
		});
		
		$(".calendar").fancybox({
			'titleShow'			: false,
			'autoDimensions'    : true,
			'scrolling'			: 'no',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'showCloseButton'	: true,
			'hideOnOverlayClick': false,
			'modal'				: false	
		});
				
		$(".video").fancybox({
			'titleShow'			: false,
			'autoDimensions'    : true,
			'scrolling'			: 'no',			
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'showCloseButton'	: true,
			'hideOnOverlayClick': false,
			'modal'				: false	
		});
						
		$(".contact").fancybox({
			'titleShow'			: false,
			'scrolling'			: 'no',			
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'showCloseButton'	: true,
			'hideOnOverlayClick': false,
			'modal'				: false,
			'type'				: 'iframe',
			'height'			: 500,
			'width'				: 500
		});
		
		$("a.compgallery").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'titleShow'		:	false
		});
		
		$("a.coachinggallery").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'titleShow'		:	false
		});		

		
		//When page loads...
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content

		//On Click Event
		$("ul.tabs li").click(function() {

			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
	
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
	
	
  	}); // end functions

	// animated anchor scroll
	$(document).ready(function() {
			$("a.anchorLink").anchorAnimate()
		});
		jQuery.fn.anchorAnimate = function(settings) {
			settings = jQuery.extend({
			speed : 1100
			}, settings);	
		
		return this.each(function(){
			var caller = this
			$(caller).click(function (event) {	
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = $(caller).attr("href")
				
				var destination = $(elementClick).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
					window.location.hash = elementClick
				});
				return false;
				})
			});
	} ///////// end animated anchors /////////
	
	// begin twitter feed
    $(document).ready(function(){
    
    	
    	$.getJSON('http://twitter.com/status/user_timeline/toniwestwnbfpro.json?count=3&callback=?', function(data){
    		$.each(data, function(index, item){
    			$('#twitter').append('<div class="tweet"><p>' + item.text.linkify() + '</p><p><strong>' + relative_time(item.created_at) + '</strong></p></div>');
    		});
    	
    	});
    	
    	
    	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);
    	  
    	  var r = '';
    	  if (delta < 60) {
    		r = 'a minute ago';
    	  } else if(delta < 120) {
    		r = 'couple of minutes ago';
    	  } else if(delta < (45*60)) {
    		r = (parseInt(delta / 60)).toString() + ' minutes ago';
    	  } else if(delta < (90*60)) {
    		r = 'an hour ago';
    	  } else if(delta < (24*60*60)) {
    		r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
    	  } else if(delta < (48*60*60)) {
    		r = '1 day ago';
    	  } else {
    		r = (parseInt(delta / 86400)).toString() + ' days ago';
    	  }
    	  
    	  return r;
    	}
    	
    	String.prototype.linkify = function() {
    		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
    			return m.link(m);
    		});
    	};
    
    }); // end twitter
