/*
 * Copyright by Oliver Musebrink (www.olivermusebrink.de)
 */


/*
 * jQuery
 */
$(document).ready(
  function()
  {
    /*
     * Slideshow
     */
    if($("#slideshow") && $("#slideshow").length)
    {
      /*
       * Scroll function
       */
      jQuery.easing.easeOutQuadric = function(x, t, b, c, d)
      {
        t = (t / d) - 1;
        p = -c * ((t * t * t * t) - 1) + b;

        return p;
      }




      /*
       * Showcase
       */
      $("#showcase").serialScroll(
        {
          items:      "li",
          axis:       "x",
          prev:       "#navigation-previous",
          next:       "#navigation-next",
          offset:     0, 
          start:      0,
          duration:   500,
          force:      false,
          stop:       true,
          lock:       false,
          cycle:      true,
          easing:     "easeOutQuadric",
          jump:       false
        }
      );




      /*
       * Slideshow button effects
       */
      $("#navigation-previous").mouseover(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade in
          $("#button-previous").stop  ();
          $("#button-previous").fadeTo(333, 1.0);
        }
      );

      $("#navigation-previous").mouseout(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade in
          $("#button-previous").stop  ();
          $("#button-previous").fadeTo(333, 0.0);
        }
      );


      $("#navigation-next").mouseover(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade in
          $("#button-next").stop  ();
          $("#button-next").fadeTo(333, 1.0);
        }
      );

      $("#navigation-next").mouseout(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade in
          $("#button-next").stop  ();
          $("#button-next").fadeTo(333, 0.0);
        }
      );




      /*
       * Showcase images
       */
      if($("#showcase img.image"))
      {
        // Show image
        if($("#showcase img.image").attr("complete"))
        {
          // Fade in image immediately
          $("#showcase img.image").fadeIn(333);
        }
        else
        {
          // Completely load image, then fade in
          $("#showcase img.image").load(
            function()
            {
              $("#showcase img.image").fadeIn(333);
            }
          ); 
        }
      }
    }




    /*
     * Contact form
     */
    if($("#contact-form") && $("#contact-form").length)
    {
      var contactFormValidator = null;


      contactFormValidator = $("#contact-form").validate(
      {
        submitHandler: function(form)
                       {
                         form.submit();
                       },

        errorClass:    "error",

        errorElement:  "div",

        rules:         {
                         name:
                         {
                           required:  true,
                           minlength: 1
                         },

                         email:
                         {
                           required: true,
                           email:    1
                         },

                         message:
                         {
                           required:  true,
                           minlength: 1
                         }
                       },

        messages:      {
                         name:
                         {
                           required: "Bitte geben Sie Ihren Namen ein!"
                         },

                         email:
                         {
                           required: "Bitte geben Sie Ihre E-mail-Adresse ein!",
                           email:    "Bitte geben Sie eine gültige E-mail-Adresse ein!"
                         },

                         message:
                         {
                           required: "Bitte geben Sie Ihre Nachricht ein!"
                         }
                       }
      });




      /*
       * Reset button
       */
      $("#contact-form .reset").click(
        function()
        {
          contactFormValidator.resetForm();
        }
      );
    }




    /*
     * Error page image
     */
    if($("#error") && $("#error").length)
    {
      if($("#error img.image"))
      {
        // Show image
        if($("#error img.image").attr("complete"))
        {
          // Fade in image immediately
          $("#error img.image").fadeIn(333);
        }
        else
        {
          // Completely load image, then fade in
          $("#error img.image").load(
            function()
            {
              $("#error img.image").fadeIn(333);
            }
          ); 
        }
      }
    }




    /*
     * Menu effects
     */
    $("#menu a").mouseover(
      function()
      {
        // Stop everything
        $(this).stop();

        // Fade in
        if(!$(this).hasClass("selected"))
        {
          $(this).fadeTo(333, 0.66);
        }
      }
    );

    $("#menu a").mouseout(
      function()
      {
        // Stop everything
        $(this).stop();

        // Fade out
        if(!$(this).hasClass("selected"))
        {
          $(this).fadeTo(333, 0.4);
        }
      }
    );
  }
);

