$(window).load(function () {

	// home banner show

   $(".banner-bg").fadeIn(2000, function () {
       $(".banner-text").fadeIn(1000);
   });
   
   // portfolio show
	
	$(".home-port ul li, .all-port ul li").each(function( intIndex ){
 		var imgH = $('img', this).height();
 		$(this).css("height", imgH);
    });
    
    $('.project-show').cycle({ 
    fx:      'fade',
    timeout: 0,
	next: '.project-show div',
	pager: '#project-nav'
	
	});
	
});

$(document).ready(function () {

	$('#flickr_badge_wrapper').prepend('<div id="flickr_badge_image" class="flickr_badge_image"><a href="http://www.flickr.com/photos/brocktoncg"><img width="75" height="75" title="IMG_0067" alt="A photo on Flickr" src="/themes/i/flickr-hdr.png"></a></div>');
	
	$(".col-work:last-child").addClass("last");
	
// Blog Shiz
	
$('.blog-filter ul li').click(function(){
	 
	 $('.activeChild').fadeTo(600, '0', 'easeInOutExpo').hide();
	 $('.activeBlock a img').show();
	 
	 	if ($('.blog-filter ul li').hasClass('activeBlock')) {
	 				
			$('.activeBlock').removeClass('activeBlock');
			$('.activeChild').removeClass('activeChild');
	 
	 	};
		
			$('a img',this).hide();
		
			$(this).addClass('activeBlock');			
			var thisBlock = $(this);
			var thisChild = thisBlock.children('div');
			thisChild.addClass('activeChild');
			
			$(this).stop().animate({height:'150px'}, 666, 'easeInOutExpo');
			thisChild.fadeTo(600, '1', 'easeInOutExpo').show();
			
			$('.closeMe').fadeTo(600, '1', 'easeInOutExpo').show();
			
	});
		
		$('.closeMe').click(function(){ 
		
			$('.blog-filter ul li').stop().animate({height:'25px'}, 666, 'easeInOutExpo');
			$('.activeChild').fadeTo(600, '0', 'easeInOutExpo').hide();
			$('.closeMe').fadeTo(600, '0', 'easeInOutExpo').hide();
			$('.blog-filter ul li a img').show();
		
		});
		
	$('.commentshow').toggle(function(){
	
		$('.comment-form-c').fadeTo(600, '1', 'easeInOutExpo').show();
	
	},function(){
		
		$('.comment-form-c').fadeTo(600, '0', 'easeInOutExpo').hide();
	
	});
		
   
   // portfolio thumbnails	
   
   $('.home-port ul li').hover(function() {
    	var desH = $('.description').outerHeight();
    	$('img', this).stop().animate({"margin-top": "-" + desH + "px"}, 500 );
		}, function() {
    		$('img', this).stop().animate({"margin-top": "0px"}, 500 );
	});
	
	// portfolio navigation
	
	function show() {
     var menu = $(this);
     menu.children(".client-select").slideDown();
   }
  
   function hide() { 
     var menu = $(this);
     menu.children(".client-select").slideUp();
   }
 
   $(".cs-hover").hoverIntent({
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     interval: 50,   // number = milliseconds for onMouseOver polling interval
     over: show,     // function = onMouseOver callback (required)
     timeout: 300,   // number = milliseconds delay before onMouseOut
     out: hide       // function = onMouseOut callback (required)
   });
   	
}); 

function initMenu() {
	$('#menu ul').hide();
	$('#menu li a').click(
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				return false;
				
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#menu ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				$('#menu li a').removeClass('active');
				$(this).addClass('active');
				return false;
			}
			}
		);
	}
$(document).ready(function() {initMenu();});

/*
 *  TWITTER API
*/
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('<li>'+status+'<br/><small class="right" style="margin-top:10px; font-size:80%;">'+relative_time(twitters[i].created_at)+'</small></li><br class="clear"/>');
  }
  document.getElementById('twitter_update_list').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 = 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';
  }
}

