var ek_images = new Array();
var ekJSVer = 30092011;

function arrayShuffle(){
  var tmp, rand;
  for(var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i]; 
    this[i] = this[rand]; 
    this[rand] =tmp;
  }
}

Array.prototype.shuffle = arrayShuffle;

$(document).ready(function() {
	$("noscript").remove();
	
	$(".tagcloud").children("a").each(function($p_idx){
		if ( $p_idx % 2 ) $(this).addClass("tag-odd");
	});
	
	$(".navigator").fadeTo(1000,1).fadeTo(300,0.2);
	$(".navigator").mouseenter(ek2_fadein_page);
	$(".navigator").mouseleave(ek2_fadeout_page);
	$(".navigator > a").click(ek2_hide);

	for (i=1;i<ek_images.length;i++) {
		var img = new Image();
		img.idx = i;
		$(img).hide().attr("id","album"+i).addClass("caching");
		$("#loading"+i+">a").append(img);
		$(img).bind("load",{idx: i},function(){
			var delayMultiplier = 0;
			$(this).removeClass("caching").addClass("cached");
			if ( $(".caching").get().length == 0 ) {
				$(".loading").each(function(){
					$(this).removeClass("loading").addClass("imgcontainer")
					.find(".cached").each(function(){
						$(this).fadeIn(100*(delayMultiplier++)).fadeTo(500,0.5).mouseenter(ek2_fadein).mouseleave(ek2_fadeout);
					});
				});
				$(".navigator").fadeTo(100,1).fadeTo(1000,0.5);
			}
		})
		.attr("src",ek_images[i]);
		$("#loading"+i+">.inpic-info").remove().appendTo($("#loading"+i+">a"));
	}
	
	// Timeout, falls nicht alle Bilder (schnell genug) geladen werden
	setTimeout(function(){
		if ( $("img.caching").get().length ) {
			$("img.cached").fadeIn(300).fadeTo(1000,0.5).mouseenter(ek2_fadein).mouseleave(ek2_fadeout).parent().parent().removeClass("loading").addClass("imgcontainer");
			$("img.caching").unbind("load").load(function(){
				$(this).removeClass("caching").fadeIn(300).fadeTo(1000,0.5).mouseenter(ek2_fadein).mouseleave(ek2_fadeout).parent().parent().removeClass("loading").addClass("imgcontainer");
			});
		}
	},5000);
	
	$("span#thumbnails").click(function(){
		var div = $("div#thumbs-wrapper");
		if ( div.is(":visible") ) {
			div.hide();
		} else {
			div.fadeIn();
		}
	  return false;
	});
	
	$("#showhidemenu").click(function(){
		$("#sidebar-container").slideToggle();
		return false;
	});
});

function ek_loadimage(p_href, p_title, p_i, p_src) {
	document.write('<a class="album_link" href="'+p_href+'" rel="bookmark" title="'+p_title+'"></a>');
	ek_images[p_i] = p_src;
}

function ek_facebook() {
	document.write('<fb:like layout="standard" show_faces="false" colorscheme="dark"></fb:like>');
}

function ek2_fadein() {
	if ( $(this).is(":animated") ) {
		$(this).stop().fadeTo(100,1);
	} else {
		$(this).fadeTo(100, 1);
	}
}

function ek2_fadein_page() {
	if ( $(this).is(":animated") ) {
		$(this).stop().fadeTo(100,1);
	} else {
		$(this).fadeTo(100, 1);
	}
}

function ek2_fadeout() {
	$(this).fadeTo("slow", 0.5);
}

function ek2_fadeout_page() {
	if ( $(this).is(":animated") ) {
		$(this).stop().fadeTo("slow",0.5);
	} else {
		$(this).fadeTo("slow", 0.5);
	}
}

function ek2_hide($object) {
	$(".album_link > img").unbind("mouseenter",ek2_fadein);
	$(".album_link > img").unbind("mouseleave",ek2_fadeout);
	$(".navigator").unbind("mouseenter",ek2_fadein_page);
	$(".navigator").unbind("mouseleave",ek2_fadeout_page);
	var delay = 50;
	$(".album_link > img").each(function(){
		$(this).fadeTo(delay+=50,0);
	});
	var x = $(this).attr("href");
	$(".navigator_bottom").fadeTo(delay,0, function(){document.location.href=x;});
	return false;
}

document.write("<style type=\"text/css\">\n.preloading {\nfilter:Alpha(opacity=0);opacity: 0.0;\n}\n</style>");

