    
    $.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
	return $.getUrlVars()[name];
	
  }
});
	
		//Adjust image size
		
		
		vertical_center=1;
		
	function resizeBackground() {
			ID = "#dynBg";
			
			startheight = $("#fmPage #Hintergrundbild img").attr("height");
			startwidth = $("#fmPage #Hintergrundbild img").attr("width");
			
			//Define image ratio
			var ratio = startheight/startwidth;
			
			
			//Gather browser and current image size
			var imagewidth = $(ID+" img").width();
			var imageheight = $(ID+" img").height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			var offset;
			

			//Resize image to proper ratio
			if ((browserheight/browserwidth) > ratio){
			    $(ID+" img").height(browserheight);
			    $(ID+" img").width(browserheight / ratio);
				if (vertical_center == 1){
					$(ID+" img").css('left', (browserwidth - (browserheight / ratio))/2);
					$(ID+" img").css('top', (browserheight - browserheight)/2);
				}
				
			} else {
			    $(ID+" img").width(browserwidth);
			    $(ID+" img").height(browserwidth * ratio);
				if (vertical_center == 1){
					$(ID+" img").css('left', (browserwidth - browserwidth)/2);
					$(ID+" img").css('top', (browserheight - (browserwidth * ratio))/2);
				}
			}
	};

	
	
	timeoutID = -1;
	gCount = -1;	
	showingTime = 5000;
	loadStr = "";
	stay=false;
	superstay=false;
	window.onresize = resizeBackground;
	$(window).load(function () {
		setGCountbyRefferer()
		buildPNavi();
		loadContent();
	$('#content').fadeIn();
	$('#Galerien').fadeIn();
		$('#Galerien').bind("mouseenter", function(event){stay=true;stopTimedLoading();});
		$('#Galerien').bind("mouseleave", function(event){stay=false;startTimedLoading();});
		$('#contentframe').bind("mouseenter", function(event){stay=true;stopTimedLoading();});
		$('#contentframe').bind("mouseleave", function(event){stay=false;startTimedLoading();});
		
		$('#loading').bind("click", function(event){stay=true;stopTimedLoading();});
		$('#stop').bind("click", function(event){stay=false;startTimedLoading();});
		$('.sitenavi a').bind("click", function(event){showPage(this);return false;});
	
		
$('#gFrame').load(function(){$('#galerie').fadeIn();});
		$('#dynBg img').load(function(){if(stay==false){$('#loading').animate({opacity: 0.25}, 50)}else{$('#loading').animate({opacity: 0}, 500);$('#stop').fadeIn();};resizeBackground();$('#dynBg').fadeIn();startTimedLoading();})
		$("#fmPage").ajaxComplete(function() {
										   
			$("#dynBg img").attr("src",$("#fmPage #Hintergrundbild img").attr("src"));
			$("#Galerien").html("");
//			$('#Galerien').css("visibility","hidden");	
			$("#fmPage #Media .galerie").each(function(){
				$("#Galerien").html($("#Galerien").html()+'<span class="galerie" onMouseUp="Javascript:superstay=true;stopTimedLoading();"><a href="'+
									$(this).children("a").attr("href")+'" target="gFrame"><img src="'+
									$(this).children("img").attr("src")+'" width="131" height="157"/></a><div class="weText">'+
									$(this).children("a").text()+'</div></span>');   

			});
			$("#fmPage #Media .video").each(function(){
				$("#Galerien").html($("#Galerien").html()+'<span class="video"><a href="'+
									$(this).children("a").attr("href")+'" target="_blank"><img src="'+
									$(this).children("img").attr("src")+'" width="131" height="157"/></a><div class="weText">'+
									$(this).children("a").text()+'</div></span>');  
			});
			$("#Galerien").html($("#Galerien").html()+'<div id="weTCon"><div class="Titel">'+$("#fmPage #Titel").text()+'</div>'+
														'<div class="KurzInfoText">'+$("#fmPage #KurzInfoText").text()+'</div>'+
														'<div class="KurzInfoLink">'+$("#fmPage #KurzInfoLink").html()+'</div>'+
														'</div>')
//			$('#Galerien img').load(function(){$('#Galerien').css("visibility","visible");})	
			$("#dynBg img").attr("src",$("#fmPage #Media galerie").attr("src"));
		});

	});
	
	
	
	function setGCountbyRefferer(){
		var project = $.getUrlVar('project');
		for(i=0;i<$("#pageslist a").length;i++) {
			if (project == $("#pageslist a:eq("+i+")").attr("href")) {
				gCount = i-1;
				break;
			}
		}
		
	}
	
	function loadContentbyIndex(indexNum) {
		 gCount=Number(indexNum);
		 gCount--;
		 loadContent();
		}
	
	function loadContent() {
		gCount++;
		if (gCount >= $("#pageslist a").length) {
			gCount = 0;
		}
		$("#pnavi .prj").each(function(){$(this).animate({opacity:0.3},500);});
		$($("#pnavi .prj").get(gCount)).animate({opacity:1},500);
		loadStr = $("#pageslist a:eq("+gCount+")").attr("href");
		$('#fmPage').load(loadStr+" #fmContent");
		$('#loading').animate({opacity: 1}, 500);
		$('#stop').fadeOut();
	}
	
	function stopTimedLoading() {
			if (timeoutID != -1) {
				window.clearTimeout(timeoutID);
			}
			$('#loading').animate({opacity: 0}, 500);
			$('#stop').fadeIn();
	}
		
	function startTimedLoading() {
		if(stay==false && superstay==false) {
			$('#stop').fadeOut();
			$('#loading').animate({opacity: 0.25}, 500);
			if (timeoutID != -1) {
				window.clearTimeout(timeoutID);
			}
			timeoutID = window.setTimeout(loadContent, showingTime);
		} else {
			if (timeoutID != -1) {
				window.clearTimeout(timeoutID);
			}
		}
	}
	
	function buildPNavi() {
		$("#pnavi").append("Projekte :")
		$("#pageslist a").each(function(){$("#pnavi").append('<div class="prj"></div>')});
		$("#pnavi .prj").animate({opacity:0.3},500);
		$("#pnavi .prj").bind("click",function(event){loadContentbyIndex($(this).index());});
	}
	
	var tbPage = "";
	
	function showPage(evObj) {
		if (tbPage != $(evObj).attr("href")) {
				tbPage = $(evObj).attr("href");
				$('#textboxContainerInner').load(tbPage + " #textbox");
				$("#textboxContainerInner").ajaxComplete(function(e, xhr, settings) {
					 if (tbPage == settings.url) {
						$("#textboxContainer").fadeIn();								
					 }
				});
		} else {
			hideshowPage(evObj);
		}
		
	}

	function hideshowPage() {
			if ($("#textboxContainer").css("display") == "none") {
				$("#textboxContainer").fadeIn();			
			} else {
				$("#textboxContainer").fadeOut();					
			}	
	}
	
	
	
