//jQuery.noConflict();

// Document Ready Event
jQuery(document).ready(function(){

	// Featured Slide Thing
				
	var items = jQuery('.featured li');
	var item_width = 500;
	var max_margin = items.length * item_width - item_width;
	var animstatus = false;
	var user_click = false;
	var animation_speed = 1000;
	var auto_speed = 4000;
				
				
	jQuery('.featured .fthumbs a').each(function(i,link) {
		var index = i+1;
		jQuery(link).click(function(e) {
			e.preventDefault();
			user_click = true;
			
			moveFeature(index);
		});
	});
				
	function moveFeature(location) {
		if(animstatus == false) {
			animstatus = true;
			var feature = jQuery('.featured ul');
			var pos = parseInt(jQuery(feature).css('left'));
			
			if(location) {
				if(location=='next') {
					if(pos == -max_margin){
						left = 0;
					}
					else {
						left = pos-item_width;
					}
				}
				else if(location=='back') {
					if(pos == 0){
						left = -max_margin;
					}
					else {
						left = pos+item_width;
					}
				}							
				else {
					left = -(item_width*location)+item_width;
				}
				
				var item = Math.abs(left/item_width);
				jQuery('.featured .fthumbs a img').removeClass('active');
				jQuery('.featured .fthumbs a:eq('+item+') img').addClass('active');
				
				feature.animate({left: left},animation_speed,"swing",function() {
					animstatus = false;
				});
			}
		}
	}
				
	function feature_automove() {
		if(user_click == true) {
			user_click = false;
		}
		else {
			moveFeature('next');
		}
	}
	
	var feature_auto = setInterval(feature_automove, auto_speed);
	
});
