			
			function initCallback(carousel) {
//				jQuery('#relatedtags a').bind('click', function() {
//					tag = $(this).text();
//					carousel.setup(1);
//					return false;
//				});
			};
			
			
			function itemLoadCallback(carousel, state)
			{
				if (carousel.has(carousel.first, carousel.last)) {
					return;
				}
				$.getJSON(
					'/API/photostream',
					{
						first: carousel.first,
						last: carousel.last,
						tag: tag
					},
					function(data) {
						itemAddCallback(carousel, carousel.first, carousel.last, data);
					}
				);
			};

			function itemAddCallback(carousel, first, last, data)
			{
				carousel.size(parseInt(data.amount));
				
				if (data.success == true) {
					var counter = 1;
					$.each(data.data, function(i,item){
						carousel.add(first + i, getItemHTML(item, counter));
						counter++;
					});
					$("a[rel^='prettyPhoto']").prettyPhoto();
				} else alert("keine Fotos verfügbar"); 
			};

			function getItemHTML(item,counter)
			{
				// var tag = '<a href="' + item.plink + '" title="' + item.Title + '"><img src="' + item.url + '" width="'+item.width+'" height="'+item.height+'" alt="'+item.Title+'" />';
				// var tag = '<a rel="prettyPhoto" href="' + item.fullsize + '" title="&lt;a href=&#x27;'+item.plink+'&#x27; target=&#x27;_top&#x27; &gt;Kommentare und Link zu: &lt;strong&gt;'+item.Title+'&lt;/strong&gt;&lt;/a&gt;"><img src="' + item.url + '" width="'+item.width+'" height="'+item.height+'" alt="'+item.Title+'" />';
				
				if (counter <= 3) {
					var tag = '<a rel="prettyPhoto[gallery]" href="' + item.fullsize + '" title="&lt;a href=&#x27;'+item.plink+'&#x27; target=&#x27;_top&#x27; &gt;Kommentare und Link zu: &lt;strong&gt;'+item.Title+'&lt;/strong&gt;&lt;/a&gt;"><img src="' + item.url + '" width="'+item.width+'" height="'+item.height+'" /></a>';
				} else {
					var tag = '<a rel="prettyPhoto" href="' + item.fullsize + '" title="&lt;a href=&#x27;'+item.plink+'&#x27; target=&#x27;_top&#x27; &gt;Kommentare und Link zu: &lt;strong&gt;'+item.Title+'&lt;/strong&gt;&lt;/a&gt;"><img src="' + item.url + '" width="'+item.width+'" height="'+item.height+'" /></a>';
				}
				return tag;
			};
		
			function restartCarousel(new_tag)
			{
				tag = new_tag; 
				carousel.prev();
				return false;
			}
			
			$().ready(function(){ 
				$('#mycarousel2').jcarousel({
					initCallback: initCallback,
					itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
					itemLoadCallback: itemLoadCallback
				});
				$('#imagelist').hide();
			}); 
