$(document).ready(function() {
	if(!((document.cookie.indexOf("stopMobileRedirect=true") < 0) 
		&& /(Android|iPhone|iPod|webOS|SymbianOS)/.test(navigator.userAgent))) {
			var max_count = 15;
			var loaded = max_count;
			var scale = function(){
				loaded--;
				console.log(loaded);
				var width = this.width;
				var height = this.height;
				if(width && height){
					this.style.marginLeft = "-10px";
					this.style.marginTop = "-10px";				
					if(width>height){
						this.style.width = "420px";
						if(height/width*420<380){
							this.style.width = "auto";
							this.style.height = "415px";
							this.style.marginLeft = -Math.ceil((width*(height/415)-420)/2)+"px";
						} else {
							this.style.marginTop = -Math.ceil((height*(420/width)-420)/2)+"px";
						}
					} else {
		
					}
				}
				if(loaded==0){
					$('#slideshow').slideshow({width: 400, height: 390});
					$('#slideshow>a').click(function(e){
						return false;
					});
					setTimeout(function(){$('#slideshow img').css('visibility','visible');$('#slideshow').css("background","#000");},1000);
					
				}
			}
			$.ajax({ 	url: "http://www.fusion-festival.de/fileadmin/fusionfestival/x/scripts/flickr/?per_page=10&jsoncallback=?", 
						dataType: 'json',
						cache: true,
						jsonpCallbackString : 'homeslides',
						success: function(data){
							$.each(data.results, function(i,item){
								if(i<=max_count){
									var slide = 
									$("<img style='visibility:hidden'/>").attr("src", item.src).load(scale)
									.appendTo("#slideshow")
									.wrap("<a target='_blank' href='" + item.link + "'></a>");
								}
							});
						}
			});
		}
});

