/*
  JS Grundfunktionen | © 2010 by mc-waldkraiburg.de
____________________________________________ */

$(function (){

	$.fn.MCWaldkraiburg = function(settings) {

// --------------------- KONTAKTFORMULAR --------------------------

    // contactform | INPUT, TEXTAREA - Toggle Value on click and check content on blur
    jQuery.fn.DefaultValue = function(text){
      return this.each(function(){
      	// Make sure we're dealing with text-based form fields
      	if(this.type != 'text' && this.type != 'password' && this.type != 'textarea') {
      		return;
        }

      	// Store field reference
      	var fld_current=this;

      	// Set value initially if none are specified
            if(this.value=='') {
      		this.value=text;
      	} else {
      		// Other value exists - ignore
      		return;
      	}

      	// Remove values on focus
      	$(this).focus(function() {
      		if(this.value==text || this.value=='')
      			this.value='';
      	});

      	// Place values back on blur
      	$(this).blur(function() {
      		if(this.value==text || this.value=='')
      			this.value=text;
      	});

      	// Capture parent form submission
      	// Remove field values that are still default
      	$(this).parents("form").each(function() {
      		// Bind parent form submit
      		$(this).submit(function() {
      			if(fld_current.value==text) {
      				fld_current.value='';
      			}
      		});
      	});
      });
    };

    // contactform | VALUE - Set Text
  	$("#cf_name, #cf_forename, #cf_email").DefaultValue("(Pflichtfeld)");
  	$("#cf_city").DefaultValue("(Beides Pflichtfelder)");
  	$("#cf_message").DefaultValue("Ihre Nachricht ...");

// --------------------- BILDERGALERIE --------------------------

    if( $(".box-event").length ) {
    
      $.fn.startGallery = function() {
       $("#gallery a").lightBox();
       $("#gallery a:first").click();
      };

      $(".be-open").click(function() {

        $("#gallery").html();
        var getGalleryImages = $(this).parent(".box-event").contents(".be-gallery").html();
        $("#gallery").html(getGalleryImages).startGallery();
        
      });

    }
    
    $(".box-event:first").css('margin', '-17px 0 0');
    
  };
  
  // Activate MCWaldkraiburg if HTML is ready
  $("html").MCWaldkraiburg();

});
