$(document).ready(
function()
{
		
		$("#content").css('height',$("#content").height()+$("#footer").height()+20);
		
		/* FX: $('body').height()
		   SA: $(document).height()
		*/
		



		/* FX */
		if (($("#content").height()+$("#header").height()+$("#footer").height()+20) < $("body").height()) {
			$("#footer").css('position','absolute');
			$("#footer").css('top',$(window).height()-$("#footer").height()-20);
			$("#footer").css('width','100%');
			$("#footer").css('left',0);
		} 
		
		/* Safari */
		if (($("#content").height()+$("#header").height()+$("#footer").height()+20) < $(document).height() && $("#footer").css('position') != 'absolute') {
			$("#footer").css('position','absolute');
			$("#footer").css('top',$("body").height()-$("#footer").height()-20);
			$("#footer").css('width','100%');
			$("#footer").css('left',0);
		}
		
		
		
		
		$("ul.leftmenue-services li").hover(function() {
			$(this).attr('class','hover');
		});
}
);

function makeNormal(what) {
	$(what).attr('class','');
}

/////////////////////////////////////////////////////////////////////////////////

jQuery.fn.lightBox = function(settings) {

	settings = jQuery.extend({

		album: 1,
		overlayBgColor:		'#000',
    overlayOpacity: 	0.8,
    imageLoading: 		'lightbox-ico-loading.gif',
    imageBtnClose: 		'lightbox-btn-close.gif',
		imageArray:			new Array,
		activeImage:		null,
		keyToClose:				'c',
		keyToPrev:				'p',
		keyToNext:				'n'
	},settings);

	var _$ = this;
	function _initialize() {
		_start($(this),_$);
		return false;
	}
	function _start(objectClicked,jQueryMatchedObject) {
		$('select, embed, object').hide();
		_markup_structure();
		var arrPageSizes = ___getPageSize();
		$('#jquery-overlay').css({ backgroundColor: settings.overlayBgColor, opacity: settings.overlayOpacity, width: arrPageSizes[0], height: arrPageSizes[1] }).fadeIn();
		settings.imageArray = [];
		imageNum = 0;

  if (settings.album == "0")
     {
      		settings.imageArray.push(new Array(objectClicked.attr('href'),objectClicked.attr('title')));

   }
   else
   {

  var albumdaten = $.ajax({
  url: "album2.php?pic="+objectClicked.attr('href'),
  async: false
 }).responseText;

var bilder =  albumdaten.split("|");

 for ($ai=0;$ai<bilder.length;$ai++)
     {
      var b2 =  bilder[$ai].split(";");
      settings.imageArray.push(new Array(""+b2[0],b2[1]));
     }

 }

while ( !settings.imageArray[imageNum][0].match(objectClicked.attr('href')) ) {
			imageNum++;
		}
		var arrPageScroll = ___getPageScroll();
		$('#jquery-lightbox').css({ top: arrPageScroll[1] + (arrPageSizes[3] / 10), left: arrPageScroll[0] }).show();
		_set_image_to_view(imageNum);
	};
	function _markup_structure() {
		$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>');
		$('#jquery-overlay,#jquery-lightbox').click(function() {
			_finish();
		}).hide();
		$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
			_finish();
			return false;
		});
	};
function _set_image_to_view(imageNum) {

		settings.activeImage = imageNum
		$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
		var objImagePreloader = new Image();
		objImagePreloader.onload = function() {
			$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
			_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
			objImagePreloader.onload=function(){};
		}
		objImagePreloader.src = settings.imageArray[settings.activeImage][0];
	};
	function _resize_container_image_box(intImageWidth,intImageHeight) {
		var intCurrentWidth = $('#lightbox-container-image-box').width();
		var intCurrentHeight = $('#lightbox-container-image-box').height();
		var intWidth = (intImageWidth + (10 * 2)); //
		var intHeight = (intImageHeight + (10 * 2)); //
		var intDiffW = intCurrentWidth - intWidth;
		var intDiffH = intCurrentHeight - intHeight;
		$('#lightbox-container-image-box').animate({height: intHeight },400,function() {
      }).animate({width: intWidth},400,function() { _show_image(); });

    if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
			if ( $.browser.msie ) {
				___pause(250);
			} else {
				___pause(100);
			}
		}
		$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight });
		$('#lightbox-container-image-data-box').css({ width: intImageWidth });
	};
	function _show_image() {
		$('#lightbox-loading').hide();
		$('#lightbox-image').fadeIn(function() {
			_show_image_data();
		});
		_preload_neighbor_images();
	};
