// Javascript file
// Export for additional javascript code 

// Bugfix for Safari Viewport Scaling Bug
(function(doc) {

	var addEvent = 'addEventListener',
	    type = 'gesturestart',
	    qsa = 'querySelectorAll',
	    scales = [1, 1],
	    meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];

	function fix() {
		meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
		doc.removeEventListener(type, fix, true);
	}

	if ((meta = meta[meta.length - 1]) && addEvent in doc) {
		fix();
		scales = [.25, 1.6];
		doc[addEvent](type, fix, true);
	}

}(document));

// Load and configure flex slider
$(window).load(function() {
   $('.flexslider').flexslider({
     animation: "slide",
     slideshow: false,
	 slideshowSpeed: 7000,
	 animationDuration: 750,
	 directionNav: true,
	 controlNav: true,
	 keyboardNav: false,
	 touchSwipe: true,
	 prevText: "Zurück",
	 nextText: "Weiter",
	 randomize: false,
	 slideToStart: 0,
	 pauseOnAction: true,
	 pauseOnHover: false,
	 controlsContainer: ".flex-container"
   });
});

// select focussed input fields & textareas
$(document).ready(function() {   
     $("input, textarea").click(function() {
      // only select if the text has not changed
      if(this.value == this.defaultValue)
      {
        this.select();
      }
     })
});

// Implement smooth scrolling
$(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 500);
                return false;
            }
        }
    });
});
