/* Author: 

*/

/*========== PAGE SCROLLING SCRIPT ==========*/
$(function(){

    $('a[rel=scroll]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            console.log($target);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            //Die Höhe der ausgeslideten Container, die beim Klick eingefahren werden muss noch abgezogen werden. Deshalb "- $('#news').height() - 10;" etc...
            
            if ($target.length) {
            if ($('#news').hasClass("expanded")){
            if(this.hash.slice(1) == 'agentur'){var targetOffset = $target.offset().top - $('#news').height() - 10;}else
            if(this.hash.slice(1) == 'referenzenanker'){var targetOffset = $target.offset().top - $('#news').height() - 10;} else 
            {var targetOffset = $target.offset().top;};
            }
            else if ($('.impressum').hasClass("expanded")){
                if(this.hash.slice(1) == 'agb'){var targetOffset = $target.offset().top - $('.impressum').height() - 10;} else
                if(this.hash.slice(1) == 'datenschutz'){var targetOffset = $target.offset().top - $('.impressum').height() - 10;} 
                else 
            	{var targetOffset = $target.offset().top;};
             }
            else if ($('.datenschutz').hasClass("expanded")){
                if(this.hash.slice(1) == 'agb'){var targetOffset = $target.offset().top - $('.impressum').height() - 10;}
                else 
            	{var targetOffset = $target.offset().top;};
             }              
            else {
                var targetOffset = $target.offset().top;
             }
                
                $('html,body').animate({scrollTop: targetOffset}, "slow");  
                return false;
                
            }
            
        }
        
    });
    
});

/*========== PAGE SCROLLING SCRIPT ENDE ==========*/
/*========== TOOLTIP SCRIPT ==========*/

$('.hastip').tooltipsy();

/*========== TOOLTIP SCRIPT ENDE ==========*/
/*========== BACK TO TOP SCRIPT ==========*/

//plugin - Nicht auf iphone/iPad/Android
if(!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))) {
jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min)
      {
        el.fadeIn(settings.fadeSpeed);
      }
      else
      {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};


//usage w/ smoothscroll
$(document).ready(function() {
  //set the link
  $('#top-link').topLink({
    min: 480,
    fadeSpeed: 500
  });
  //smoothscroll
  $('#top-link').click(function(e) {
  	$("#kontakt,#news,.impressum,.datenschutz,.agb").hide("slow");
  	$("#news,.datenschutz,.impressum").removeClass("expanded");
    e.preventDefault();
    $.scrollTo(0,300);
  });
});
}
/*========== BACK TO TOP SCRIPT ENDE ==========*/

/*========== SLIDER ==========*/

$(function(){
			// Set starting slide to 1
			var startSlide = 1;
			// Get slide number if it exists
			if (window.location.hash) {
				startSlide = window.location.hash.replace('#','');
			}
			// Initialize Slides
			$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				generatePagination: true,
				play: 0,
				pause: 5000,
				hoverPause: true,
				// Get the starting slide
				start: startSlide,
				animationComplete: function(current){
					// Set the slide number as a hash
					window.location.hash = '#' + current;
				}
			});
		});

$(function(){
			// Set starting slide to 1
			var startSlide = 1;
			// Get slide number if it exists
			if (window.location.hash) {
				startSlide = window.location.hash.replace('#','');
			}
			// Initialize Slides
			$('#slides2').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				generatePagination: true,
				play: 0,
				pause: 5000,
				hoverPause: true,
				// Get the starting slide
				start: startSlide,
				animationComplete: function(current){
					// Set the slide number as a hash
					window.location.hash = '#' + current;
				}
			});
		});
/*========== SLIDER ENDE ==========*/



/*========== NAVIGATION ==========*/

$(function() {
		$(".topMenuAction").click( function() {
			if ($("#openCloseIdentifier").is(":hidden")) {
				$("#slider").animate({ 
					marginLeft: "-106px"
					}, 500 );
				$("#topMenuImage").html('Menu');
				$("#openCloseIdentifier").show();
			} else {
				$("#slider").animate({ 
					marginLeft: "0px"
					}, 500 );
				$("#topMenuImage").html('Menu');
				$("#openCloseIdentifier").hide();
			}
		});  
	});
	
