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


/*
 * jQuery
 */
$(document).ready(
  function()
  {
    /*
     * Eyecatcher
     */
    if($("#eyecatcher") && $("#eyecatcher").length)
    {
      // Show eyecatcher
      if($("#eyecatcher").attr("complete"))
      {
        // Fade in eyecatcher immediately
        $("#eyecatcher").fadeIn(666);
      }
      else
      {
        // Load eyecatcher completely, then fade in
        $("#eyecatcher").load(
          function()
          {
            $("#eyecatcher").fadeIn(666);
          }
        ); 
      }
    }




    /*
     * Image
     */
    if($("#image") && $("#image").length)
    {
      // Get image dimensions
      imgw = $("#image").width ();
      imgh = $("#image").height();

      // Set image container dimension
      $("#image-container").width (imgw + "px");
      $("#image-container").height(imgh + "px");

      // Set image wrapper dimension
      w = Math.max(imgw + 164, 884);
      h = imgh;

      $("#image-wrapper").width (w + "px");
      $("#image-wrapper").height(h + "px");

      // Show image wrapper
      $("#image-wrapper").show();

      // Show image
      if($("#image").attr("complete"))
      {
        // Fade in image immediately
        $("#image").fadeIn(666);
      }
      else
      {
        // Load image completely, then fade in
        $("#image").load(
          function()
          {
            $("#image").fadeIn(666);
          }
        ); 
      }
    }




    /*
     * 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&uuml;ltige E-mail-Adresse ein!"
                         },

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


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




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

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

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

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




    /*
     * Category list effects
     */
    if($("#category-list") && $("#category-list").length)
    {
      $("#category-list a").mouseover(
        function ()
        {
          // Stop everything
          $(this).stop();

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

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

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




    /*
     * Image button effects
     */
    if($("#image-wrapper") && $("#image-wrapper").length)
    {
      $("#image-button-previous").mouseover(
        function ()
        {
          // Stop everything
          $(this).stop();

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

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

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


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

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

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

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




    /*
     * Browse thumbnail effects
     */
    if($("#browse-thumbnails") && $("#browse-thumbnails").length)
    {
      // Show thumbnail
      if($("#browse-thumbnails img").attr("complete"))
      {
        // Fade in thumbnail immediately
        $("#browse-thumbnails img").parent().parent(".thumbnail").show();
      }
      else
      {
        // Load thumbnail completely, then fade in
        $("#browse-thumbnails img").load(
          function()
          {
            $(this).parent().parent(".thumbnail").fadeIn(666);
          }
        ); 
      }


      $("#browse-thumbnails img").mouseover(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade in
          $(this).fadeTo(250, 1.0);
        }
      );

      $("#browse-thumbnails img").mouseout(
        function ()
        {
          // Stop everything
          $(this).stop();

          // Fade out
          $(this).fadeTo(250, 0.33);
        }
      );
    }
  }
);

