// JavaScript Document

/* ------------------------------------------------ Global vars */
var webPath = "http://www.dahlsfoods.com/index.php/";
/* ------------------------------------------------ Global vars */


/* ------------------------------------------------ Document ready (onload) */
$(document).ready(function(){
});
/* ------------------------------------------------ Document ready (onload) */


/* ------------------------------------------------ Carousel */
// Global vars
var reqSlide = 0;
var loop;
var timer = 0;

// Run carousel
function runCarousel(){
	if(!timer)
	{
		timer=1;
		carousel();
	}
}

// Stop carousel
function stopCarousel(){
	clearTimeout(loop);
	timer=0;
}

// Pause carousel
function pauseCarousel(){
	$('#carousel_link').hover(
		function(){
			stopCarousel();
		}, 
		function(){
			setTimeout('runCarousel()', 3000);
		}
    );
}

// Change the carousel slide
function changeCarousel(){
	clearTimeout(loop);
	timer=0;
	runCarousel();
}

// Slide transition and loop
function carousel(){
	// Number of slides
	var slides = 6;
	
	// Adjust the requested slide if needed
	if(reqSlide >= slides){
		reqSlide = 0;
	}
	
	// Request the next slide
	$.ajax({
		url: webPath+'carousel/get/slide:'+reqSlide,
		success: function(data){
			$('#carousel_link').stop(true, true).html(data).fadeIn(2000);
			$('.carlnk').removeClass('active');
			$('#carlnk_'+reqSlide).addClass('active');
			
			reqSlide++;
			loop = setTimeout('carousel()', 7000);
		}
	});
}
/* ------------------------------------------------ Carousel */


/* ------------------------------------------------ Carousel Navigation */
function carouselNav(){
	// request the next slide
	$.ajax({
		url: webPath+'carousel/nav',
		success: function(data){
			$('#carousel_nav').html(data);
		}
	});
}
/* ------------------------------------------------ Carousel Navigation */
