var spot_count 	  = 1;
var spot_position = 1;
var num_spots	  = 0;
var btn_clicked   = '';

$(document).ready(function(){
	// Get the number of feature items from the spots ul rel
	num_spots = $('#spots > li').size();

	$("#homecarousel").jCarouselLite({
		// auto: 5000, 
		speed: 1000,
	    btnNext: "#ss-next",
	    btnPrev: "#ss-prev",
		easing: "easeOutQuart",
		afterEnd: function() {
			if(btn_clicked == 'prev') {
				$('#spots li').removeClass('active');
				spot_position--;
				if(spot_position == 0) spot_position = num_spots;
				$('#spot-feature-item-'+spot_position).addClass('active');
			} else if(btn_clicked == 'next') {
				$('#spots li').removeClass('active');
				spot_position++;
				if(spot_position > num_spots) spot_position = 1;
				$('#spot-feature-item-'+spot_position).addClass('active');
			}
		}
	});
	
	$('.tooltip-parent').simpletip({
		onShow: function() {
			this.update(this.getParent().attr('rel'));
		}
	});
	
	$('#ss-prev').click(function() {
		btn_clicked = 'prev';
	});

	$('#ss-next').click(function() {
		btn_clicked = 'next';
	});

	$("a[rel='external']").click( function(){ window.open($(this).attr('href')); return false; });
	$("a[rel='nofollow']").click( function(){ window.open($(this).attr('href')); return false; });


});