var h,w,pad, wi, nextHeight,reloadformobile,reloadforscreen,proscreenw,next,myhash;
var ieold,mobile,opera,norez=false;
var activeslide =1;
var first = true;

var ua = $.browser; if( ua.msie && ua.version.slice(0,1) < "9" ) {ieold = true;}
var mo = navigator.userAgent.toLowerCase();if(mo.indexOf("mobile") != -1){mobile=true;}

function Scrollto(that, speed){
		// jQuery SmoothScroll | Version 10-04-30
		var duration = (speed == "fast") ? 0 : 600;
		var easing='swing';
		var newHash=that.hash;
		if((newHash.indexOf("#top") != -1 )&&(mobile==true)){
			target=$(that.hash).offset().top+1;
		}else{
			 target=$(that.hash).offset().top;
		}
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=that;
		// make sure it's the same location
		if (location.pathname.replace(/^\//,'') == that.pathname.replace(/^\//,'') && location.hostname == that.hostname) {
			// animate to target and set the hash to the window.location after the animation
			inScroll = true;
			$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
				// add new hash to the browser location
				window.location.href=newLocation;
				inScroll = false;
				});
			// cancel default click action
		return false;
		}
}
function rrandom(min,max){return (min>max)?-1:((min==max)?min:(min+parseInt(Math.random()*(max-min+1))));}
function picShuffle(){	
	var z = $('.images').length;
	for(i=0;i<=z;i++){
		if(w>=650){var height2 = rrandom(0,200);var height3 = rrandom(0,250);}else{var height2 = rrandom(0,100);var height3 = rrandom(0,150);}
		if(w>=1100){var left2 = rrandom(280,320);}else{var left2 = rrandom(100,150);}
		if(w>=1100){var left3 = rrandom(480,520);}else{var left3 = rrandom(200,250);}
		$(".images:eq("+i+") .probild2").css({"top":""+height2+"px","left":""+left2+"px"});
		$(".images:eq("+i+") .probild3").css({"top":""+height3+"px","left":""+left3+"px"});
		}
}
function mysize(){
w = $(window).width();wi = $("body").innerWidth();h = $(window).height();		
	if(w>650){	
		if(reloadforscreen){console.log("reloadforscreen");var c=new Date().getTime();$("body").fadeOut();window.location.href  = "index.html?c="+c+window.location.hash;}
		reloadformobile = true;
		reloadforscreen = false;
	
		$('#wrapper').css({"width":""+w+"px","height":""+5*h+"px"});
		$('.screen').css({"width":""+w+"px","height":""+h+"px"});
		$('#home').css({"position":"absolute", "height":""+2*h+"px","top":""+2*h+"px"});
		$('#projects').css({"position":"absolute","top":""+4*h+"px","width":""+w+"px"});
		$('#proscreen').css({"width":""+w+"px"});
		$('#about').css({"position":"absolute","top":"0px","height":""+2*h+"px" });
		$('.pro-screen').css({"width":""+proscreenw+"px" });
			
		var verticalmiddleproscreen = (h-$("#proscreen").height())/2+30;if(verticalmiddleproscreen < 100){verticalmiddleproscreen=100;}$("#proscreen").css({"top":""+verticalmiddleproscreen+"px","background":"none"});
		var verticalmiddleaboutcontent = (h-$(".aboutcontent").height())/2+30;if(verticalmiddleaboutcontent < 100){verticalmiddleaboutcontent=100;}$(".aboutcontent").css({"top":""+verticalmiddleaboutcontent+"px","background":"none"});
		var verticalmiddleh2 = (h-$("#title").height())/2;if(verticalmiddleh2 < 100){verticalmiddleh2=100;}$("#title").css({"top":""+verticalmiddleh2+"px","background":"none"});
		
		$('#wrapper').off();$("#proscreen").on();
		
		if(w>=1100){pad=(w-1000)/2;$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});$("#home, #projects, #about").fadeIn();}
		else{pad=(w-600)/2;$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});$("#home, #projects, #about").fadeIn();}
	}else{
		if(reloadformobile){console.log("reloadformobile");var c=new Date().getTime();$("body").fadeOut();window.location.href  = "index.html?c="+c+window.location.hash;}
		reloadformobile = false;
		reloadforscreen = true;
		
		$('#wrapper').css({"position":"absolute","width":""+w+"px","height":"auto","top":"0"});
		$('.screen').css({"position":"absolute","width":""+w+"px","height":"auto","top":"0"});
		$('#home').css({"position":"absolute", "height":"auto","top":"0","width":""+w+"px"});
		$('#projects').css({"position":"absolute","top":"0","width":""+w+"px"});
		$('#about').css({"position":"absolute","top":"0px","height":"auto","width":""+w+"px" });
		pad=w/10;
		$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});
		$("#proscreen").off();$("#wrapper").on();
	}
}
$(document).ready(function() {	
	
	w = $(window).width();
	if(w>650){reloadformobile = true;reloadforscreen = false;}else{reloadformobile = false;reloadforscreen = true;}
	//if(mobile){window.scrollTo(0,1);}
	$("#wrapper").fadeIn();
	$("body").fadeIn();
	mysize();picShuffle();
	
	
	if(ieold){window.status="Ihr Browser ist veraltet! Um diese Seite im Originalzustand zu erleben aktualisieren Sie bitte Ihre Software!";var tit = document.title;document.title = "Bitte aktualisieren Sie Ihren Browser! "+tit;}
if(w>=650){
		
		$('#wrapper').off();$('#proscreen').on();
	
		if(!window.location.hash){window.location = window.location + "#home";var startpos = new Number(2*h);scrollTo(0,startpos);}
	
		$('.scroller a').click(function() {Scrollto(this,"slow");return false;});
		$('.ab').click(function(){$("#about").animate({"top":"0"});ab=true;});
		$('.abtop').click(function(){$("#about").animate({"top":"-"+h+"px"});ab=false;});

		$('#proscreen').cycle({
			timeout: 0,
			fx: 'scrollHorz',
			next: '.next',
			prev: '.prev',
			speed: 900,
			width: function(){
				w = $(window).width();
				proscreenw = 1.33*w;
				return proscreenw;
				},
			animOut: {opacity: 0}, 
    		animIn: {opacity: 1},
    		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
    				w = $(window).width();
					proscreenw = 1.33*w;
        			$(".pro-screen").width(""+proscreenw+"px");
        			if(w>=1100){
						pad=(w-1000)/2;
						$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});
					}else{
						pad=(w-600)/2;
						$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});
						}
        			},
    		after: function(currSlideElement, nextSlideElement, options, forwardFlag){
        			$(".pro-screen").width(""+proscreenw+"px");
        			if(w>=1100){
						pad=(w-1000)/2;
						$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});
					}else{
						pad=(w-600)/2;
						$('.pro-screen').css({"padding":"0 "+pad+"px 0 "+pad+"px"});
						}
        			}
		}); 
	if(!mobile){
	$(".n").mouseover(function(){
		var text = $(this).attr("id");var pos = $(this).offset();
		$("body").append("<div id='tooltip'><div id='up'></div><span class='tip'>"+text+"</span></div>");
		
		if($(this).hasClass("top")){
			$("#tooltip").css({
			"position":"absolute",
			"top": (pos.top + $(this).height() + 8) + "px",
			"right": $(window).width() - (pos.left + $(this).width()) + "px"});
			$("#tooltip").addClass("r");
			
			$("#tooltip #up").css({
				"margin-left": $(".tip").width() - 7 +"px"
			});
		}else{
			$("#tooltip").css({
			"position":"absolute",
			"top": (pos.top + $(this).height() + 8) + "px",
			"left": (pos.left) + "px"});
		}
		$("#tooltip").delay(1000).fadeOut(400);
	});
		$(".n").mouseout(function(){var text = false;var pos = false;$("#tooltip").remove();});
	}else{
	$(".n").css({
		"width":"120px",
		"text-indent":"0",
		"font-family": "'M1pthin', sans-serif",
		"font-size":"10pt",
		"color":"#fff",
		"text-decoration":"none",
		"background":"none",
		"padding-top":"5px"
		});
	$(".n.next").css({
		"width":"80px",
		"text-indent":"0",
		"font-family": "'M1pthin', sans-serif",
		"font-size":"10pt",
		"color":"#fff",
		"text-decoration":"none",
		"background":"none",
		"padding-top":"5px"
		});
	$(".n.top").css({
		"width":"70px",
		"text-indent":"0",
		"font-family": "'M1pthin', sans-serif",
		"font-size":"10pt",
		"color":"#fff",
		"text-decoration":"none",
		"background":"none",
		"padding-top":"5px"
		});	
	$(".n.abtop").css({
		"width":"80px",
		"text-indent":"0",
		"font-family": "'M1pthin', sans-serif",
		"font-size":"10pt",
		"color":"#000",
		"text-decoration":"none",
		"background":"none !important",
		"padding-top":"5px"
		});
		
	}
}else{
	$("#proscreen").off();$('#wrapper').on();
	//if((mobile)&&(mo.indexOf("android") == -1)){
	//	$("#wrapper").css({"overflow":"scroll !important"});
	//}
	$('#wrapper').cycle({
				fx: 'scrollHorz',
				pager: '#pager',
				width: "100%",
				timeout: 0,
				startingSlide: activeslide,
				speed: "slow",
				pagerAnchorBuilder: function(idx, slide) { 
        				// return selector string for existing anchor
        				return '#pager a:eq(' + idx + ')'; 
        			},
        		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
        				$("#wrapper, body").height(0);
        				var nextEle = nextSlideElement.id;
        				
        				//h = $(window).height();
        				$("#"+nextEle+"").css({"display":"block"});
        				$("#formail").css({"min-height":""+h+""});
						nextHeight = ($("#"+nextEle+"").outerHeight())*1.01;
						//console.log(nextHeight);
        				//$("#wrapper").height(nextHeight+"px");
        				$("#wrapper").css({"height":""+nextHeight+"px !important","padding-bottom":"50px"});
        				$("body").css({"height":""+nextHeight+"px !important","padding-bottom":"50px"});
        				scrollTo(0,1);
        				
        			},
        		after: 	function(currSlideElement, nextSlideElement, options, forwardFlag){
        				$(".screen").width("100%");
        				//scrollTo(0,1);
        				//var thisEle = nextSlideElement.id;
        				//h = $(window).height();
        				//thisHeight = $("#"+thisEle+"").height();
        				//$("#wrapper").height(thisHeight+"px");
        				//$("#wrapper").css({"top":"56px"});
        			}
		});
	if(first){$("#pagernavi a.tohome").addClass("active");first = false;}
	$('#pagernavi a.toinfo').click(function() { $('#pager a:eq(0)').trigger('click'); activeslide = 0;$("#pagernavi a").removeClass("active");$(this).addClass("active");return false; }); 
	$('#pagernavi a.topro').click(function() { $('#pager a:eq(2)').trigger('click'); activeslide = 2;$("#pagernavi a").removeClass("active");$(this).addClass("active");return false; });
	$('#pagernavi a.tohome').click(function() { $('#pager a:eq(1)').trigger('click'); activeslide = 1;$("#pagernavi a").removeClass("active");$(this).addClass("active");return false; });
	$('.contactform input, .contactform textarea').focus(function() {norez = true;});
	$('.contactform input').blur(function() {norez = false;});	
	$(".uplink").click(function(){scrollTo(0,1); return false;});
}
});

$(window).resize(function() {if(!norez){mysize();picShuffle();if(w>=650){mysize();picShuffle();Scrollto(window.location,"fast");}}else{return false;}});

