var cont_flicker;
var speed=200;


function flickerbgcol(obj,from,to){
	if(cont_flicker){
		obj.css("background-color",to);
		window.setTimeout(function(){flickerbgcol(obj,to,from)}, 50);
	} else {
		obj.css("background-color","");
	}
}

function getHeigth() {
	myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function presentelem(inhalt){
	var h=getHeigth();
	if(h<inhalt.height()+40){
		//inhalt.css("margin-bottom",getHeigth()-inhalt.height()+"px");
	} else {
		inhalt.css("height",getHeigth() -$(".line:first").height()*2 -30 +"px");
	}
	formattables(inhalt);
	insertPlayer(inhalt);
	insertMail(inhalt);
	
	var span=inhalt.prev().find(".static");
	span.addClass("normal");
	span.after('<span class="hover"><span class="links">&nbsp;</span>zur&uuml;ck</span>');
	
	cont_flicker=false;
	
	
		
	inhalt.slideDown(speed,function(){
		$.scrollTo( inhalt.parent(), speed, {offset:-3});
	});
}

function showelem(hash){
	//$.scrollTo( 150, 800);
	if(hash!="index.html" && hash!="" && $("[href="+hash+"]:first").length>0){
		var currlink=$('[href="'+hash+'"]:first');
		
		// verstecke die info und zeige neue info
		$(".container").find(".rechts").hide();
		currlink.find(".rechts").show();
		
		var href=currlink.attr("href");
		currlink.attr("name",href);
		currlink.attr("href","/");
		
		// verstecke andere inhalte
		$(".container").next("div").slideUp(speed,function(){
			$(this).remove("div");
		});
		
		// füge neuen inhalt ein
		currlink.after("<div style=\"display: none\">fdsa</div>");
		var inhalt=currlink.next();
		
		cont_flicker=true;
		flickerbgcol(currlink,"#999","#000","#000");
		inhalt.load(href+" .inhalt","",function(){
			$(this).find("img").preload({
				onFinish:function(){
					presentelem(inhalt);
				}
			});
		});
		
		$.address.title("Jan Hoeft - " + currlink.find(".titel").text());
	} else {
		cont_flicker=false;
		var currlink=$("[href='/']");
		
		currlink.each(function(){
			$(this).attr("href",$(this).attr("name"));
			
			$(this).find(".static").removeClass("normal");
			$(this).find(".hover").remove();
		});
		
		// meins ist ausgeklappt also versteck es
		currlink.find(".rechts").hide();
		currlink.next("div").slideUp(speed,function(){
			$.scrollTo( 0, speed+400);
			$(this).remove("div");
		});
		$.address.title("Jan Hoeft - Portfolio");
	};
};

$(document).ready(function(){
	$.address.change(function(event) {
		var href=event.value.substr(1,event.value.length);
		showelem(href);
	});
	 
	$(".container").each(function(){
		$(this).find(".rechts").hide();
		
		$(this).click(function(){
			var href=$(this).attr('href');
			$.address.value(href);
			return(false);
		});
	});
	
//	if(window.location.hash.length!=0){
//		showelem(window.location.hash.substr(1,window.location.hash.length));
//	}
});