$(function() {
		$(".topMenuAction").mouseover( function() {
				if (!($('.topMenuAction').hasClass("hover"))){	
				$("#slider").animate({ 
					marginLeft: "0px"
					}, 500 );
				$("#navigation").animate({ 
					width: "165px"
					}, 500 );	
				$("#topMenuImage").html('Menu');
				$("#openCloseIdentifier").hide();
				setTimeout(function(){
     			$(".topMenuAction").addClass("hover");
				},600);
				//$(this).addClass("hover").wait(2000); 
				}
		});  
	});
	
	
	$(function() {
		$("#slider").mouseleave( function() {		
		if ($('.topMenuAction').hasClass("hover")){	
		//alert("blablub");
				hideslider()		
				}	
		});  
	});
	
	function hideslider(){
				$("#slider").animate({ 
					marginLeft: "-106px"
					}, 500 );
					$("#navigation").animate({ 
					width: "85px"
					}, 500 );
				$("#topMenuImage").html('Menu');
				$("#openCloseIdentifier").show();
				setTimeout(function(){
     			$(".topMenuAction").removeClass("hover");
				},600);
				
				
	};

/*========== NAVIGATION ENDE ==========*/

/*========== CONTENT FUNKTION ==========*/

$(function() {

      $(".cv-ruebner").click(function(event){
      	  $(".cv-ruebner").addClass("active");
      	  $(".cv-rath").removeClass("active");
      	  $(".cv-luethje").removeClass("active"); 
          $('.lebenslauf').load('data/cv-ruebner.html');
      });
		$(".cv-rath").click(function(event){
		  $(".cv-ruebner").removeClass("active");
      	  $(".cv-rath").addClass("active");
      	  $(".cv-luethje").removeClass("active");
          $('.lebenslauf').load('data/cv-rath.html');
      });
		$(".cv-luethje").click(function(event){
		  $(".cv-ruebner").removeClass("active");
      	  $(".cv-rath").removeClass("active");
      	  $(".cv-luethje").addClass("active");
          $('.lebenslauf').load('data/cv-luethje.html');
      });
			$(".moreNews").click(function(){
					$(".impressum,#kontakt,.datenschutz,.agb").hide("slow");
					$(".impressum,.datenschutz").removeClass("expanded");
					$("#news").slideToggle("slow");
					$("#news").toggleClass("expanded");
			});
			$(".moreKontakt").click(function(){
					$(".impressum,#news,.datenschutz,.agb").hide("slow");
					$(".impressum,.datenschutz,#news").removeClass("expanded");
					$("#kontakt").slideToggle("slow");		
			});
			$(".moreCv").click(function(){
					$("#cv").slideDown("slow");
			});
			$(".lessCv").click(function(){
					$("#cv").slideUp("slow");
			});
			$(".moreImpressum").click(function(){
					$("#kontakt,#news,.datenschutz,.agb").hide("slow");
					$("#news,.datenschutz").removeClass("expanded");
					$(".impressum").slideToggle("slow");
					$(".impressum").toggleClass("expanded");
			});
			$(".referenzen_link").click(function(){
					$("#news,#kontakt,.datenschutz,.impressum,.agb").hide("slow");
					$("#news,.datenschutz,.impressum").removeClass("expanded");
			});
			$(".agentur_link").click(function(){
					$("#kontakt,#news,.impressum,.datenschutz,.agb").hide("slow");
					$("#news,.impressum,.datenschutz").removeClass("expanded");
			});
			
			$(".moreDatenschutz").click(function(){
					$("#kontakt,#news,.impressum,.agb").hide("slow");
					$("#news,.impressum").removeClass("expanded");
					$(".datenschutz").slideToggle("slow");
					$(".datenschutz").toggleClass("expanded");

			});
			$(".moreAgb").click(function(){
					$("#kontakt,.datenschutz,#news,.impressum").hide("slow");
					$("#news,.datenschutz,.impressum").removeClass("expanded");
					$(".agb").slideToggle("slow");

			});
   });

/*========== CONTENT FUNKTION ENDE ==========*/

/*========== Abfrage nach dem Gerät =========*/
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/Android/i)))
		{
			$("#navigation").hide();
			$("a[rel=references]").click(function(){return false;});
		}
	if((navigator.userAgent.match(/iPad/i))) {$("#navigation").hide();}

	if(!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))) {
/*========== Zum Hovern der Lupe und die onclick-Funktion der Lupe ===================*/     
       	$('#slides .slide img').mouseover(function (){$('#lupe').fadeIn("fast");});
       	$('#lupe,.next,.prev').mouseover(function (){$('#lupe').addClass("hovered");});
       	$('#lupe,.next,.prev').mouseleave(function (){$('#lupe').removeClass("hovered");});
       	$('#slides .slide img').mouseleave(function (){setTimeout(function(){if(!$('#lupe').hasClass("hovered")){$('#lupe').fadeOut("fast");}},10);});
       	
       	$('#lupe').click(function (){
			$('#slides .slide').each(function (){
       			if ($(this).is(':visible')) {
       				$(this).find('a').click();
       			};
       		});
       	});
       	}