function _show_image_data() {
		$('#lightbox-container-image-data-box').slideDown('fast');

		var weiter ="";
		var zurueck = "";
    if ( settings.activeImage != 0 )
       {var zurueck = '<a href="#" title="Voriges Bild (Pfeiltaste links)" id="zur">«</a>'}

    if ( settings.activeImage != ( settings.imageArray.length -1 ) )
       {var weiter = '<a href="#" title="Nächstes Bild (Pfeiltaste rechts)" id="wei">»</a>'}

		if ( settings.imageArray.length > 1 ) {
			$('#lightbox-image-details-currentNumber').html('Bild ' + ( settings.activeImage + 1 ) + ' von ' + settings.imageArray.length + ' | '+zurueck+ ' '+weiter).show();
		}

		if ( settings.imageArray[settings.activeImage][1] ) {
		$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show(function() { _update_nav(); });
		}

	};
	function _update_nav() {

    $('#lightbox-nav').show();
		if ( settings.activeImage != 0 ) {
			$('#lightbox-nav-btnPrev').unbind();
			$('#lightbox-nav-btnPrev').show().bind('click',function() {
				_set_image_to_view(settings.activeImage - 1);
        return false;
			});

			$('#zur').unbind();
			$('#zur').show().bind('click',function() {
				_set_image_to_view(settings.activeImage - 1);
        return false;
			});

		}
		if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
			$('#lightbox-nav-btnNext').unbind();
			$('#lightbox-nav-btnNext').show().bind('click',function() {
				_set_image_to_view(settings.activeImage + 1);
				return false;
			});

			$('#wei').unbind();
			$('#wei').show().bind('click',function() {
  			_set_image_to_view(settings.activeImage + 1);
				return false;
			});

		}
			_enable_keyboard_navigation();

	};


		function _enable_keyboard_navigation() {
			$(document).keydown(function(objEvent) {
				_keyboard_action(objEvent);
			});
		}

		function _disable_keyboard_navigation() {
			$(document).unbind();
		}

		function _keyboard_action(objEvent) {
			// To ie
			if ( objEvent == null ) {
				keycode = event.keyCode;
				escapeKey = 27;
			// To Mozilla
			} else {
				keycode = objEvent.keyCode;
				escapeKey = objEvent.DOM_VK_ESCAPE;
			}
			// Get the key in lower case form
			key = String.fromCharCode(keycode).toLowerCase();
			// Verify the keys to close the ligthBox
			if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
				_finish();
			}
			// Verify the key to show the previous image
			if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
				// If we´re not showing the first image, call the previous
				if ( settings.activeImage != 0 ) {
					settings.activeImage = settings.activeImage - 1;
					_set_image_to_view(settings.activeImage);
					_disable_keyboard_navigation();
				}
			}
			// Verify the key to show the next image
			if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
				// If we´re not showing the last image, call the next
				if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {
					settings.activeImage = settings.activeImage + 1;
					_set_image_to_view(settings.activeImage);
					_disable_keyboard_navigation();
				}
			}
		}

function _preload_neighbor_images() {
		if ( (settings.imageArray.length -1) > settings.activeImage ) {
			objNext = new Image();
			objNext.src = settings.imageArray[settings.activeImage + 1][0];
		}
		if ( settings.activeImage > 0 ) {
			objPrev = new Image();
			objPrev.src = settings.imageArray[settings.activeImage -1][0];
		}
	};
function _finish() {
		$('#jquery-lightbox').remove();
		$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
		$('select, embed, object').show();
	};
function ___pause(ms) {
		var date = new Date();
		curDate = null;
		do { var curDate = new Date(); }
		while ( curDate - date < ms);
	 };
function ___getPageSize() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		var scroll = ___getPageScroll();
    if ((pageHeight-scroll[1]) < 750){pageHeight = scroll[1] +750}

		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
		return arrayPageSize;
	};
function ___getPageScroll() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}
		arrayPageScroll = new Array(xScroll,yScroll)
		return arrayPageScroll;
	};
	return this.click(_initialize);
};


////////////////////////////////////////////////////////////////////////////////

$(document).ready(

function(){

////////////////////////////////////////////////////////////////////////////////


$('.galerie').lightBox();
$('.vorschau').lightBox({"album":"0"});


});

/////////////////////////////////////////////////////////////////////////////////


// jquery validate

$(document).ready( function() {


	function validateField(field) {
		var error = false;
    var fehlermeldung = "";
		// required fields
		if ($(field).attr("class").indexOf("required") != -1) {
			if (!$(field).val().length)
				error = true;
				fehlermeldung = "Bitte füllen Sie das Feld aus.";
		}
		// numeric fields
		if ($(field).attr("class").indexOf("numeric") != -1) {
			if (!/^[0-9]*$/.test($(field).val()))
				error = true;
				fehlermeldung = "Bitte geben Sie eine Zahl ein.";
		}
		// characters (letters)
		if ($(field).attr("class").indexOf("character") != -1) {
			if (!/^[a-zA-ZöÖäÄåÅ]*$/.test($(field).val()))
				error = true;
				fehlermeldung = "Bitte geben Sie nur Buchstaben ein";
		}
		// emails
		if ($(field).attr("class").indexOf("email") != -1) {
			if (!/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/.test($(field).val()))
				error = true;
				fehlermeldung = "Bitte geben Sie eine korrekte E-Mailadresse an.";
		}

    var fid = ("#f_"+$(field).attr("name"))

		if (error) {
			$(field).addClass("error");

  			$(fid).html(fehlermeldung)

		} else {
			$(field).removeClass("error");
			$(fid).html("")
		}

		return !error;
	}

	$("form").each( function() {
		// handle submissions without filling any field
		$(this).submit(function () {
			var validationError = false;
			// for each field test it
			$("input, select, textarea", this).each( function() {
				if ($(this).attr("class")) {
					if (!validateField(this))
						validationError = true;
				}
			});
			return !validationError;
		});

		// handle changes on the fly
		$("input, select, textarea", this).each( function() {
			if ($(this).attr("class")) {
				$(this).blur( function() { validateField(this) } );
    			}
		});

	$("input, select, textarea", this).each( function() {
			if ($(this).attr("class")) {


        $(this).after("<div class='fehlermeldung' id='f_"+this.getAttribute("name")+"'></div>")
        	}
		});

	});


});





