jQuery(function($){

$.easy.popup();
				
	//homepage featured
	(function(){
		$('#featured').each(function(){
	
				var pause = 5000;
				var initPause = 0;
			
				var obj = $(this);	
				var children = $('.excerpt article', obj);
				var length = $(children).length;
				var temp = length-1;
				var z = 1;
				var timeout;
				var play = true;
				
				var numeric = $('<ol class="numeric"></ol>').appendTo(obj);

				function change(){						
					temp = (temp == length-1) ? 0 : temp+1; 
					show();
				};
				
				function show(){
					clearTimeout(timeout);						
					$(children).hide();						
					$('.excerpt article:eq(' + temp + ')',obj).fadeIn('fast');					
					$('.article-list article',obj).removeClass('active');
					$('.article-list article:eq(' + temp + ')',obj).addClass('active');
					if(play){	
						timeout = setTimeout(change,pause);
					}
				};
				
				function controls(){
					var controls = $('<div class="controls">').appendTo(obj);
					$('<a href="javascript:void(0);" class="button back-button"><span class="button-label">Back</span></a>')
						.click(function(){
							temp = (temp == 0) ? length-1 : temp-1; 
							show();			
						})
						.appendTo(controls)
					$('<a href="javascript:void(0);" class="button pause-button"><span class="button-label">Play / Pause</span></a>')
						.click(function(){
							playpause(this);	
						})
						.appendTo(controls)		
					$('<a href="javascript:void(0);" class="button next-button"><span class="button-label">Next</span></a>')
						.click(function(){
							temp = (temp == length-1) ? 0 : temp+1; 
							show();		
						})
						.appendTo(controls)	
				};
				
				function playpause(button){
					if(play){
						clearTimeout(timeout);
						play = false;
						$(button).addClass('play');
					} else {
						play = true;
						$(button).removeClass('play');
						timeout = setTimeout(change,0);						
					};
				};
								
				function init(){
					change(); 
					controls(); 
				};
				
				$('.article-list article',obj)
					.click(function(){							
						var index = $('.article-list article',obj).index(this);	
						if(index != temp){
							clearTimeout(timeout);
							temp = index;
							show();
						};
					});
						
				if (length > 1) setTimeout(init,initPause);						
			
		});
	})();
		
	//teams		
	(function(){
		$('#team-logos li').each(function(){
			var obj = this;
			var a = $('.top',obj);
			var div = $('.body',obj);
			$(obj).hover(
				function(){$(div).slideDown('fast');},
				function(){$(div).hide();}
			);
		});		
	})();	
		
		
	//homepage tabs
	(function(){
		var tabs = $('nav.tabs li');
		var targets = $('#follow-us .container').hide();	
		tabs.each(function(){						
			$(this).click(function(e){	
				e.preventDefault();
				var target = $('a',this).attr('href');
				tabs.removeClass('active');
				targets.hide();
				$(this).addClass('active');
				$(target).show();
			});
		});	
		$('nav.tabs li:eq(0)').trigger('click');
	})();
	
	//twitter box
	$('#twitter').each(function(){
		var obj = this;		
		var feed = 'http://twitter.com/status/user_timeline/twitter.json?count=4&callback=?';
		$('<ul></ul>').appendTo(obj);
		$.getJSON(feed, function(json) {
			$.each(json, function(i, item) {   
				var text = item.text;
				$('ul',obj).append('<li>'+text+'</li>');		  
		   });		   
		});
		$(obj).append('<p>Follow us on <a href="http://twitter.com/twitter">Twitter</a></p>');
	});
		
});
