var MIN_HEIGHT = 800;
//var DELAY = 100;

var userAgent = navigator.userAgent.toLowerCase();
var Browser = {
	Version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
	Chrome: /chrome/.test(userAgent),
	Safari: /webkit/.test(userAgent),
	Opera: /opera/.test(userAgent),
	IE: /msie/.test(userAgent) && !/opera/.test(userAgent),
	Mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
	Check: function() { alert(userAgent); }
};

//if (Browser.Chrome || Browser.Safari) DELAY = 150;



function get(Element) 
{
	return document.getElementById(Element);	
}
function checkBrowserName(name){  
    var agent = navigator.userAgent.toLowerCase();  
    if (agent.indexOf(name.toLowerCase())>-1) {  
      return true;  
   }  
    return false;  
}  

function formatTitle(title,currentArray, currentIndex, currentOpts)  {
    return '<div id="image-title">' + title + '<br/><br/><div id="image-count">Bild <b>' + (currentIndex + 1) + '</b> von <b>' + currentArray.length + '</b></div></div>';
}

	var i = 0
function HomepageHeight(counter) {
	if (counter == null) counter = 0;
	//if (Browser.Chrome || Browser.Safari) window.setTimeout(SetHeight, 150);
	SetHeight();
	
	
	function SetHeight(){
		var PositionTop;
		var $Content = $('#Content');
		
		if ($('#Linkliste').size() > 0)
		{
			$Content = $('#Linkliste');
			PositionTop = parseInt($('#Linkliste').height() + $('#Linkliste').offset().top - 219);
		}
		else if ($('#Right-Col .ContentRahmen').size() > 0)
		{
			if ($Content.height() < MIN_HEIGHT && $('#SlideshowRahmen').size() == 0)
				$Content.css('height', MIN_HEIGHT + 'px');
				
			PositionTop = parseInt($('div#Right-Col div.ContentRahmen').height());
			if ($('#SlideshowRahmen').size() != 0) PositionTop += 550;
		}
		else PositionTop = parseInt($('div#Right-Col').height() - 63);
		
		if($('#like-button').css('top',(PositionTop + 132)+"px")){
			$('#like-button').removeClass('hidden');
		}
		$('#Left-Col').css('height', (PositionTop + 84) + 'px');
		
		//if (counter < 10) window.setTimeout(function(){HomepageHeight(counter+1)}, (counter+1) * 250);
	}
}

var slideIntervall;
function align_slide()
{
	var slideControlWidth = 0;
	
	$('div.slide-control div.nivo-controlNav a.nivo-control').each(function(i) {
		slideControlWidth += 25;
	});
	
	if (slideControlWidth > 0)
	{
		var slideLeft = 287.5 - (slideControlWidth/2);
		$('div.slide-control div.nivo-controlNav').css('margin-left', slideLeft + 'px');
		clearInterval(slideIntervall);
	}
}

function show_caption()
{
	$(this).find('.nivo-caption').fadeIn();
}

function hide_caption()
{
	$(this).find('.nivo-caption').fadeOut(1000);
}

$(window).load(function(){
	if(!$('#contact_form').length && !$('#impressum').length){
		HomepageHeight();
	}

})

$(document).ready(function(){
	//window.setTimeout(HomepageHeight, DELAY);
	HomepageHeight();
	slideIntervall = setInterval('align_slide()', 100);
	
	$(function() {
		$('ul#menu li img')
		.mouseover(function() {
			if ($(this).hasClass('act') === false)
			{
				var src = $(this).attr('src').match(/[^\.]+/) + '_act.png';
				$(this).attr('src', src);
				$('img#' + $(this).attr('id').replace('menu', 'icon')).show();
			}
		})
		.mouseout(function() {
			if ($(this).hasClass('act') === false)
			{
				var src = $(this).attr('src').replace('_act', '');
				$(this).attr('src', src);
				$('img#' + $(this).attr('id').replace('menu', 'icon')).hide();
			}
		});
	});
	
	
	$("a.fancybox").fancybox({
		'transitionIn'	:	EffektIN,
		'transitionOut'	:	EffektOUT,
		'speedIn'		:	600,
		'speedOut'		:	400,
		'titlePosition' :	TitlePosition,
		'overlayOpacity': 	0.5,
		'overlayColor'  :   '#000',
		'titleFormat'	:	formatTitle
	});
	
	$('.vorschaubild').hover(function(){$(this).css({ 
		'border': '2px solid #f29400' 
		});
	},function(){$(this).css({ 
		'border': '2px solid #c6c7c8' 
		});
	});
		
	//$('div#Slideshow').hoverIntent(show_caption, hide_caption);
	
	$('.album').hover(function(){
		$(this).find('img').css({
			'border'		: '2px solid #f29400'
		});
		$(this).find('.grey').css({
			'color'		   : '#f29400'
		});
		$(this).find('.change').css({
			'color'		   : '#f29400'
		});
	}, function(){ 
		$(this).find('img').css({
			'border'		   : '2px solid #c6c7c8'
		});
		$(this).find('.grey').css({
			'color'		   : '#58585a'
		});
		$(this).find('.change').css({
			'color'		   : '#000000'
		});
	});
	
	// PRELOAD NAVI BACKGROUND-IMAGES
	var preloadImages = ['menu_meine-person_act.png', 'menu_taetigkeiten_act.png', 'menu_familie_act.png', 'menu_galerie_act.png', 'menu_aktuelles_act.png'];
	for (var i = 0; i < preloadImages.length; i++) {
		$('<img style="display:none" src="images/' + preloadImages[i] + '" />').appendTo('body');
	}
	
	// Height Fix for Contact Form and Impressum
	if($('#contact_form').length || $('#impressum').length){
		PositionTop = parseInt($('#Left-Col').height());
		$('#like-button').css('top',(PositionTop - 90)+"px");
		$('#Left-Col').css('height', (PositionTop - 115) + 'px');
	
	}
	
	

		

	
});


// www.web-toolbox.net W. Jansen
//Captcha
var zufallszahl01;
var zufallszahl02;

function Schreiben01() {
var now = new Date();
var sec = now.getSeconds();
var min = now.getMinutes();
zufallszahl01 = sec % 10;
zufallszahl01 +=1;
zufallszahl02 = (min + sec) % 10;
zufallszahl02 +=1;
document.write("E-Mail-Spam-Schutz: " + zufallszahl01 + " + " + zufallszahl02 + " = ");
}

function Fragen01() {
document.write('<input class="kurz" onFocus="this.style.background=\'#FFFFFF\';" type="text" id="antwort01" maxlength="3" value=""> &nbsp;Bitte tragen Sie die richtige Summe ein.');
return
}

function Kontrolle01() {
var Ergebnis01 = zufallszahl01 + zufallszahl02;
var Eintrag01 = document.getElementById("antwort01").value;

  if(Ergebnis01 != Eintrag01)
  {
	  alert("CAPTCHA-Eintrag nicht korrekt!");
	  document.getElementById("antwort01").value = "";
	  document.getElementById("antwort01").focus();
	  return false;
  }
  else{
  	return true;
  }
}

/* Form Validation */
validate = new SimpleForm();
validate.setAttribute("attribute_validate","class");
validate.setAttribute("attribute_action","class");

function submitForm( form )
{
	validate.validate(form);
	//validate.postprocess(form);
	if(Kontrolle01()) document.getElementById("contact_form").submit();
}




