//http://totmacher.eu/jquery/ticker/examples.html

$(document).ready(function(){
	$(".ticker ul").ticker("init",{
		delay: 8000, 	// Delay between switching of elements
		speed: 500, 		// Animation speed
		linked: true, 	// If stepping after last element will go to first or stop and stepping before first will goto last or stop
		selection: 'li',	// The sub-selection to use for each element
		animations: {
			_in:'fadeIn',	// Animation used to fade in
			out:'fadeOut'	// Animation used to fade out
		},
		callbacks: {
			_in:function(ul) {
				items = $(".ticker li");
				items.each(function(_i) {
					if (ul.ticker.current == items[_i]) {
						$(".ticker .label").text((_i + 1) + "/" + items.length);
					}
				});
			},
			out:function(ul) {
				// Current (active) element is in ul.ticker.current
				// Called when the fade out animations tarts
			},
			init:function(ul) {
				// Current (active) element is in ul.ticker.current
				// Called when ticker is initialized
			}
		}
	}).ticker("loop");
	
	$(".ticker").append("<a href='javascript: void(0)' class='prev' title='Zum vorheriger Reisetipp'><</a>" +
						"<span class='label'>1/" + $(".ticker li").length + "</span>" +
						"<a href='javascript: void(0)' class='next' title='Zum nächsten Reisetipp'>></a>" + 
						"<a href='/specials' class='more' title='Übersicht aller Reisetipps'>&raquo;alle</a>");

	$(".ticker a.prev").click(function(){
		$('.ticker ul').ticker("stop");
		$('.ticker ul').ticker('prev');
	});
	
	$(".ticker a.next").click(function(){
		$('.ticker ul').ticker("stop");
		$('.ticker ul').ticker('next');
	});
});