/**
 * jQuery.slideshow - Fadeshow Jquery
 * @author Jeroen Evers <jeroen@be-interactive.nl>
 * @version 0.1
 * @date 2010-12-16
 */
// -- slideshow vars en functions
	var slideDuration = 7000;
	var fadeDuration = 1500;
	var fadeDurationFast = 300;
	var nextIndex = 0;
	var currentIndex = 0;
	var timer = false;
	var slide_h = '397px';
	var slide_w = '486px';


	/*
	 * initSlide
	 * 
	 * Hide elements, start autoSlide.
	 */
	function initSlide(){
		//$(".slideshow li").css({opacity: 0.0});
		// set CSS for items
		autoSlide();
		$('.slideshow,.slideshow ul,.slideshow ul li').css({
			'width' : slide_w,
			'height' : slide_h
		});
	};
	
	/*
	 * autoSlide
	 * 
	 * Automatic slide function. 
	 * Sets timer interval.
	 */
	function autoSlide(){
		// next slide
		nextIndex = currentIndex+1;
		if(nextIndex > $(".slideshow li").length) {
			nextIndex = 1;
		}
		
		// action
		$("'.slideshow li:nth-child("+nextIndex+")'").animate({opacity: 1.0}, fadeDuration).addClass('show');
		$("'.slideshow li:nth-child("+currentIndex+")'").animate({opacity: 0.0}, fadeDuration).removeClass('show');
		currentIndex = nextIndex;
		
		// set interval timer
		if (!timer) {
			timer = window.setInterval('autoSlide()',slideDuration);
		}
	};
	
	/*
	 * doSlide
	 * Manual slide function.
	 * 
	 * @param varchar $type direction: next or previous
	 */
	function doSlide(type){
		// kill timer
		window.clearInterval(timer);
		
		// next slide
		if (type=='next') {
			nextIndex = currentIndex+1;
			if(nextIndex > $(".slideshow li").length) {
				nextIndex = 1;
			}
		// previous slide
		} else if (type=='previous') {
			nextIndex = currentIndex-1;
			if(nextIndex < 1) {
				nextIndex = $(".slideshow li").length;
			}
		}
	
		// action
		$("'.slideshow li:nth-child("+nextIndex+")'").animate({opacity: 1.0}, fadeDurationFast).addClass('show');
		$("'.slideshow li:nth-child("+currentIndex+")'").animate({opacity: 0.0}, fadeDurationFast).removeClass('show');
		currentIndex = nextIndex;
	};
