/*
  JS Grundfunktionen | © 2010 by ciference.com
____________________________________________ */

$(function (){

  $.fn.CiferenceScripts = function(settings) {

//-------------------- SLIDER -------------------------

    $("#flowpanes").scrollable({
      circular: true,
      mousewheel: true
    }).navigator({
      navi: "#flowtabs",
      naviItem: 'a',
      activeClass: 'current',
      history: true
    }).autoscroll({
      autoplay: true,
      interval: 6000,
      autopause: true
    });

//-------------------- TERMS -------------------------
/*
  $("#navigation a[title*='Termine']").attr({
      href: '#',
      class: 'open-overlay'
    });*/

//-------------------- GALLERY -------------------------

    $("#overlay_bg, #video_bg").css('opacity', '0.7');

    $("#open-overlay").click(function() {
     
      $("#overlay_bg, #overlay_overlay").fadeIn(250);

    });

    $("#overlay_overlay, #overlay_close").click( function() {
      $("#overlay_bg, #overlay_overlay").fadeOut(250);

    });
    
    $(".scroll-item .open-video").click(function() {

      $("#video_content span").html();
      var getVideo = $(this).parent(".scroll-item").contents(".box-hidden").html();
      $("#video_content span").html(getVideo);
      $("#video_bg, #video_overlay").fadeIn(250);

    });
    
    $(".box-partner-item .open-video").click(function() {

      $("#video_content span").html();
      var getVideo = $(this).parent(".box-partner-item").contents(".box-hidden").html();
      $("#video_content span").html(getVideo);
      $("#video_bg, #video_overlay").fadeIn(250);

    });

    $("#overlay_overlay, #overlay_close, #video_overlay, #video_close").click( function() {
      $("#overlay_bg, #overlay_overlay, #video_bg, #video_overlay").fadeOut(250);

    });
    
    $.fn.startGallery = function() {
     $("#gallery a").lightBox();
     $("#gallery a:first").click();
    };
    
    $(".box-reference-data-links-gallery").click(function() {

      $("#gallery").html();
      var getGalleryImages = $(this).parent(".box-reference-data-links").contents(".box-hidden").html();
      $("#gallery").html(getGalleryImages).startGallery();

    });

    $("#overlay_content, #video_content").click( function() {
      return false;
    });

// --------------------- 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
    $("input[name~='cf-name']").DefaultValue("> Name (Pflichtfeld)");
    $("input[name~='cf-forename']").DefaultValue("> Vorname (Pflichtfeld)");
    $("input[name~='cf-street']").DefaultValue("> Straße | Nr.");
    $("input[name~='cf-zip']").DefaultValue("> PLZ (Pflichtfeld)");
    $("input[name~='cf-country']").DefaultValue("> Land");
    $("input[name~='cf-email']").DefaultValue("> mail (Pflichtfeld)");
    $("input[name~='cf-website']").DefaultValue("> homepage");

  };

  // Activate CiferenceScripts if HTML is ready
  $("html").CiferenceScripts();

});
