$(function(){
/**** Features Slider ****/
	var fc_width = 1000;
	var scrubber_item;
	var scrubber_items = $("#featured-carousel #scrubber .item").size();
	var fc_active_item = $("#featured-carousel #scrubber .item").index('.active-item');
	var animDuration = 500;

	/**** The slider animation ****/
	function tal_animate(el, x) 
	{
		el.animate({ "left": "+="+x }, animDuration);
	}

	var a = 0;
	var autoplay = setInterval(function() { 
		if (a < (scrubber_items-1)) {
			tal_animate($('#featured-carousel #billboard .ads'), '-1000px');
			$('#featured-carousel #scrubber .active-item').removeClass('active-item').next().addClass('active-item');
			a++;
        } else {
			tal_animate($('#featured-carousel #billboard .ads'), '3000px');
			$('#featured-carousel #scrubber .active-item').removeClass('active-item');
			$('#featured-carousel #scrubber .item:first').addClass('active-item');
			a=0;
		}
		fc_active_item = a;
	}, 8000 );
	
	$('#featured-carousel #scrubber .item').click(function(e) {
		scrubber_item = $('#featured-carousel #scrubber .item').index(this);
		if (scrubber_item != fc_active_item) {
			var fc_direction = (scrubber_item > fc_active_item ? 'right' : 'left');
			var moveX;
			if (fc_direction == 'right') { moveX = (scrubber_item == 0 ? (scrubber_items -1) * fc_width +'px' : (scrubber_item - fc_active_item) * -fc_width +'px'); }
			if (fc_direction == 'left')  { moveX = (fc_active_item - scrubber_item) * fc_width +'px'; }
			$('#featured-carousel #scrubber .active-item').removeClass('active-item');
			$(this).addClass('active-item');
			tal_animate($('#featured-carousel #billboard .ads'), moveX);
			fc_active_item = scrubber_item;
			clearTimeout(autoplay);
		}
	});
	
	$('a.fancy').fancybox();
	$('a.ajax_fancy').fancybox({
		ajax: {	type: 'GET' }
	});
	
	/* Loader Links */
	$('a.loader').click(function(e){
		e.preventDefault();
		tal_loader($(this));
	});

});
