/* Animation and scripting for site */
var ah = {
	init: function(){
		ah.contact.init();
		ah.externalLinks();
		ah.centerImages();
		delete ah.init;
	},
	externalLinks: function(){
		$('#activity_list a:not([href*="http://austinhappel.com"]), #stalkBubble a').attr("target", "_blank");
	},
	centerImages: function(){
		var self = this;
		$(window).load(function() {
			var elems = $('#activity_list li.item div.image a img')
			var count = elems.length;
			
			elems.each(function(i){
				if($(this).width() > 140) {
					$(this).css({
						"margin-left" : (-($(this).width() / 2) + 70) + "px"
					});
				}
				if($(this).height() > 200) {
					$(this).css({
						"margin-top" : (-($(this).height() / 2)) + 100 + "px"
					});
				}
				/* resize short images. This makes the images look pixellated :(
				----------------------------------------------------------------
				if($(this).height() < 200) {
					$(this).css({
						"height" : "200px"
					});
				}
				*/
				// if the subtraction of 'count' is 0 then run the rest...
				if(!--count){
					self.showItems();
				}
			});
		});
		
	},
	showItems: function (){
		var self = this;
		
		// start fading in the li's one by one
		$('#activity_list li:first').hide().removeClass('hidden').fadeIn(300, function(){
			self.listFader($(this).next());
		});
		
		$('#pagination').hide().removeClass('hidden');
				
		/*  Works also: 
		$('#activity_list li').each(function(i){
			var target = $(this);
			$('#activity_list').queue('loader',function(){
				target.hide().removeClass('hidden').fadeIn(200, function(){
					$('#activity_list').dequeue('loader');
				});
			});
		});
		$('#activity_list').dequeue('loader');
		*/
		
		/*	works also, but fades ALL images in at once.
			$('#activity_list li').hide().removeClass('hidden').delay(300).fadeIn('slow'); 
		*/
	},
	listFader: function(target){
		var self = this;
		
		target.hide().removeClass('hidden').fadeIn(200, function(){
			if(!$(this).next().length){
				$('#pagination').fadeIn();
			}
			self.listFader($(this).next());
		});
	}
}

$(document).ready(function(){
	ah.init();
});		


