$(function() {
  $("#slider")
    //calling scrollable plugin
    .scrollable({
      size: 1,
      speed: 500, // The time (in milliseconds) of the scrolling animation.
      easing: "swing" // The type of "easing" applied to the scrolling animation. 'swing' means that there is an acceleration, followed by a constant speed, followed by a deceleration. 'linear' means that the whole animation happens at a constant speed.
    })
    //calling autoscroll plugin
    .autoscroll({
      steps: 1, // The number of items being scrolled within a single autoscroll.
      interval: 4000, // The time (in milliseconds) between autoscrolls.
      autoplay: true, // When enabled the scrolling starts automatically upon page load.
      autopause:true // If this property is set to true then, when any navigational buttons are mouseovered, the autoscrolling will pause.
    })
    //calling circular, and navigator
    .circular()
    .navigator(); // comment out this line if you don't want to support keyboard navigation in slider, just remember to add semicolon(;) to the previous line.
    //.mousewheel(500); // uncomment this line if you want to support mousewheel navigation in slider, just remember to remove the semicolon(;) from the previous line.

  //calling tooltip plugin
  $(".items img").tooltip({
    tip: ".items .info",
    position: "bottom center",
    offset: [-100,0],
    effect: "slide",
    relative: true
  })

  //calling reflection plugin
  $("#slider img").reflect({
    height: 0.15,
    opacity: 0.2
  });

  //calling superfish plugin
  $('ul#main-menu').superfish({
    autoArrows: false
  });

  //calling prettyPhoto plugin
  $(".project-gallery-lightbox .item a[rel^='prettyPhoto']")
    .prettyPhoto({
      theme:'dark_rounded' // available theme: dark_rounded, dark_square, facebook, light_rounded, light_square.
  });

  //calling autofill plugin
  $('#search-input').autofill({
    value: "Search...",
    defaultTextColor:"#2D363B"
  });

  // Custom Script
  // calculate and set absolute left position for navi
  // to make it horizontally centered
  var navWidth = $(".navi").width();
  var galWidth = $("#slider").width();
  $(".navi").css({'left' : ((galWidth - navWidth) / 2) + "px"});

  // Ajax PHP Contact Form
  // Based on tutorial by Jeffrey Way, http://blog.themeforest.net/tutorials/how-to-create-a-contact-form-using-php-and-ajax/

  var paraTag = $('input#submit').parent('p');
  $(paraTag).children('input').remove();
  $(paraTag).append('<input class="button" type="button" name="submit" id="submit" tabindex = "5" value="Send" />');

  $('#contact-main input#submit').click(function() {
      $('#contact-main p.button').append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');

      var name = $('input#name').val();
      var email = $('input#email').val();
      var subject = $('input#subject').val();
      var message = $('textarea#message').val();

      $.ajax({
          type: 'post',
          url: 'sendEmail.php',
          data: 'name=' + name + '&email=' + email + '&subject=' + subject + '&message=' + message,

          success: function(results) {
              $('#contact-main img.loaderIcon').fadeOut(1000);
              $('div#response').html(results);
              var responseStatus = $('div#response p').attr('class');
              $('div#response').removeClass().addClass(responseStatus);
              if (responseStatus == 'success')
                $( "form" )[ 0 ].reset();
          }
      }); // end ajax
  });
});


