/**
*	Custom Image Slider 
*	@Author Dennis Nissen (post@dennisnissen.de)
*	18.11.2011
*	
*/

jQuery.fn.imageSlider = function(){

	this.data("slides",new Array());
	this.data("currentSlide",0);
	var _this = this;
	this.updateSlider = function(){
		var currentSlide = _this.data("currentSlide");
		var slides = _this.data("slides");
		currentSlide++;
		if (currentSlide > slides.length){
			currentSlide=0;
		}
		jQuery(slides[currentSlide]).trigger("click");
		_this.data("currentSlide",currentSlide);
	}
	 jQuery(".small .thumb img",this).click(function(){
			var __this = this;
			jQuery(".big img").fadeOut("slow",function(){
					//remove link from big image if there is one
					if (jQuery(".big a").size() > 0){
						jQuery(".big img").unwrap();
					}
					jQuery(".big img", _this).attr("src",jQuery("img",jQuery(__this).parent().next()).attr("src"));
					//see if there is a link with the new image
					if (jQuery("a",jQuery(__this).parent().next()).size() > 0){
						jQuery(".big img").wrap(jQuery("a",jQuery(__this).parent().next()));
					}
					
					jQuery(".big img", _this).fadeIn("slow");
				});
	});
	jQuery(".small .thumb img", this).each(function(){
		var slides = _this.data("slides");
		slides.push(this);
		_this.data("slides",slides);
	});
	window.setInterval(this.updateSlider,7000);

}


	
