
	var itemcount = Math.ceil((itemcount == null) ? 0 : itemcount);
	var currentitem = 0;
	var previousitem = currentitem;
	var defaultspeed = 600;
	var offset = (offset != null) ? offset : 0;
	// var itemcount is found within xhtml-template
	
	
	$("#arrow-next, .next").mousedown(function() { startScrolling("next"); });
	$("#arrow-prev").mousedown(function() { startScrolling("prev"); });
	$("#arrow-prev, #arrow-next, .next").mouseleave(function() { stopScrolling(); });
	$("#arrow-prev, #arrow-next, .next").mouseup(function() { stopScrolling(); });
	
	
	function startScrolling(direction) {
		scrollToItem(direction);
		timer = setTimeout("startScrolling('"+direction+"')", speed + 50);	
	}
	
	function stopScrolling() {
		clearTimeout(timer);
	}
	
	function scrollToItem(direction) {
		
		previousitem = currentitem;
		
		// next item
		if (direction == 'next') {
			$("#arrow-prev").show();

			// prevent "overscrolling"
			if (currentitem > (itemcount-3)) {
				currentitem = (itemcount-1);
				$("#arrow-next").hide();
			} else {
				currentitem++;  
				$("#arrow-next").show();
				
			}
		}
		
		
		// previous item
		if (direction == 'prev') {
			$("#arrow-next").show();
			
			// prevent "underscrolling"
			if (currentitem < 2) { 
				currentitem = 0;
				$("#arrow-prev").hide();
			} else { 
				currentitem--; 
				$("#arrow-prev").show();
			}
		}
		
		
		// first item
		if (direction == 'first') {
			$("#arrow-next").show();
			$("#arrow-prev").hide();
			currentitem = 0;				
		}
		
		// now scroll!
		doScrolling();		

		return false;
	
	}
	
	
	function doScrolling(speedoverwrite) {

		if (speedoverwrite != null) { speed = speedoverwrite; }
		else { speed = defaultspeed; }
		

		// scrollen
		var curItem = $("#items > li:eq("+currentitem+")");
		$("#scroller").stop().scrollTo(
			curItem, 
			speed, 
			{
				offset:offset,
				onAfter: function() {
					// set selected border
					$("#items li").removeClass("selected");
					curItem.addClass("selected");
					
					// update detailinfo
					if (typeof curItem.find("img").attr("rel") != 'undefined') {
						fieldvalues = curItem.find("img").attr("rel").split(",");
						youtubesrc = "http://www.youtube.com/embed/" + fieldvalues[1];
						imgsrc = "/media/media/resizeMedia.do?media_id=" + fieldvalues[0];
					
						// Video file + smallimage
						if (fieldvalues[1].length > 0) {
							
							$(".bigbox td").html(
								"<iframe width=\"305\" height=\"200\" src=\"http://www.youtube.com/embed/" + 
								fieldvalues[1] + "\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>"
							);
							
							$(".bigbox #smallimage").html("<img src=\"" + imgsrc + "&amp;width=50&amp;height=50\" />");
						
						// nur Bild
						} else {
							$(".bigbox td").html("<img src=\"" + imgsrc + "&amp;width=258&amp;height=188\" />");
							$(".bigbox #smallimage").empty();
						}
						
						$(".bigbox > div#scrollercontent").html(curItem.children(".info").html());
					}	
				}
			}
			
		);
				
	}
	
	
	function scrollDirectlyToItem(ele) {
		currentitem = $(ele).attr("rel");
		if (currentitem < 1) {
			$("#arrow-prev").hide();
			$("#arrow-next").show();
		}
		
		if (currentitem > 0) {
			$("#arrow-prev").show();
			$("#arrow-next").hide();
		}
		
		doScrolling();
	}
	
	
	function checkSpektrumBackButton() {
		if ($("#arrow-prev").css("display") == "none") { $("#spektrum-backbutton").show(); } 
		else { $("#spektrum-backbutton").hide(); }
	}

	
	// init
	if (currentitem > 0) { $("#arrow-prev").show(); }
	if (currentitem == (itemcount-1)) { $("#arrow-next").hide(); }
	if (itemcount < 2) {
		$("#arrow-next").hide();
		$("#arrow-prev").hide();
	}
	doScrolling(50);
	
	// scroll by hashtag
	elepos = location.hash.substring(1);
	if (elepos.length > 0) {
		scrollDirectlyToItem($("#items li").eq(elepos-1));
	}

