// JavaScript Document
$(document).ready(function($){
    if($('#socialshareprivacy').length > 0){
		$('#socialshareprivacy').socialSharePrivacy({
		services : {
		facebook : {
		  'status': 'on',
		  'action': 'like',
		  'dummy_img': 'images/socialshareprivacy/dummy_facebook.png'
		}, 
		twitter : {
			'status' : 'off'
		},
		gplus : {
		  'status' : 'off'
		}
		},
		'info_link': 'http://lauschabwehr.lentz-detektei.de/datenschutz-facebook.html',
		'css_path': 'css/socialshareprivacy.css'
		});
    }
	
	if ( $("a.fancyboxYt").length > 0 ) {	// wenn Youtube-Video in Fancybox vorhanden
		var ytSource = $('#ytvideo iframe').attr('src')+'&autoplay=1';
		$("a.fancyboxYt").fancybox({
			'padding': 0,
			'scrolling': 'no',
			'onComplete': function() {
				$('#ytvideo iframe').attr('src',ytSource);
			}
		});
	}
	
	if ( $("a.fancybox").length > 0 ) { // wenn vergrößerbare Bilder vorhanden
		$("a.fancybox").fancybox({
			'padding': 0,
			'scrolling': 'no'
		});
	}
	
	if ( $("a.gallery").length > 0 ) { // wenn Galerie vorhanden
		$("a.gallery").fancybox({
			'padding': 0,
			'scrolling': 'no',
			'titlePosition': 'over'
		});
	}
	
	// Telefon-Hinweis
	var openBig = false;
	var openSmall = false;
	setTimeout(function() { 
		$('#achtung').fadeOut(200, function(){});
		$("#achtung-open").mouseenter(function() {
			openSmall = true;
			$('#achtung').fadeIn(200);
		}).mouseleave(function(){
			openSmall = false;
			setTimeout(function() { 
				if(!openBig){
					$('#achtung').fadeOut(200);
				}
			}, 250);
		});
		
		$("#achtung").mouseenter(function() {
			openBig = true;
		}).mouseleave(function(){
			openBig = false;
			setTimeout(function() { 
				if(!openSmall){
					$('#achtung').fadeOut(200);
				}
			}, 250);	
		});
	
		$("#achtung-open").click(function() {
			$('#achtung').fadeToggle(200);
		});
	}, 5000);
	
	
});

if(typeof sIFR == "function"){
 sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"flash/DIN-Medium.swf", sColor:"#ffffff", sWmode:"transparent" }));
};
       $(document).ready(function(){
     $('#sendEmail').click(function(){ 
   sendingEmail();
    });  
  
  $('#checkListeForm').submit(function() { 
   sendingEmail();
  });
  
  function sendingEmail() { 
   
   email = $('#checkListeForm').find('input[name=email]').val();
   if (validateEmail(email)){
     
    newsletter = $('#newsletter').attr('checked'); 
    params = "";
    params += "email=" + email + "&newsletter=" + newsletter;
    $.ajax({
     url: 'phplib/doIt.php' ,
     type: 'POST',
     data: params,
     beforeSend: function() {
      $('#info').remove();
      $('<p id="info" style="color:red;margin-top:-5px;">Warten Sie Bitte...</p>').insertBefore($('#checkListeForm')).slideDown("slow");
     },
     error: function(){
      $('#info').remove();
      $('<p id="info" style="color:red;margin-top:-5px;">Ajax error</p>').insertBefore($('#checkListeForm')).slideDown("slow");
     },
     success: function(msg){
      var obj = JSON.parse(msg);
      $('#info').remove();
      $(obj).insertBefore($('#checkListeForm')).fadeOut(4000, function() {
       $(this).remove();
      });//.slideDown("slow");
      $('#checkListeForm').find('input[name=email]').css( 'border-style','none').val('');      
      } 
    });   
     //return false; 
   }else if (email == '') {
    $('#info').remove();
    $('<p id="info" style="color:red;margin-top:-5px;">Bitte geben Sie eine E-Mail-Adresse ein!</p>').insertBefore($('#checkListeForm')).slideDown("slow");
    $('#checkListeForm').find('input[name=email]').css({'border-color' : 'red', 'border-style':'solid','border-width':'2px'}) ;
 
   } else {
    $('#info').remove();
    $('<p id="info" style="color:red;margin-top:-5px;">Die E-Mail-Adresse ist nicht korrekt.</p>').insertBefore($('#checkListeForm')).slideDown("slow");
    $('#checkListeForm').find('input[name=email]').css({'border-color' : 'red', 'border-style':'solid','border-width':'2px'}) ;
   }
        }
 
  function validateEmail(email) {
   var mail_pattern = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
   if(mail_pattern.test(email) == true){
   return true;
   }else {
   return false
   }
  } 
  
});

