
$(document).ready(function() {
	$(function() {
		$("div.slideshow").each(function(index){
			$(this).attr('id', 'slideshow'+(index+1)+'');
			var slideshow_id = $(this).attr("id");
	    });
	});
});

$(document).ready(function() {
	$(function() {
		$("a.next").each(function(index){
			$(this).attr('id', 'next_'+(index+1)+'');
			var next_id = $(this).attr("id");
		 });
	});
	$(function() {
		$("a.prev").each(function(index){
			$(this).attr('id', 'prev_'+(index+1)+'');
			var prev_id = $(this).attr("id");
		 });
	});
});
$(document).ready(function() {
	$(function() {
		$('div.slidesContainer').each(function(i) {
			var wie = $(this).children().length;
			if (wie == 1) {
				$("a#prev_"+(i+1)+"").hide();
				$("a#next_"+(i+1)+"").hide();
			}else{
				// weiter so
			}
	    });
	});
});
		
$(document).ready(function() {
	$(function() {
	    $('div.slidesContainer').each(function(i) {
		var p = this.parentNode;
	        $(this).before('').attr('id', 'touch_'+(i+1)+'').cycle({
	            fx:     'scrollHorz',
	            speed:  'fast',
	            timeout: 0,
				next: $('a.next', p),
				prev: $('a.prev', p),
				before: onBefore,
				after: 	onAfter
	        });
			function onBefore(curr, next, opts) {
				var index = opts.currSlide;
				$(function() {
					if (index == 0){
						$("a#prev_"+(i+1)+"").removeClass("nav_first");
						$("a#prev_"+(i+1)+"").addClass("nav_first");
					}
				});
			}
			function onAfter(curr, next, opts) {
				var index = opts.currSlide;
				$(function() {
					if (index == 0){
						$("a#prev_"+(i+1)+"").addClass("nav_first");
					}
					if (index > 0){
						$("a#prev_"+(i+1)+"").removeClass("nav_first");
					}
					if (index == opts.slideCount- 1){
						$("a#next_"+(i+1)+"").addClass("nav_last");
					}
					if (index < opts.slideCount- 1){
						$("a#next_"+(i+1)+"").removeClass("nav_last");
					}
				});
			}
		});
	});
});

// gibt jeder Slideshow eine ID und benutzt diese um die touchwipe funktion anzu wenden
$(document).ready(function() {
	$(function() {
		if ( $.browser.msie ) {
		 // do nothing
		}else{
			$(".slidesContainer").each(function(index){
				var div_id = $(this).attr("id");
				$("[id="+div_id+"]").touchwipe({
		        	wipeLeft: function() {
		            	$("[id="+div_id+"]").cycle("next");
		        	},
		        	wipeRight: function() {
		            	$("[id="+div_id+"]").cycle("prev");
		        	}
		    	});
		    });
		}
	});
});

