	var slideTimer = new Object;
jQuery(function(){
	var curFeat = 3;
	var curFull = 4;
	var animSpeed = 1200;
	var slideDelay = 12000;
	var curAnim = false;
	
	$('.sub-home .sub-nav ul li a').mouseover(function() {
   		$('.sub-home .sub-nav ul li a').addClass('dull');
   		$(this).removeClass('dull');
  	}).mouseout(function(){
       		$('.sub-home .sub-nav ul li a').removeClass('dull');
  	});
	
	$("#featurePreviews").jcarousel({
    	wrap: 'circular',
    	initCallback: mycarousel_initCallback,
    	buttonNextHTML: null,
        buttonPrevHTML: null,
        animation: animSpeed
    });
    function mycarousel_initCallback(carousel) {

	    jQuery('#featurePreviews li a').each(function(idx){
				$(this).click(function(){
				//document.title = curAnim;
					if (curAnim == false){ 
						curAnim = true;
						clearInterval(window.slideTimer);
						clickSlide(idx);
						
					}
					return false;
				});
		});
		function clickSlide(idx) {
			
			var amt = Math.abs(idx+1 - curFeat);
			if (idx == 0 && curFeat == 1) {
				amt = 3;
			} else if (idx == 0 && curFeat == 3) {
				amt = 1;
			} else if (idx < curFeat) {
				amt = idx + curFeat;
				if (amt > 3) { amt = amt - 2; }
			} else {
				amt = idx - curFeat;
			}
			carousel.options.scroll = amt;
			$('.homeFeature .full .feat'+curFull).animate({'left':'-880px'},animSpeed, function(){ $(this).css('left','880px'); });
			curFeat = idx;
			curFull = curFeat + 1;
			$('.homeFeature .full .feat'+(curFull)).animate({'left':'0px'},animSpeed, function(){curAnim = false;});
			carousel.next();
		}
	  	function startCarousel() {
	  		slideTimer = window.setInterval(nextSlide, slideDelay);
	  	}
		function nextSlide() {
			clearInterval(window.slideTimer);
			var nextFeat;
			if (curFeat == 3) { nextFeat = 0 } else { nextFeat = curFeat + 1; }
			clickSlide(nextFeat); 
			startCarousel();
		}
		startCarousel();

	}

	
});

