//tab effects
var obj;
var TabbedContent = {
	init: function() {	
		$(".tab_item").click(function() {
		
			var background = $(this).parent().find(".moving_bg");
			
			$(background).stop().animate({
				left: $(this).position()['left']
			}, {
				duration: 300
			});
			
			TabbedContent.slideContent($(this));
			
			clearInterval(autoProgress);
			
		});
	},
	
	slideContent: function(obj) {
		
		var margin = $(obj).parent().parent().find(".slide_content").width();
		margin = margin * ($(obj).prevAll().size() - 1);
		margin = margin * -1;
		
		$(obj).parent().parent().find(".tabslider").stop().animate({
			marginLeft: margin + "px"
		}, {
			duration: 300
		});
	}
}

$(document).ready(function() {
	TabbedContent.init();
	
	var count = 0;
	// Set up the interval for auto rotation
	autoProgress = setInterval(function() {
		// Grab the next slide
		newTab = $(".tab_item").eq(count);
		// Animate
		var background = newTab.parent().find(".moving_bg");
		$(background).stop().animate({
			left: newTab.position()['left']
		}, {
			duration: 400
		});	
		TabbedContent.slideContent(newTab);
		// Progress count
		count = count + 1 >= $(".tab_item").length ? 0 : count + 1;
	// Delay between auto rotations	
	}, 7000);	
});


var margin = $(obj).parent().parent().find(".slide_content").width();
margin = margin * ($(obj).prevAll().size() - 1);
margin = margin * -1;

$(obj).parent().parent().find(".tabslider").stop().animate({
	marginLeft: margin + "px"
}, {
	duration: 300
});
