	EXref="";
	top.document.referrer?EXref=top.document.referrer:EXref=document.referrer;
	var currentpage=new Array();
	var currentset=null;
//	var pages=null;
	var loadedImgs=new Array();
	var currentheight=0;
	var subfolder="";
$(function() {

	var padding=0;
	var addmargin=45;
	var maxPictureHeight=1000;
	var maxSelectorHeight=130;
	var minSelectorHeight=40;
	var picdescriptionheight=52;
	var maxPageHeight = maxPictureHeight+(padding*2)+$(".picdescription").height()+maxSelectorHeight;
	var minPageHeight = $("#menu").height();
	var menuwidth = $("#menu").width()+12; //margin vom Menu
	var aspectratio = 1.8;
//	var descriptionFontSizes=Array(9,10,11,12,13,14,15,16);
	var descriptionFontSizes=Array(9,10,10,10);
	//animation
	var ease=400;
	var hover=250;
	var fade=500;
	var slide=500;
	var picfadeOut=600;
	var picfade=600;
	var sliderStep=5;
	var sliderPos=0;
	var slideropacity=0.5;
	var useTracker=true;
	var trackPage=false;


	/*initial stuff*/
	var pagereq=null;
	var pagedim=new Array();
	var newsletterCnt="";
	var contactCnt="";
	var clientsCnt="";
	var setsCnt;
	var sliderCanvasLeftOffset=-400;

	if($("#subfolder").length>0) subfolder=$("#subfolder").html();
	if($.client.os=="Mac" && $.client.browser=="Firefox") $(".loadset").css("line-height","14px");
	resize($(window).width(), $(window).height(), true);
	track("home");
	$(".loadset").each(function() {
		$(this).css("width",Math.ceil($(this).width())+1);
		$(this).data("iniwidth",$(this).width()+0);
	});
	$(".menusets").hide();
	$(".menulinks").hide();
	$("#menu > h1").after("<div id='menuwait'><img style='margin: 50px 50px 10px 50px;' src='"+$("#metahttpbase").attr("content")+"images/clock.gif' alt='' /><br />loading, please wait</div>");

	$("#menuwait").show();
	$(".loadset").css("opacity",1);

	function loadData() {
		$.post(window.location.href,
			{
				ajaxrequest: "getAllData",
				sliderheight: $("#slidercanvas").height()
			}, function(result) {
				clientsCnt=result["clients"];
				contactCnt=result["contact"];
				newsletterCnt=result["newsletter"];
				setsCnt=result["pics"];
				$("#menuwait").remove();
				$(".menusets").fadeIn(fade);
				$(".menulinks").fadeIn(fade);
	//			if(usePreloader) loadImage(null,true);
			},"json"
		)
	}

	$("#slidercanvasOpaq").css("opacity",slideropacity);
	$("#slidercanvasOpaq").mouseenter(function() {
		$(this).stop().animate({"opacity": 1},hover);
	});
	$("#slidercanvasOpaq").mouseleave(function() {
		$(this).stop().animate({"opacity": slideropacity},hover);
	});

	$("#sl_loadnext").click(function() {
//		currentpage++;
		sliderPos=sliderPos+sliderStep;
		slideTo();
//		loadPage();
	});
	$("#sl_loadprev").click(function() {
//		currentpage--;
		sliderPos=sliderPos-sliderStep;
		slideTo();
//		loadPage();
	});
	$("#sl_loadnext").mouseenter(function() {
		$("#slidercanvasOpaq").stop().animate({"opacity": 1},hover);
	});
	$("#sl_loadnext").mouseleave(function() {
		$("#slidercanvasOpaq").stop().animate({"opacity": slideropacity},hover);
	});
	$("#sl_loadprev").mouseenter(function() {
		$("#slidercanvasOpaq").stop().animate({"opacity": 1},hover);
	});
	$("#sl_loadprev").mouseleave(function() {
		$("#slidercanvasOpaq").stop().animate({"opacity": slideropacity},hover);
	});


	$(".loadset").mouseover(function() {
		if(!$(this).hasClass("active")) {
			$(this).stop().animate({"background-color": "#9a6d01"},hover);
		}
	});
	$(".loadset").mouseout(function() {
		if(!$(this).hasClass("active")) {
			$(this).stop().animate({"background-color": "#000000"},hover);
		}
	});
	$(".inverse").mouseover(function() {
		$(this).stop().animate({"background-color": "#9a6d01"},hover);
	});
	$(".inverse").mouseout(function() {
		if($(this).hasClass("active")) return;
		$(this).stop().animate({"background-color": "#000000"},hover);
	});
	$(".loadclients").mouseover(function() {
		$(this).stop().animate({"color": "#9a6d01"},hover);
	});
	$(".loadclients").mouseout(function() {
		if($(this).hasClass("active")) return;
		$(this).stop().animate({"color": "#000000"},hover);
	});
	$(".loadcontact").mouseover(function() {
		$(this).stop().animate({"color": "#9a6d01"},hover);
	});
	$(".loadcontact").mouseout(function() {
		if($(this).hasClass("active")) return;
		$(this).stop().animate({"color": "#000000"},hover);
	});
	$(".loadnewsletter").click(function(event) {
		event.preventDefault();
		unloadSlider();
		if($(this).hasClass("active")) return;
		$(".othermenu").each(function() {
			if($(this).data("old_bgcol")!=null) $(this).animate({"background-color": $(this).data("old_bgcol")});
			if($(this).data("old_col")!=null) $(this).animate({"color": $(this).data("old_col")});
			$(this).removeClass("active");
		});
		klappin();
		$(this).data("old_bgcol", "#000000");
		$(this).data("old_col", "#ffffff");
		$(this).stop().animate({"background-color": "#9a6d01"},hover);
		$(this).addClass("active");

		$(".slider").fadeOut(fade,function() {$(this).remove();});
		$(".picdescription").fadeOut(fade,function() {$(this).remove();});
		$(".page").fadeOut(fade,function() {
			var page=$(this);
			var width="";
			var height="";
			if(page.css("min-width")=="0px") width=page.css("width");
			else width=page.css("min-width");
			if(page.css("min-height")=="0px") width=page.css("height");
			else width=page.css("min-height");
			$(".page").remove();
			$("#content").append("<div id='browncanvas' class='page' style='display: none; width:630px; min-height:"+height+";'></div>");
			$("#browncanvas").append(newsletterCnt);
			$("#newslettercanvas").css("top", Math.floor($(".loadcontact").position().top-$("#content").position().top)+"px");
			$("#browncanvas").fadeIn(fade);
			$("#nl_submit").click(function(event) {
				event.preventDefault();
				$.post(window.location.href,
					{
						ajaxrequest: "newsletterSubscription",
						name: $("#nl_name").attr("value"),
						mail: $("#nl_mail").attr("value"),
						subscribe: $("#nl_subscribe").attr("checked"),
						unsubscribe: $("#nl_unsubscribe").attr("checked")
					}, function(result) {
						if(result=="noname") $("#newsletterresult").html("PLEASE ENTER NAME AND VALID EMAIL ADDRESS");
						if(result=="nomail") $("#newsletterresult").html("PLEASE ENTER NAME AND VALID EMAIL ADDRESS");
						if(result=="noaction") $("#newsletterresult").html("PLEASE CHOOSE SUBSCRIBE OR UNSUBSCRIBE");
						if(result=="subscribe") $("#newsletterresult").html("YOU'VE SUCCESSFULLY SUBSCRIBED TO ALEX TREBUS NEWS.");
						if(result=="unsubscribe") $("#newsletterresult").html("YOU'VE SUCCESSFULLY UNSUBSCRIBED FROM ALEX TREBUS NEWS.");
					}
				)
			});
		});
		track("nl");
	});

	$(".loadclients").click(function(event) {
		event.preventDefault();
		unloadSlider();
		if($(this).hasClass("active")) return;
		$(".othermenu").each(function() {
			if($(this).data("old_bgcol")!=null) $(this).animate({"background-color": $(this).data("old_bgcol")});
			if($(this).data("old_col")!=null) $(this).animate({"color": $(this).data("old_col")});
			$(this).removeClass("active");
		});
		klappin();
		$(this).data("old_col", "#000000");
		$(this).stop().animate({"color": "#9a6d01"},hover);
		$(this).addClass("active");

		$(".slider").fadeOut(fade,function() {$(this).remove();});
		$(".picdescription").fadeOut(fade,function() {$(this).remove();});
		$(".page").fadeOut(fade,function() {
			var page=$(this);
			var width="";
			var height="";
			if(page.css("min-width")=="0px") width=page.css("width");
			else width=page.css("min-width");
			if(page.css("min-height")=="0px") width=page.css("height");
			else width=page.css("min-height");
			$(".page").remove();
			$(".picdescription").remove();
			$("#content").append("<div id='browncanvas' class='page' style='display: none;'></div>");
//			makePageDim();
			$("#browncanvas").append(clientsCnt);
			$("#browncanvas").fadeIn(fade);
		});
		track("cli");
	});

	$(".loadcontact").click(function(event) {
		event.preventDefault();
		unloadSlider();
		if($(this).hasClass("active")) return;
		$(".othermenu").each(function() {
			if($(this).data("old_bgcol")!=null) $(this).animate({"background-color": $(this).data("old_bgcol")});
			if($(this).data("old_col")!=null) $(this).animate({"color": $(this).data("old_col")});
			$(this).removeClass("active");
		});
		klappin();
		$(this).data("old_col", "#000000");
		$(this).stop().animate({"color": "#9a6d01"},hover);
		$(this).addClass("active");

		$(".slider").fadeOut(fade,function() {$(this).remove();});
		$(".picdescription").fadeOut(fade,function() {$(this).remove();});
		$(".page").fadeOut(fade,function() {
			$(".page").remove();
			$("#content").append("<div id='browncanvas' class='page' style='display: none;'></div>");
			makePageDim();
			$("#browncanvas").append(contactCnt);
//					resize($(window).width(), $(window).height());
			$("#browncanvas").fadeIn(fade);
		});
		track("con");
	});



	$(".loadset").click(function(event) {
		event.preventDefault();
		if($(this).hasClass("active")) return;
		$(this).stop().animate({"background-color": "#9a6d01"},hover);
		$(".othermenu").each(function() {
			if($(this).data("old_bgcol")!=null) $(this).animate({"background-color": $(this).data("old_bgcol")});
			if($(this).data("old_col")!=null) $(this).animate({"color": $(this).data("old_col")});
			$(this).removeClass("active");
		});
		var cur=$(this).attr("id");
		$(".navlink").remove();
		klappin(cur);
		$(this).addClass("active");
//		$(this).animate({"width": $(this).width()+39+"px"},ease,"easeOutBounce", function() {
		$(this).animate({"padding-right": "0px", "width": $(this).width()+39+"px"},ease,"easeOutBounce", function() {
			$(this).append("<a class='right navlink nextpic' href='#'><img src='"+$("#metahttpbase").attr("content")+"images/right.gif' alt='' /></a>");
			$(this).append("<a class='right navlink prevpic' href='#'><img src='"+$("#metahttpbase").attr("content")+"images/left.gif' alt='' /></a>");
			$(".navlink").fadeIn(ease);
			$(".nextpic").click(function() {
				currentpage[currentset]++;
				slideToCurrentPage();
				loadPage();
			});
			$(".prevpic").click(function() {
				currentpage[currentset]--;
				slideToCurrentPage();
				loadPage();
			});
		});
		currentset=$(this).attr("id").substr(7);
		if(!currentpage[currentset]) currentpage[currentset]=1;
		loadPage();
		loadSlider();
		track("p"+currentset);
	});

	$(".othermenu").click(function(event) {
		if($(this).hasClass("doLink")) {
			return true;
		}
		event.preventDefault();
		if($(this).hasClass("active")) return;
		$(".othermenu").each(function() {
			if($(this).data("old_bgcol")!=null) $(this).animate({"background-color": $(this).data("old_bgcol")});
		});
		var cur=$(this).attr("id");
//		if($(this).data("old_bgcol")==null) $(this).data("old_bgcol",$(this).css("background-color"));
//		$(this).animate({"background-color": "#9a6d01"});
	});


	function loadPage() {
		if(setsCnt==null) return;
		if(currentpage[currentset]>setsCnt[currentset].length) currentpage=1;
		if(currentpage[currentset]<1) currentpage[currentset]=setsCnt[currentset].length;
		$("#pagepos"+currentset).html(currentpage[currentset]+"/"+setsCnt[currentset].length);
		var newHtml="";
		for(var i=0; i<setsCnt[currentset][(currentpage[currentset]-1)].length; i++) {
			newHtml+="<div class='image'>";
			newHtml+=setsCnt[currentset][(currentpage[currentset]-1)][i]["imgtag"];
			newHtml+="</div>";
			//console.log(pages[(currentpage-1)][i]);
		}
		$(".page").addClass("page_old");
		$(".page_old").removeClass("page");
		$(".image").addClass("image_old");
		$(".image_old").removeClass("image");
		$(".picdescription").addClass("picdescription_old");
		$(".picdescription_old").removeClass("picdescription");
		var page=$(".page_old");
		$(".picdescription_old").fadeOut(picfadeOut,function() {
			$(this).remove();
		});
$("#prevNextPaneCanvas").remove();
$("#content").append("<div class='page' style='display: none;'></div><div id='prevNextPaneCanvas'><div id='prevPicPane'>&nbsp;</div><div id='nextPicPane'>&nbsp;</div></div>");
$(".page").html(newHtml);
for(var i=0; i<setsCnt[currentset][(currentpage[currentset]-1)].length; i++) {
	if($(".image").length==0) break;
	var picdesc=setsCnt[currentset][(currentpage[currentset]-1)][i]["desctag"];
//	console.log(picdesc);
	$("#content").append(picdesc);
	$(".picdescription").hide();
	//$("#d"+pages[(currentpage-1)][i]["id"]).css("width",width);
	//console.log(pages[(currentpage-1)][i]);
}
resize($(window).width(), $(window).height());
		page.fadeOut(picfadeOut,function() {
			$(".page_old").remove();
//			$("#prevNextPaneCanvas").remove();
//			$("#content").append("<div class='page' style='display: none;'></div><div id='prevNextPaneCanvas'><div id='prevPicPane'>&nbsp;</div><div id='nextPicPane'>&nbsp;</div></div>");
//			$(".page").html(newHtml);
//			for(var i=0; i<setsCnt[currentset][(currentpage[currentset]-1)].length; i++) {
//				if($(".image").length==0) break;
//				var picdesc=setsCnt[currentset][(currentpage[currentset]-1)][i]["desctag"];
//				$("#content").append(picdesc);
//				//$("#d"+pages[(currentpage-1)][i]["id"]).css("width",width);
//				//console.log(pages[(currentpage-1)][i]);
//			}
//			resize($(window).width(), $(window).height());
			$(".picdescription").fadeIn(picfade);
			$(".page").fadeIn(picfade);
			$("#nextPicPane").click(function() {
				currentpage[currentset]++;
				slideToCurrentPage();
				loadPage();
			});
			$("#prevPicPane").click(function() {
				currentpage[currentset]--;
				slideToCurrentPage();
				loadPage();
			});

		});
		if(trackPage) {
//			console.log("p"+currentset+"_"+currentpage[currentset]);
			track("p"+currentset+"x"+currentpage[currentset]);
		}
	}

	function unloadSlider() {
		$(".slider_btn").fadeOut(fade);
		$("#slidercanvas").children().fadeOut(fade, function() {$(this).remove();});
	}

	function loadSlider() {
		var html="";
		for(var i=0; i<setsCnt[currentset].length; i++) {
			html+="<div class='sliderpage page"+i+"'>";
			for(var j=0; j<setsCnt[currentset][i].length; j++) {
				var id=setsCnt[currentset][i][j]["id"];
				//erstelle Slider hier!
				html+=setsCnt[currentset][i][j]["imgslidertag"];
			}
			html+="</div>";
		}
		$("#slidercanvas").html("<div id='sliderwindow'></div><div id='slidercanvasInner'><span class='sl_current'>"+html+"</span></div>");
		var firstpic=$(".sl_current img:first").attr("class");
//		console.log(firstpic);
		var htmlwidth=0;
		$(".sliderpage").each(function() {
			htmlwidth+=$(this).width();
		});
		$("#sliderwindow").css({
			width: (($(".sliderpage:first-child").width()+2)+"px"),
			height: (($(".sliderpage:first-child").height()+2)+"px"),
			left: ((($("#slidercanvas").width()-2)/2)+"px")
		});

		var faktor=Math.ceil(($("#slidercanvas").width()+sliderCanvasLeftOffset) / htmlwidth);
		$("#slidercanvasInner").append("<span class='sl_next'>"+html+"</span>");
		$("#slidercanvasInner").prepend("<span class='sl_prev'>"+html+"</span>");
		for(var i=0; i<faktor; i++) {
			$("#slidercanvasInner").append("<span class='sl_other'>"+html+"</span>");
			$("#slidercanvasInner").prepend("<span class='sl_other'>"+html+"</span>");
		}
//		$("#slidercanvasInner").scrollTo($(".sl_current"),1000, function() {console.log("X");});
//		$("#slidercanvas").scrollTo($(".sl_current  ."+firstpic),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		slideToCurrentPage(true);
		$(".sliderpage").click(function() {
			var goPage=0;
			firstpic=$(this).children("img").first().attr("class");
			var classes=$(this).attr("class").split(" ");
			for(var c=0; c<classes.length; c++) {
				if(classes[c].substr(0,4)=="page") goPage= parseInt(classes[c].substr(4));
			}
			$("#slidercanvas").scrollTo($(this),slide,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			if($(this).parent().attr("class")!="sl_current") {
				$("#slidercanvas").scrollTo($(".sl_current  ."+firstpic),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			}
			currentpage[currentset]=goPage+1;
			sliderPos=currentpage[currentset];
//			slideToCurrentPage();
			loadPage();
//			console.log(sliderPos);
		});
		$(".slider_btn").fadeIn(fade);
	}

	function slideToCurrentPage(fast) {
		var slidespeed=slide;
		if(fast!=null) slidespeed=0;
		if(currentpage[currentset]>setsCnt[currentset].length) {
			currentpage[currentset]=1;
			$("#slidercanvas").scrollTo($(".sl_next  .page"+(currentpage[currentset]-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}, onAfter:function() {
					$("#slidercanvas").scrollTo($(".sl_current  .page"+(currentpage[currentset]-1)),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		}
		else if(currentpage[currentset]<1) {
			currentpage[currentset]=setsCnt[currentset].length;
			$("#slidercanvas").scrollTo($(".sl_prev  .page"+(currentpage[currentset]-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}, onAfter:function() {
					$("#slidercanvas").scrollTo($(".sl_current  .page"+(currentpage[currentset]-1)),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		}
		else $("#slidercanvas").scrollTo($(".sl_current  .page"+(currentpage[currentset]-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		sliderPos=currentpage[currentset];
//		console.log(sliderPos);
	}

	function slideTo(fast) {
		var slidespeed=slide;
		if(fast!=null) slidespeed=0;
		if(sliderPos>setsCnt[currentset].length) {
			sliderPos=sliderPos-setsCnt[currentset].length;
			$("#slidercanvas").scrollTo($(".sl_next  .page"+(sliderPos-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}, onAfter:function() {
					$("#slidercanvas").scrollTo($(".sl_current  .page"+(sliderPos-1)),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		}
		else if(sliderPos<1) {
			sliderPos=sliderPos+setsCnt[currentset].length;
			$("#slidercanvas").scrollTo($(".sl_prev  .page"+(sliderPos-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}, onAfter:function() {
					$("#slidercanvas").scrollTo($(".sl_current  .page"+(sliderPos-1)),0,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
			}});//,1000, {"axix":"x", "offset":{"left":"400"}});
		}
		else $("#slidercanvas").scrollTo($(".sl_current  .page"+(sliderPos-1)),slidespeed,{offset:{left:$("#slidercanvas").width()/(-2)}});//,1000, {"axix":"x", "offset":{"left":"400"}});
//		console.log(sliderPos);
	}

	function klappin(leaveout) {
		$(".loadset").each(function() {
			if($(this).attr("id")==leaveout) return;
			$(".navlink").fadeOut(ease,function(){
				$(this).remove();
			});
			$("#prevNextPaneCanvas").remove();
			$("#pagepos"+$(this).attr("id").substr(7)).html("&nbsp;");
			$(this).css("padding", "0 2px 0 2px");
			$(this).animate({"background-color":"#000000", "width": $(this).data("iniwidth")+"px"},ease,"easeOutBounce");
			$(this).removeClass("active");
		});
	}


	/*resizing stuff*/
	$(window).resize(function() {
		loadedImgs=new Array();
		currentheight=0;
		resize($(window).width(), $(window).height());
	});

	function makePageDim() {
		if(pagedim!=null) {
			$(".page").css({"height": pagedim["height"]+"px", "width": pagedim["width"]+"px"});
			$("#prevPicPane").css({"width":Math.floor((pagedim["width"]*0.50)-3)+"px", "float":"left"})
			$("#nextPicPane").css({"width":Math.floor((pagedim["width"]*0.50)-3)+"px", "float":"left"})
			$("#prevNextPaneCanvas").css({"height":Math.ceil(pagedim["height"])+"px"});
		}
	}

	function resize(width, height, ini) {
//console.log("begin resize");
//		if(ajaxcall) ajaxcall.abort();
		var destwidth=0;
		var destheight=0;
		//console.log("height: "+height+"\nwidth: "+width);
		var canvheight=height-maxSelectorHeight-picdescriptionheight-(padding*2);
		var canvwidth=width-menuwidth-(padding*2)-addmargin;
		if(canvheight > maxPictureHeight) canvheight=maxPictureHeight;
		if(canvheight < minPageHeight) canvheight=minPageHeight;
		if(canvwidth > maxPictureHeight*aspectratio) canvwidth=maxPictureHeight*aspectratio;
		if(canvwidth < minPageHeight*aspectratio) canvwidth=minPageHeight*aspectratio;
//		console.log("height: "+canvheight+"\nwidth: "+canvwidth);
		if(canvheight*aspectratio < canvwidth) {
			destheight=canvheight;
			destwidth=Math.ceil(canvheight*aspectratio);
		}
		else {
			destwidth=canvwidth;
			destheight=Math.ceil(canvwidth/aspectratio);
		}
		currentheight=destheight;
		pagedim["height"]=Math.ceil(destheight);
		pagedim["width"]=Math.ceil(destheight*aspectratio);
		$("#canvas").css({width: (destwidth+menuwidth+(padding*2))+"px"});
		$("#content").css({width: destwidth+(padding*2)+"px", height: destheight+(padding*2)+"px"}); //stimmt die breite wirklich?!
		//$(".page").css({height: destheight+"px", width: Math.ceil(destheight*aspectratio)+"px"});
		makePageDim();
		var imgCount=0;
		if(ini!=null) {
			imgCount=$(".image").length;
		}
//		$(".picdescription").css({width: Math.floor(destwidth/2)-padding+"px"});
		$(".imageloadover").remove();
		$(".image > img").each(function() {
			var img=$(this);
			var id=img.attr("id").substr(1);
			//console.log(loadedImgs[id]);

			if(img.data("curRequest")) img.data("curRequest").abort();
//			if(ajaxcall[img.attr("id")]) {
//				ajaxcall[img.attr("id")].abort();
//			}
			var dims=$(this).attr("class").substr(1).split("x");
			$(this).css({height: (Math.floor(destheight))+"px", width: (Math.floor(destheight/dims[0]*dims[1]))+"px"});
			$(this).css({"margin-top": Math.floor(dims[2]/dims[0]*destheight)+"px", "margin-right": Math.floor(dims[3]/dims[0]*destheight)+"px", "margin-bottom": Math.floor(dims[4]/dims[0]*destheight)+"px", "margin-left": Math.floor(dims[5]/dims[0]*destheight)+"px"});
			//picDescription
			var heightrange=maxPictureHeight-minPageHeight;
//			console.log(Math.floor(heightrange / (descriptionFontSizes.length)));
//			console.log(descriptionFontSizes);
			var fontsize=descriptionFontSizes[Math.floor((Math.floor(destheight)-minPageHeight)/Math.floor(heightrange / (descriptionFontSizes.length)))];
			var marginall=Math.floor(dims[3]/dims[0]*destheight)+Math.floor(dims[5]/dims[0]*destheight);
			$("#d"+id).css({"font-size": fontsize+"px", "width": Math.floor(destwidth/$(".picdescription").length)-padding-marginall+"px", "margin-right": Math.floor(dims[3]/dims[0]*destheight)+"px", "margin-left": Math.floor(dims[5]/dims[0]*destheight)+"px"});
			if(loadedImgs[id]) {
				img.replaceWith(loadedImgs[id]);
				return;
			}
//			ajaxcall[img.attr("id")]=$.post(
//			console.log(img.position());
			
//			img.after("<div id='"+id+"_over' class='imageloadover' style='width:"+img.css("width")+"; height:"+img.css("height")+"; top:"+img.position().top+"px; left:"+img.position().left+"px; margin-top: "+img.css("margin-top")+"; margin-bottom: "+img.css("margin-bottom")+"; margin-left: "+img.css("margin-left")+"; margin-right: "+img.css("margin-right")+";'><img style='padding-left:"+((parseInt(img.css("width"))-32)/2)+"px; padding-top:"+((parseInt(img.css("height"))-32)/2)+"px;' src='"+$("#metahttpbase").attr("content")+"images/clock.gif' alt='Bitte warten' /></div>");
//			img.after("<div id='"+id+"_over' class='imageloadover' style='width:"+img.css("width")+"; height:"+img.css("height")+"; top:"+(-1*parseInt(img.css("height")))+"px; margin-top: "+img.css("margin-top")+"; margin-bottom: "+img.css("margin-bottom")+"; margin-left: "+img.css("margin-left")+"; margin-right: "+img.css("margin-right")+";'><div style='position: relative; left:"+((parseInt(img.css("width"))-61)/2)+"px; top:"+(((parseInt(img.css("height"))-61)/3))+"px; width: 61px; height: 61px;'><img style='margin: 14px 0 0 14px;' src='"+$("#metahttpbase").attr("content")+"images/clock.gif' alt='Bitte warten' /></div></div>");
			img.after("<div id='"+id+"_over' class='imageloadover' style='width:"+img.css("width")+"; height:"+img.css("height")+"; position: absolute; left: 0; top: 0px; margin-top: "+img.css("margin-top")+"; margin-bottom: "+img.css("margin-bottom")+"; margin-left: "+img.css("margin-left")+"; margin-right: "+img.css("margin-right")+";'><div style='position: relative; left:"+((parseInt(img.css("width"))-61)/2)+"px; top:"+(((parseInt(img.css("height"))-61)/3))+"px; width: 61px; height: 61px;'><img style='margin: 14px 0 0 14px;' src='"+$("#metahttpbase").attr("content")+"images/clock.gif' alt='Bitte warten' /></div></div>");
			img.data("curRequest",$.post(
				window.location.href,
				{
					ajaxrequest: "getResizedPic",
					id: img.attr("id"),
					height: destheight
				}, function(result) {
					if(result==null) return;
					$("<img class='"+img.attr("class")+"' id='"+result["id"]+"' alt='' style='"+result["style"]+"' />").attr('src', result["path"]).load(function(){
//						console.log($(this).css("height"));
//						console.log(img.height());
						if($(this).css("height") == img.css("height")) {
							//Korrekt!!! => Replace
							img.replaceWith($(this));
							loadedImgs[id]=$(this);
						}
						$("#"+id+"_over").fadeOut(300,function() {$(this).remove();});
//console.log("end resize");
						imgCount--;
//						ajaxcall[img.attr("id")]=null;
						if(ini!=null && imgCount==0) {
							loadData();
						}
					});
				},"json"
			));
		});
	}

	function track(pid) {
		if(useTracker==false) return;
		if(subfolder.length>0) {
			pid=subfolder.substr(0, (7-pid.length))+"x"+pid;
		}
//		console.log(pid);
		EXs=screen;
		EXw=EXs.width;
		navigator.appName!="Netscape"?EXb=EXs.colorDepth:EXb=EXs.pixelDepth;
		navigator.javaEnabled()==1?EXjv="y":EXjv="n";
		EXd=document;
		EXw?"":EXw="na";
		EXb?"":EXb="na";
		location.protocol=="https:"?EXprot="https":EXprot="http";
		EXref?EXref=EXref:EXref=EXd.referrer;
		$("body").append("<img src='"+EXprot+"://nht-2.extreme-dm.com/n3.g?login=smiles78&amp;pid="+pid+"&amp;auto=y&amp;jv="+EXjv+"&amp;j=y&amp;srw="+EXw+"&amp;srb="+EXb+"&amp;l="+escape(EXref)+"' height='1' width='1' />");
	}

/*
	function resize(width, height) {
//		if(ajaxcall) ajaxcall.abort();
		var destwidth=0;
		var destheight=0;
		//console.log("height: "+height+"\nwidth: "+width);
		var canvheight=height-maxSelectorHeight-picdescriptionheight-(padding*2);
		var canvwidth=width-menuwidth-(padding*2)-addmargin;
		if(canvheight > maxPictureHeight) canvheight=maxPictureHeight;
		if(canvheight < minPageHeight) canvheight=minPageHeight;
		if(canvwidth > maxPictureHeight*aspectratio) canvwidth=maxPictureHeight*aspectratio;
		if(canvwidth < minPageHeight*aspectratio) canvwidth=minPageHeight*aspectratio;
//		console.log("height: "+canvheight+"\nwidth: "+canvwidth);
		if(canvheight*aspectratio < canvwidth) {
			destheight=canvheight;
			destwidth=Math.ceil(canvheight*aspectratio);
		}
		else {
			destwidth=canvwidth;
			destheight=Math.ceil(canvwidth/aspectratio);
		}
		currentheight=destheight;
		pagedim["height"]=Math.ceil(destheight);
		pagedim["width"]=Math.ceil(destheight*aspectratio);
		$("#canvas").css({width: (destwidth+menuwidth+(padding*2))+"px"});
		$("#content").css({width: destwidth+(padding*2)+"px", height: destheight+(padding*2)+"px"}); //stimmt die breite wirklich?!
		//$(".page").css({height: destheight+"px", width: Math.ceil(destheight*aspectratio)+"px"});
		makePageDim();
//		$(".picdescription").css({width: Math.floor(destwidth/2)-padding+"px"});
		$(".image > img").each(function() {
			var dims=$(this).attr("class").substr(1).split("x");
			$(this).css({height: (Math.floor(destheight))+"px", width: (Math.floor(destheight/dims[0]*dims[1]))+"px"});
			$(this).css({"margin-top": Math.floor(dims[2]/dims[0]*destheight)+"px", "margin-right": Math.floor(dims[3]/dims[0]*destheight)+"px", "margin-bottom": Math.floor(dims[4]/dims[0]*destheight)+"px", "margin-left": Math.floor(dims[5]/dims[0]*destheight)+"px"});
			loadImage($(this), destheight, destwidth);
		});
	}

	function loadImage(img, destheight, destwidth) {
		var id=img.attr("id").substr(1);
		//console.log(loadedImgs[id]);

		if(img.data("curRequest")) img.data("curRequest").abort();
//			if(ajaxcall[img.attr("id")]) {
//				ajaxcall[img.attr("id")].abort();
//			}
		//picDescription
		var dims=img.attr("class").substr(1).split("x");
		var heightrange=maxPictureHeight-minPageHeight;
//			console.log(Math.floor(heightrange / (descriptionFontSizes.length)));
//			console.log(descriptionFontSizes);
		var fontsize=descriptionFontSizes[Math.floor((Math.floor(destheight)-minPageHeight)/Math.floor(heightrange / (descriptionFontSizes.length)))];
		var marginall=Math.floor(dims[3]/dims[0]*destheight)+Math.floor(dims[5]/dims[0]*destheight);
//		console.log("Destwidth: "+destwidth+" --- "+Math.floor(destwidth/2)+" - "+padding+" - "+marginall);
		$("#d"+id).css({"font-size": fontsize+"px", "width": Math.floor(destwidth/$(".picdescription").length)-padding-marginall+"px", "margin-right": Math.floor(dims[3]/dims[0]*destheight)+"px", "margin-left": Math.floor(dims[5]/dims[0]*destheight)+"px"});
		if(loadedImgs[id]) {
			img.replaceWith(loadedImgs[id]);
			return;
		}
		img.data("curRequest",$.ajax({
			url: window.location.href,
			data: {
				ajaxrequest: "getResizedPic",
				id: img.attr("id"),
				height: destheight
			},
			success: function(result) {
				if(result==null) return;
//					for(var time=0; time<result["time"].length; time++) {
//						console.log(result["time"][time]);
//					}
				$("<img class='"+img.attr("class")+"' id='"+result["id"]+"' alt='' style='"+result["style"]+"' />").attr('src', result["path"]).load(function(){
//						console.log("Bild geladen");
//						console.log($(this).css("height"));
//						console.log(img.height());
//						console.log(img.css("height"));
					if($(this).css("height") == img.css("height")) {
						//Korrekt!!! => Replace
						//img.replaceWith($(this));
						loadedImgs[id]=$(this);
						if($("#"+result["id"]).length>0) {
							$("#"+result["id"]).replaceWith($(this));
						}
					}

//						ajaxcall[img.attr("id")]=null;
				});
			},
			dataType: "json",
			async: false,
			type: "POST"
		}));
	}
*/


	var currentThb=0;
	var folder=$("#thumbMaker").attr("class");
	$("#thumbMaker .mkthb").each(function() {
		$.ajax({
			url: window.location.href,
			data: {
				ajaxrequest: "generateThb",
				folder: folder,
				path: $(this).html()
			},
			success: function(result) {
				currentThb++;
				$("#currentThb").html(currentThb);
			},
			async: false,
			type: "POST"
		});
	});

	if($("#largeMaker").length > 0) {
		var height=$("#largeMaker").attr("class").substr(2);
		var currentLarge=0;
		$("#largeMaker .mklarge").each(function() {
			$.ajax({
				url: window.location.href,
				data: {
					ajaxrequest: "generateLargepics",
					folder: folder,
					height: height,
					path: $(this).html()
				},
				success: function(result) {
					currentLarge++;
					$("#currentLarge").html(currentLarge);
				},
				async: false,
				type: "POST"
			});
		});
	}

	$(".zipMaker").each(function() {
		var el=$(this);
		var set=el.attr("id").substr(3);
		$.ajax({
			url: window.location.href,
			data: {
				ajaxrequest: "generateZip",
				folder: folder,
				set: set
//				path: $(this).html()
			},
			success: function(result) {
				el.append(result);
//				$("#currentLarge").html(currentLarge);
			},
			async: false,
			type: "POST"
		});
	});
	
	$("#renewfinished").each(function() {
		$.ajax({
			url: window.location.href,
			data: {
				ajaxrequest: "setfinished"
			},
			success: function(result) {
				$("#renewfinished").html(result);
//				$("#currentLarge").html(currentLarge);
			},
			async: false,
			type: "POST"
		});
	});

});


(function() {

	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.userAgent,
				subString: "iPhone",
				identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};

	BrowserDetect.init();

	window.$.client = {os : BrowserDetect.OS, browser : BrowserDetect.browser};

})();
