

$(document).ready(function(){

  if(typeof $.prettyPhoto == 'object') {
  	$(".slGal a[rel^='pPGal'], .cGal a[rel^='pPGal']").prettyPhoto({"theme": "facebook"});
  }	

	// Read Rel 
	$.urlParam = function(name){ 
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); 
    if (!results) { return 0; } return results[1] || 0;
  } 


  el = $("input.formtext[title='Interesse an folgendem Aufruf:']");
  
  if(el.size() && $.urlParam("rel")) { 
    if(el.val()=="") { el.val(decodeURI($.urlParam("rel"))); }
  } 



  $(window).load(function(){ 
    $("#body").css({"height":"auto"});
    footerPush("#body"); 
  }).resize(function(){ 
    $("#body").css({"height":"auto"});
    footerPush("#body"); 
  });
  
      
  //externalLinks();
  
  $('a[href^=http]').click( function() {        
   window.open(this.href);         
   return false;     
  }); 
  
  noSpam();
  
  
  // Navigation 
  
  var sub_menue_to = 600;
  var sub_menue_timer = 0;
  var sub_current = 0; 
  
  $(".navigation li").mouseenter(function() {
  
    sub_menue_timerc();
    sub_menue_close();
  
    pr = $(this);
    tg = $(".sub_nv[el^="+pr.attr("rel")+"]");
    pos = pr.position();
    
    if(tg.size()) { 
      sub_current = tg.css({ "top":(parseInt(pos.top)+40) + "px", "left":(parseInt(pos.left)) + "px", "z-index":"99999999", "position":"absolute"}).show().mouseenter(function(){
        sub_menue_timerc();
      }).mouseleave(function() { sub_menue_close(); }); 
    } else{
      sub_menue_timerc(); sub_menue_close();
    }
    
  }).mouseleave(function() { sub_menue_timer(); });
  
  
  
 if(client_browser()!="browser") { 
      $(".navigation li[rel^=sc]").click(function(){
      
       
      
        if(sub_current) {
          if($(this).attr("rel") == sub_current.attr("el")) {
            return true;
          }
        } 
        
         tg = $(".sub_nv[el^="+$(this).attr("rel")+"]");
        
        if(tg.size()) { 
          $("<div></div>").css({"width":"100%", "height":"100%", "top":90+"px", "left":0,  "background-image":"url(/css/img/spacer.gif)", "z-index":"99999997", "position":"absolute"}).click(function(){ sub_menue_close();  $(this).remove(); }).appendTo("body");
          $(this).trigger("mouseenter");
          return false;
        } else {
          return true;
        }
        
      });
 }
  
  
  
  function sub_menue_close() {  if(sub_current) { sub_current.hide(); sub_current = 0; } }
  function sub_menue_timer() {  sub_menue_timer = window.setTimeout(sub_menue_close, sub_menue_to); }
  function sub_menue_timerc() { if(sub_menue_timer) { window.clearTimeout(sub_menue_timer); sub_menue_timer = null;  } }

  /* NEWSLETTER */
  
  
  $('form.newsletter').submit(function(){
	 error = $('form.newsletter input[name=email], form.newsletter input[name=name]').filter(function(index) { 
	
		if( $(this).val()=="") return true;
		
		if( $(this).attr("name") == "email") { 
			if(!$(this).val().search(/@/i) || $(this).val() == "E-Mail") {  return true; }
		}
 
 		if( $(this).attr("name") == "name") { 
 			if($(this).val() == "Vorname") return true; 
		}
		
 		return false;
		
	 });
	
	 if(error.size()>0) { error.css({'border':'1px solid #990000'}); } 
	 else { 
		$('form.newsletter input').hide();
		$(this).append('Bitte warten ...');
		$(this).load('/newsletter/', $(this).serialize());
	 }

	}).find('input[type=text]').focusin(function(){ $(this).val(""); });


});


function client_browser() {
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { return "ios"; }
  return "browser";
}

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            anchor.target = "_blank";
        }
    }
}


function noSpam() {
    var a = document.getElementsByTagName("a");
    for (var i = a.length-1; i >= 0; i--) {
      if (a[i].className.search(/\bemail\b/) != -1) {
        var email = a[i].firstChild.data + "@" + a[i].lastChild.data;
        a[i].innerHTML = email;
        a[i].href = "mailto:" + email;
      }
    }
}

function openPopup(){
  window.open("","_popup","toolbars=0,location=0,width=750,height=550");
  return true;
}



function footerPush (bodyElement) {

    if ( $(window).height() > $(document.body).height() ) {
        if ( $.browser.msie ) {             //If Microsoft's IE
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()));
        } else if ($.browser.mozilla) {     //If Mozilla's Firefox
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) );
        } else if ($.browser.safari) {      //If Apple's Safari *or* Google's Chrome
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()));
        } else {                            //Any other browser, default to 'standard' implementation
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()));
        };
    };
    if ( $.browser.opera ) {     //If Opera
        if ( window.innerHeight > $(document.body).height() ) {
            $(bodyElement).height( $(bodyElement).height() + ( window.innerHeight - $(document.body).height()));
        };
    };
};




