function scaleSite(what) {
	document.body.style.fontSize = what + "%";
	setCookie('scale',what);	
}

function contrast() {
	if (document.body.className != "contra"){
		document.body.className = "contra";
		setCookie('contrast','1');
	} 
	else{
		document.body.className = "";
		setCookie('contrast','0');	
	} 
}

function setCookie(name, value, expires, path, domain, secure){
	    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");	
}

function getCookie(name){
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
return(setStr);	
}

$(document).ready(function(){
    
  //$("input:not(.send), textarea").emptyonclick();
  
  $("#vorname, #name, #street, #zip, #city, #phone, #mobil, #email, #message, #recEmail, #sendName").focus(function(){
      if(typeof ($(this).attr('default')) == 'undefined' || $(this).val() == $(this).attr('default')){
          $(this).attr('default',$(this).val());
          $(this).val('');
      }
  }).blur(function(){
      var newValue = $(this).val();
      if (newValue == '') {
          var myVal = $(this).attr('default');
          $(this).val(myVal);
      }
  });
    
    
    
    
    
    
    var elementsClass = '#homeImage .active, .homeRight';
    checkEleHeight(elementsClass);

	var formWidthPX = $('#shader').css("width");
	var formHeightPX = $('#shader').css("height");
	var formWidth = formWidthPX.split('p');
	var formHeight = formHeightPX.split('p');

	var fweite = ((Fensterweite()/2)-(formWidth[0]/2));
	$.blockUI.defaults.css = {};
	$('#recommend').click(function(){
		$.blockUI({ message: $('#shader') });
		$('.blockMsg').css('left',fweite+"px");
	});
	
	$('#knopf').click(function(){
        var acUrl = location.href;
        var Ergebnis = acUrl.search(/index.php.+/);
	if (Ergebnis == -1){
	    acUrl = 'index.php?no_cache=1';
	}
        var postData = $('#formular form').serialize();
        $.get(acUrl +'&'+postData+'&no_cache=1');
		$('#formular').replaceWith($('#sent').html());
	});

    
    $('#favi').jFav();
    
    $(function() {
        setInterval( "slideSwitch()", 6000 );
    });

	if(getCookie('contrast') == '1'){
		contrast();
	}

	if(getCookie('scale') != ''){
		var what = getCookie('scale');
		scaleSite(what)
	}

   




});


function slideSwitch() {
    var $active = $('#homeImage IMG.active');

    if ( $active.length == 0 ) $active = $('#homeImage IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#homeImage IMG:first');

    $active.css({'z-index': 9})
        .addClass('last-active');

    $next.css({opacity: 0.0,'z-index': 10})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active').css('z-index','8');
        });
}




function closeMe() {
	$.unblockUI();
	location.reload();
}

function checkEleHeight(elementsClass){
    var largestElementHeight = 0;
    var elementHeight = 0;
    $.each( $(elementsClass), function(i, n){
        var elementHeight = $(n).height();
        if(elementHeight > largestElementHeight){
            largestElementHeight = $(n).height();
        }
    });  
		var em =  (largestElementHeight / 16);
		$('.homeRight').css("height",em+"em");
	    
}

function Fensterweite () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}


function Fensterhoehe () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}

