jQuery(document).ready(function() {
  // Start Kontaktdaten/Agentur ein-/ausblenden
  jQuery(".kopfImage").bind("mouseenter",function(){
    jQuery(this).prev().fadeIn();
  });
      
  jQuery(".kopfContent").bind("mouseleave",function(){
    jQuery(this).fadeOut();
  });
  // Ende
  
  // Start Projekt/Memory Daten ein-/ausblenden
  jQuery(".projektMemory").bind("mouseenter",function(){
    jQuery(this).parent().prev().fadeIn();
  });
      
  jQuery(".projektContent").bind("mouseleave",function(){
    jQuery(this).fadeOut();
  });
  // Ende
  
  // Start Slideshow Agentur
  jQuery('#agenturImageContainer').cycle({
    fx:    'fade',
    speed:	2500,
    timeout:  2000
  });
  // Ende
    
    
  jQuery(".clickHeader").click(function () {
    jQuery(this).next().next().slideToggle('fast');
    if(jQuery(this).css('backgroundPosition')=='0px 2px'){
      jQuery(this).css('backgroundPosition','20px 2px');
    }
    else
    {
      jQuery(this).css('backgroundPosition','0px 2px');
    }
  });
  
  jQuery(".agentur_more").click(function () {
    jQuery(".agentur_teaser").hide();
    jQuery(".agentur_text").show();
  });
  
  // Submenu-Hover
  jQuery("ul#topNav li").hover(function() { //Hover over event on list item
    // alert('ok');
    // $(this).css({ 'background' : '#1376c9 url(topnav_active.gif) repeat-x'}); //Add background color and image on hovered list item
    jQuery(this).find("span").show(); //Show the subnav
  } , function() { //on hover out...
    // $(this).css({ 'background' : 'none'}); //Ditch the background
    jQuery(this).find("span").hide(); //Hide the subnav
  });
    
  // Newsletter-Bereich aufklappen
  jQuery("#newsletterText a").click(function () {
    jQuery("#newsletterFormBox").slideToggle('fast');
    return false;
  });
  
  // Newsletter Formular-Validierung
  jQuery("#newsletterForm").validate({
    rules: {
      from_email: {
        required: true,
        email: true
      }
    },
    messages: {
      from_email: {
        required: "Bitte füllen Sie diese Feld aus",
        email: "Bitte geben Sie eine gültige Email-Adresse ein"
      }
    }
  });
  
  // Newsletter Ajax_Form
  jQuery('#newsletterForm').ajaxForm(function() {
    alert("Ihre Registrierung wurde erfolgreich abgesendet. Vielen Dank!");
    jQuery("#newsletterFormBox").slideToggle('fast');
  });
  
  // in-field Labels
  jQuery("label").inFieldLabels();

  
  jQuery(function() {
    setInterval( function() {
      jQuery("#customers ul :first").slideUp(1500, function() {jQuery("#customers ul li").filter(":first").insertAfter(jQuery("#customers ul li").filter(":last")).show()});
    }, 2000 );
  });
	
});

var activeMedia;

function showMedia( id ) {
	
	activeMedia = id;
	
	jQuery( "#mediaPagination a" ).removeClass("blue");
	jQuery( "#mediaPagination a#link_" + id ).addClass("blue");
	
	jQuery( ".mediaObject" ).hide();
	jQuery( "#mediaObject_" + id ).show();
	
}

function showAllMedia()
{
    jQuery( ".mediaObject" ).show();
}

function prevMedia( totalMedia ) {
	if ( activeMedia == undefined ) {
		showMedia( totalMedia );
		return;
	}
	
	prev = parseInt( activeMedia ) - 1;

	if ( parseInt( prev ) < 1 ) {
		showMedia( totalMedia );
		return;
	}
	
	showMedia( prev );
}

function nextMedia( totalMedia ) {
	if ( activeMedia == undefined ) {
		showMedia( 2 );
		return;
	}
	
	next = parseInt( activeMedia ) + 1;

	if ( parseInt( next ) > parseInt( totalMedia ) ) {
		showMedia( 1 );
		return;
	}
	
	showMedia( next );
	
}

function slideShowStart(count){
  jQuery('#startseiteSlide').cycle({
        fx:    'fade',
        speed:   500,
        pause: true,
        timeout:  4000,
        cleartype: true,
        next: '#next',
        prev: '#prev',
        pager: '#slidePager',
        pagerAnchorBuilder: function(idx, slide) {
          return '#slidePager a:eq(' + idx + ')';
        },
        after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
          replaceHeadlines();
        }    
   });
		
  jQuery('.slideImagePager a').click(function() {
    var index = jQuery('.slideImagePager a').index(this);
    jQuery('#slidePager a:eq('+(index % count)+')').trigger('click'); 
    return false; 
  });
}
  
function emailMe(link,title){
  if(link){
      var email = "email@adresse.com";
      var subject_title = (title)? ": "+title:"";
      var subject_bodytitle = (title)? '"'+title+'"':"";
      var subject = "Tipp von www.muehlhausmoers.com"+subject_title;
      var body_message = "Diese Seite auf www.muehlhausmoers.com "+subject_bodytitle+" könnte für Sie interessant sein.%0D%0A%0D%0ADies ist der Link zu der Seite:%0D%0A"+link;
      var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
      document.location.href= mailto_link;
  }
}
