		var image_pos = Array;
		var image_length_all = 0;
		var cur_slide_image = 0;
		var float = 100;
		var	img1,img2,img_load;
		var slide_dir = 0;
		
		$(document).ready(function(){
			img1 = $('#image1')
			img2 = $('#image2')
			img_load = $('#image_load')
			img1.hide()
			img2.hide()
			img_load.hide()
		});
		
		function slide_add( i ){
			if( images.length <= i){
				slide_to( 0 )
				return;
			}
			val = images[i]
			$("#slider").append('<a href="javascript:slide_to('+i+')" onfocus="blur()"><img src="" id="img_'+i+'"/></a>');
			$("#img_"+i).hide();
			$("#img_"+i).attr('src', 'thumb.php?'+val).load( function(){
				$("#img_"+i).fadeIn("fast");
				image_pos[  parseInt($(this).attr('id').split("_")[1])  ] = image_length_all;
				image_length_all += parseInt( $(this).width() ) + 12;
				if( i==3 ){
					slide_to( 0 )
				}
				slide_add(i+1)
			} );
		}
		
		function slide_back(){
			if( cur_slide_image <= 0 )return;
			slide_to( cur_slide_image-1 );
		}
		function slide_next(){
			if( cur_slide_image >= images.length-1 )return
			slide_to( cur_slide_image+1 );
		}
		
		function slide_page_back(){
			slide_page_by( -parseInt($("#slideshow").width()) );
		}
		function slide_page_next(){
			slide_page_by( parseInt($("#slideshow").width()) );
		}
		
		function slide_to( num ){
			if( (cur_slide_image - num) > 0 )
				slide_dir = 1;
			else
				slide_dir = -1
			cur_slide_image = num
			var wc = parseInt($("#slideshow").width())
			$("#slider > a > img").css('border','1px solid black')
			$("#img_"+num).css('border','1px solid white')
			
			var m = (wc/2) - image_pos[num];
			if( m > 0 )m = 0
			if( m < -(image_length_all-wc) )m = -(image_length_all-wc);
			$("#slider").animate({marginLeft: m+'px'}, 300 );
			if($.browser.msie){
				flipIe( )
			}else{
				flip( )
			}
		}

		function slide_page_by( amount ){
			var slider_pos = parseInt($("#slider").css('marginLeft'));
			var slider_div = parseInt($("#slideshow").width()) - image_length_all;

			var m = slider_pos - amount;
			if( m > 0 ){
				m = 0;
			}
			if( m < slider_div ){
				m = slider_div
			}			
			$("#slider").animate({marginLeft: m+"px"}, 300 );
		}

		function flipIe( ){
			hideMeta();
			img1.stop(1,0)
			img2.stop(1,0)
			if( img1.is(':visible') ){
				img1.animate({marginLeft:float*slide_dir},400,"swing",function(){
				img1.hide();
				img2.animate({marginLeft:(-float*slide_dir)},10)
				src = 'image.php?'+images[cur_slide_image];
				img_load.fadeIn("fast");
				img2.attr('src', src);
				img2.load(function(){
									img_load.fadeOut("fast",function(){
									img2.show().animate({marginLeft:0},400,"swing",function(){loadMeta()});
					})}) 
				});
			}else{
				img2.animate({marginLeft:float*slide_dir},400,"swing",function(){
				img2.hide();
				img1.animate({marginLeft:(-float*slide_dir)},10)
				src = 'image.php?'+images[cur_slide_image];
				img_load.fadeIn("fast");
				img1.attr('src', src);
				img1.load(function(){
									img_load.fadeOut("fast",function(){
									img1.show().animate({marginLeft:0},400,"swing",function(){loadMeta()});
					})})
				});
			}
		}
		
		function flip( ){
			hideMeta();
			img1.stop(1,0)
			img2.stop(1,0)
			if( img1.is(':visible') ){
				img1.animate({marginLeft:float*slide_dir,opacity:0},400,"swing",function(){
				img1.fadeOut();
				img2.animate({marginLeft:(-float*slide_dir)},10)
				src = 'image.php?'+images[cur_slide_image];
				img_load.fadeIn("fast");
				img2.attr('src', src);
				img2.load(function(){
									img_load.fadeOut("fast",function(){
									img2.fadeIn().animate({marginLeft:0,opacity:1},400,"swing",function(){loadMeta()});
								   })})
				});
			}else{
				img2.animate({marginLeft:float*slide_dir,opacity:0},400,"swing",function(){
				img2.fadeOut();
				img1.animate({marginLeft:(-float*slide_dir)},10)
				src = 'image.php?'+images[cur_slide_image];
				img_load.fadeIn("fast");
				img1.attr('src', src);
				img1.load(function(){
									img_load.fadeOut("fast",function(){
									img1.fadeIn().animate({marginLeft:0,opacity:1},400,"swing",function(){loadMeta()});
								   }) })
				});
			}
		}
		
		function hideMeta(){
			$('.image_title').fadeOut('fast').html();
			$('.image_desc').fadeOut('fast').html();
		}
		function loadMeta(){
			$.getJSON("ajax.php?"+images[cur_slide_image],function(data){
				var desc = '<p>'+data.medianame+'</p>'
				if(data.internal_notice.length > 2){
					desc += '<p><a href="'+data.internal_notice+'" target="_blank">einen Print dieses Bildes kaufen</a></p>';
				}
				$('.image_desc').html(desc).fadeIn()
			});
		}
		
		
