﻿/* ============================
DotControl copyright 2010
by Anton P.
==============================*/



$(document).ready(function () {
	var stoptime = 10000;
	var slides = $(".slides ul li");
	var content = $(".main_slide");
	var currentslide = 0;
	nextslide();
	var Timer = setInterval(nextslide, stoptime);
	$('.slider').hover(
		function () {
			clearInterval(Timer)
		},
		function () {
			Timer = setInterval(nextslide, stoptime);
		}
	);


	function clicked(slide) {
		currentslide = jQuery.inArray(slide, slides);
		//Set Variables
		var imgAlt = $(slide).find('img').attr("alt"); //Get Alt Tag van de IMG
		var imgUrl = $(slide).find('a').attr("href"); //Get Main Image
		var imgDesc = $(slide).find('.block').html(); 	//Get HTML of slide
		var imgDescHeight = content.find('.block').height(); //Bereken de hoogte van de slider	

		var contentImage = content.find("img");
		var contentCaption = content.find(".block")

		if (!$(slide).is(".active")) {
			//Animate the Teaser + IMG		
			contentImage.animate({ opacity: 0 }, 300, function () {
				contentImage.animate({ opacity: 1 }, 500);
				contentImage.attr({ src: imgUrl, alt: imgAlt });
			});
			content.find(".block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 300, function () {
				content.find(".block").html(imgDesc).animate({ opacity: 0.80, marginBottom: "0" }, 300);
			});

		} else {
			return false;
		}

		$(".slides ul li").removeClass('active');
		$(slide).addClass('active');
		return false;
	}

	function nextslide() {
		clicked(slides[currentslide]);
		currentslide++;
		if (currentslide == slides.length) {
			currentslide = 0;
		}
	}

	//Click and Hover events for slidenail list
	$(".slides ul li:first").addClass('active');
	$(".slides ul li").click(function () {
		clicked(this);
	}).hover(function () {
		$(this).addClass('hover');
	}, function () {
		$(this).removeClass('hover');
	});
});
