if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelectorAll('meta[name="viewport"]')[0];
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
document.body.addEventListener('gesturestart', function() {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}

// Plugins

// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || [];   // store logs to an array for reference
log.history.push(arguments);
arguments.callee = arguments.callee.caller; 
if(this.console) console.log( Array.prototype.slice.call(arguments) );
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info, log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

// jQuery/helper plugins

/*!
 * HTML5 Placeholder jQuery Plugin v1.8.2
 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
 * @author Mathias Bynens <http://mathiasbynens.be/>
 */
 
;(function($) {

	var isInputSupported = 'placeholder' in document.createElement('input'),
	    isTextareaSupported = 'placeholder' in document.createElement('textarea');
	if (isInputSupported && isTextareaSupported) {
		$.fn.placeholder = function() {
			return this;
		};
		$.fn.placeholder.input = $.fn.placeholder.textarea = true;
	} else {
		$.fn.placeholder = function() {
			return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
				.bind('focus.placeholder', clearPlaceholder)
				.bind('blur.placeholder', setPlaceholder)
			.trigger('blur.placeholder').end();
		};
		$.fn.placeholder.input = isInputSupported;
		$.fn.placeholder.textarea = isTextareaSupported;
	}

	function args(elem) {
		// Return an object of element attributes
		var newAttrs = {},
		    rinlinejQuery = /^jQuery\d+$/;
		$.each(elem.attributes, function(i, attr) {
			if (attr.specified && !rinlinejQuery.test(attr.name)) {
				newAttrs[attr.name] = attr.value;
			}
		});
		return newAttrs;
	}

	function clearPlaceholder() {
		var $input = $(this);
		if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) {
			if ($input.data('placeholder-password')) {
				$input.hide().next().attr('id', $input.removeAttr('id').data('placeholder-id')).show().focus();
			} else {
				$input.val('').removeClass('placeholder');
			}
		}
	}

	function setPlaceholder(elem) {
		var $replacement,
		    $input = $(this),
		    $origInput = $input,
		    id = this.id;
		if ($input.val() === '') {
			if ($input.is(':password')) {
				if (!$input.data('placeholder-textinput')) {
					try {
						$replacement = $input.clone().attr({ type: 'text' });
					} catch(e) {
						$replacement = $('<input>').attr($.extend(args(this), { type: 'text' }));
					}
					$replacement
						.removeAttr('name')
						// We could just use the `.data(obj)` syntax here, but that wouldn’t work in pre-1.4.3 jQueries
						.data('placeholder-password', true)
						.data('placeholder-id', id)
						.bind('focus.placeholder', clearPlaceholder);
					$input
						.data('placeholder-textinput', $replacement)
						.data('placeholder-id', id)
						.before($replacement);
				}
				$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
			}
			$input.addClass('placeholder').val($input.attr('placeholder'));
		} else {
			$input.removeClass('placeholder');
		}
	}

	$(function() {
		// Look for forms
		$('form').bind('submit.placeholder', function() {
			// Clear the placeholder values so they don’t get submitted
			var $inputs = $('.placeholder', this).each(clearPlaceholder);
			setTimeout(function() {
				$inputs.each(setPlaceholder);
			}, 10);
		});
	});

	// Clear placeholder values upon page reload
	$(window).bind('unload.placeholder', function() {
		$('.placeholder').val('');
	});



	$('#container').css('min-height', ($(window).height() - 80) + 'px');
	
	
	if ($(window).width() <= 480) {
		$('#hauptnavigation').hide();
	}

	$(window).resize(function(){
		$('#container').css('min-height', ($(window).height() - 80) + 'px');

		if (($(window).width() <= 480) && (! $('#hauptnavigation').hasClass('isvisible') )) {
			$('#hauptnavigation').hide();
		} else {
			$('#hauptnavigation').show();
		}
	});

	$("a[href='#hauptnavigation']").click(function(e) {
		if (($(window).width() <= 480) && (!$('#hauptnavigation').hasClass('isvisible'))) {
			$('#hauptnavigation').show('slow').addClass('isvisible');
		} else if (($(window).width() < 480) && ($('#hauptnavigation').hasClass('isvisible'))) {
			$('#hauptnavigation').hide('slow').removeClass('isvisible');
		} else {
			return true;
		}
		return false;
	});


	if($('a[rel="gallery"]').length>0) {
		if($('html').is('.ie7, .ie8')) {
			$("section[role='main']>article, section[role='main']>section, section.teaser>div>article, section.teaser>div>section, aside[role='complementary']>article, aside[role='complementary']>section").not('.teaser').each(function() {
				$(this).find('a[rel="gallery"]').colorbox({
					innerWidth: '600px',
					maxWidth: '90%', 
					maxHeight: '90%',
					current: "Bild {current} von {total}",
					previous: "Vorheriges",
					next: "Nächstes",
					close: "Schließen",
					slideshowStart: "Start Slideshow",
					slideshowStop: "Stop Slideshow"
				})
			});
		} else {
			$("section[role='main']>article, section[role='main']>section, section.teaser>div>article, section.teaser>div>section, aside[role='complementary']>article, aside[role='complementary']>section").not('.teaser').each(function() {
				$(this).find('a[rel="gallery"]').colorbox({
					maxWidth: '90%', 
					maxHeight: '90%',
					current: "Bild {current} von {total}",
					previous: "Vorheriges",
					next: "Nächstes",
					close: "Schließen",
					slideshowStart: "Start Slideshow",
					slideshowStop: "Stop Slideshow"
				})
			});
		}
	}

	/* $('head').append('<link rel="stylesheet" href="http://nachhaltigeswebdesign.de/uni-due/css/scratch.css" type="text/css" />');*/



	if (location.pathname!='/') {
		$('#mainnav a[href$="' + location.pathname + location.search + '"]').addClass('current');
	}

	$("a img").parent().addClass('containsimage');

}(jQuery));

// self executing function to avoid global namespace conflicts
(function($) {
  /*--------------------------------------------------------------------------------------
    fadeIn() and fadeTo(speed, 1) now removes filter attribute in IE to resolve
    clearType issues in IE6 and IE7. Addresses tickets #2457, #3230, #4779 and others.
    source: http://ralphholzmann.com/2010/01/fadein_and_jquery-goodness/
  ---------------------------------------------------------------------------------------*/
  
  var _fadeIn = $.fn.fadeIn;
  var _fadeTo = $.fn.fadeTo;

  $.fn.fadeIn = function(easing, callback) {
      return _fadeIn.call(this, easing, function(){
          if( jQuery.browser.msie ) this.style.removeAttribute('filter');
          if( $.isFunction(callback) ) callback.call(this);
      });
  }
  
  $.fn.fadeTo = function(speed, to, callback) {
    return _fadeTo.call(this, speed, to, function() {
      if( jQuery.browser.msie && to == 1 ) this.style.removeAttribute('filter');
      if( $.isFunction(callback) ) callback.call(this);
    });
  }
  
  /*-------------------------------------------------------------
    The DOM is ready ... yeah!
  -------------------------------------------------------------*/
  
  jQuery(function() {
    // Set defaults for all datepickers 
    if ( $.datepicker ) {
      $.datepicker.setDefaults($.datepicker.regional['de']);
    }
    
    /*-------------------------------------
      Examples
    -------------------------------------*/
    
    // enhance all forms in the content for now
    $('#container form').enhanceForm();


    $('#ui-datepicker-div').css('clip', 'auto'); 
  });
})(jQuery);

