/* Scrollen der gesamten Website zum jeweiligen container */

$(function() {
                $('.nav a').bind('click',function(event){
                    var $anchor = $(this);
                    
                    $('html, body').stop().animate({
                        scrollTop: $($anchor.attr('href')).offset().top
                    }, 800);
                    event.preventDefault();
                });
            });



/* Sliding Caption Start */

$(document).ready(function(){
	$('.boxgrid-1.captionfull-1').hover(function(){
		$(".cover-1", this).stop(true, true).fadeIn({queue:true,duration:300});
	}, function() {
		$(".cover-1", this).stop(true, true).fadeOut({queue:true,duration:300});  
	});
});

$(document).ready(function(){
	$('.boxgrid-2.captionfull-2').hover(function(){
		$(".cover-2", this).stop(true, true).fadeIn({queue:true,duration:300});
	}, function() {
		$(".cover-2", this).stop(true, true).fadeOut({queue:true,duration:300});
	});
});

/* Kontaktformular Pruefung */

function chkFormular() {
  if((document.getElementById('konform').mailer_name.value == "Name *") || (document.getElementById('konform').mailer_name.value == "")) {
    alert("Du hast deinen Namen vergessen!");
    document.getElementById('konform').mailer_name.focus();
    return false;
  }
  if((document.getElementById('konform').mailer_vorname.value == "Vorname *") || (document.getElementById('konform').mailer_vorname.value == "")) {
    alert("Du hast deinen Vornamen vergessen!");
    document.getElementById('konform').mailer_vorname.focus();
    return false;
  }
  if(document.getElementById('konform').mailer_email.value == "E-Mail *") {
    alert("Du hast deine E-Mail-Adresse vergessen!");
    document.getElementById('konform').mailer_email.focus();
    return false;
  }
  if(document.getElementById('konform').mailer_email.value.indexOf('@') == -1) {
    alert("Bitte eine korrekte E-Mail-Adresse eingeben!");
    document.getElementById('konform').mailer_email.focus();
    return false;
  }
  if((document.getElementById('konform').mailer_nachricht.value == "Liebe Tonmeisterei... *") || (document.getElementById('konform').mailer_anliegen.value == "")) {
    alert("Nix mitzuteilen?!");
    document.getElementById('konform').mailer_nachricht.focus();
    return false;
  }
}


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


$(function(){
	$(".impressum").hide();
	$('a.slideDownClick').bind('click',function(event){
                    $(".impressum").fadeIn(100);
					var $anchor = $(this);
                    
                    $('html, body').stop().animate({
                        scrollTop: $($anchor.attr('href')).offset().top
                    }, 500, "swing" );
                    event.preventDefault();
                });
	
	
	$("a.close").click(function (){
	$(".impressum").slideUp(500);});
});


function initialize() {
    var latlng = new google.maps.LatLng(53.142118,8.220778, 0.002542,0.009356);
    var myOptions = {
      zoom: 16,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.HYBRID
    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
	
var contentString = '<div>'+
    '<h1 style="margin: 0 0 20px 0;">Die Tonmeisterei</h1>'+
    '<div id="bodyContent">'+
    'Bleicherstr.11a<br />26122 Oldenburg'+
    '</div>';

var infowindow = new google.maps.InfoWindow({
    content: contentString,
	position: new google.maps.LatLng(53.142118,8.220700, 0.002542,0.009356),
	map: map
});



google.maps.event.addListener(map, 'click', function() {
  infowindow.open();
});
  
  }


/* Slideshow */ 

// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images

// mit license. paul irish & andre? hansson. 2010.

// callback function is passed the last image to load
//   as an argument, and the collection as `this`


// Added support for calling the callback on each image load event
// 

// 'fireOne' argument is optional, if set, will invoke the callback once for every
// image in the 'this' collection, thus making 'this' in the callback that element alone
// If it's not used, the callback will be invoked once all the images in the collection has
// been loaded. And 'this' will be the jQuery collection of the filtered 'img' elements.



$.fn.imagesLoaded = function(callback, fireOne) {
  var
    args = arguments,
    elems = this.filter('img'),
    elemsLen = elems.length - 1;
	  elems.bind('load', function(e) {
        if (fireOne) {
            !elemsLen-- && callback.call(elems, e);
        } else {
            callback.call(this, e);
        }
    }).each(function() {
        // cached images don't fire load sometimes, so we reset src.
        if (this.complete || this.complete === undefined){
            this.src = this.src;
        }
    });
}


$(document).ready(function(){
  var images = $(".header-fade-menue img");
  images.parent().addClass("loading");
  images.hide();
  images.imagesLoaded(function() {
		slideShow($(this),5000);
  },true);
});

$(document).ready(function(){
  var images = $(".header-fade-die_tonmeisterei img");
  images.parent().addClass("loading");
  images.hide();
  images.imagesLoaded(function() {
		slideShow($(this),5000);
  },true);
});

$(document).ready(function(){
  var images = $(".header-fade-technik img");
  images.parent().addClass("loading");
  images.hide();
  images.imagesLoaded(function() {
		slideShow($(this),5000);
  },true);
});


function slideShow(obj,speed) {
	if (!obj.length) return;
	if (obj.length <= 1) return;
	var array = [];
	var auto = true;
	var direction = "forward";
	var fn = {
		loop: function() {
			if (!auto) return;
			fn.blend();
			setTimeout(fn.loop, speed );
		},
		blend: function() {
			var current = obj.filter(".current").fadeOut("slow").removeClass("current");
			if (direction == "forward") current = (current.next().length) ? current.next() : obj.first();
			if (direction == "back") current = (current.prev().length) ? current.prev() : obj.last();
			current.fadeIn("slow").addClass("current");
		},
		getLargest: function(array){ 
			return Math.max.apply( Math, array ); 
		}
	}
	obj.hide();
	obj.each(function() {
		array.push($(this).height());
	});
	obj.parent().animate({height:fn.getLargest(array)},"fast");		
	obj.parent().removeClass("loading");
	obj.first().fadeIn("slow",function() {
		setTimeout(fn.loop, speed );
	}).addClass("current");

}



$(document).ready(function() {
	$("a.fancy").fancybox();	
});










