
function scroll(to) {

  // Scroll to this new position.
  $.scrollTo("#" + to, 800);

  // Remove the selected class from the others.
  $("#menu ul li").removeClass("selected");

  // Select the proper item from the menu.
  $("#" + to + "m").addClass("selected");

}

function sendMsg() {

  var errors = new Array();

  // The data
  var name = $("#cf-name").val();
  var email = $("#cf-email").val();
  var msg = $("#cf-msg").val();
  var name_err = email_err = msg_err = false;

  // Error check name.
  if (name == "Walter Sobchak" || name == "") {
    errors.push('* What shall I call you?');
    name_err = true;
  }

  // Error check email
  if (email == "walter@sobchak.com" || email == "") {
    errors.push('* Please enter an email address.');
    email_err = true;
  }

  // Error check msg.
  if (msg == "") {
    errors.push('* Please enter a message.');
    msg_err = true;
  }

  if (errors.length == 0) {

    $("#contact-status").html("<img src=\"images/ajax-loader.gif\"/> Sending...");

    var data = { "name" : name, "email" : email, "msg" : msg };

    $.ajax({
      url: "ajax/contact.php",
      dataType: 'json',
      data: data,
      success: function(json){
        //$(this).addClass("done");
        if (json.is_success) {
          $("#contact-status").html("Thanks, your message has been received.<br/>I will respond as soon as possible.");
        }
        else {
          $("#contact-status").html("Something went wrong! Please either try again, or try emailing me at colinabrady@gmail.com. Sorry!");
        }
      }
    });
  }
  else {
    
    var error_str = "";
    var prepend_lb = false;

    // Make an error string.
    for (var i=0; i<errors.length; i++) {
      if (prepend_lb) error_str += "\n\n";
      error_str += errors[i];
      prepend_lb = true;
    }
    // Hide the status div.
    $("#contact-status").hide();
    // Update the status.
    $("#contact-status").html(error_str);
    // Fade it back in.
    $("#contact-status").fadeIn(900);
    // Fade it out.
    $("#contact-status").delay(5000).fadeOut(900);

    if (name_err) $('#cf-name').effect("highlight", {}, 3000);
    if (email_err) $('#cf-email').effect("highlight", {}, 3000);
    if (msg_err) $('#cf-msg').effect("highlight", {}, 3000);

  }
}

/*------------------
  http://blog.amnuts.com/2009/02/17/text-box-hint-values-with-jquery/
------------------*/
(function($) {
  $.fn.textboxhint = function(userOptions) {
    var options = $.extend({}, $.fn.textboxhint.defaults, userOptions);
    return $(this).filter(':text, textarea').each(function() {
      if ($(this).val() == '') {
        $(this).focus(function() {
          if ($(this).attr('typedValue') == '') {
            $(this).removeClass(options.classname).val('');
          }
        }).blur(function() {
          $(this).attr('typedValue', $(this).val());
          if ($(this).val() == '') {
            $(this).addClass(options.classname).val(options.hint);
          }
        }).blur();
      }
    });
  }
  $.fn.textboxhint.defaults = {
    hint: 'Please enter a value',
    classname: 'hint'
  }
})(jQuery);

$(document).ready(function() {
            $("#showcase").awShowcase(
            {
                    content_width:			600,
                    content_height:			240,
                    fit_to_parent:			false,
                    auto:				false,
                    interval:				3500,
                    continuous:				true,
                    loading:				true,
                    tooltip_width:			200,
                    tooltip_icon_width:                 32,
                    tooltip_icon_height:                32,
                    tooltip_offsetx:                    18,
                    tooltip_offsety:                    0,
                    arrows:				true,
                    buttons:				false,
                    btn_numbers:			true,
                    keybord_keys:			true,
                    mousetrace:				false, /* Trace x and y coordinates for the mouse */
                    pauseonover:			true,
                    stoponclick:			false,
                    transition:				'hslide', /* hslide/vslide/fade */
                    transition_delay:                   0,
                    transition_speed:                   500,
                    show_caption:			'onload', /* onload/onhover/show */
                    thumbnails:				false,
                    thumbnails_position:                'outside-last', /* outside-last/outside-first/inside-last/inside-first */
                    thumbnails_direction:               'vertical', /* vertical/horizontal */
                    thumbnails_slidex:                  1, /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
                    dynamic_height:			false, /* For dynamic height to work in webkit you need to set the width and height of images in the source. Usually works to only set the dimension of the first slide in the showcase. */
                    speed_change:			true, /* Set to true to prevent users from swithing more then one slide at once. */
                    viewline:				false, /* If set to true content_width, thumbnails, transition and dynamic_height will be disabled. As for dynamic height you need to set the width and height of images in the source. */
                    custom_function:                    null /* Define a custom function that runs on content change */
            });



            $("#showcase-campaigns").awShowcase(
            {
                    content_width:			270,
                    content_height:			190,
                    fit_to_parent:			false,
                    auto:				false,
                    interval:				3500,
                    continuous:				true,
                    loading:				true,
                    tooltip_width:			200,
                    tooltip_icon_width:                 32,
                    tooltip_icon_height:                32,
                    tooltip_offsetx:                    18,
                    tooltip_offsety:                    0,
                    arrows:				false,
                    buttons:				true,
                    btn_numbers:			true,
                    keybord_keys:			true,
                    mousetrace:				false, /* Trace x and y coordinates for the mouse */
                    pauseonover:			true,
                    stoponclick:			false,
                    transition:				'hslide', /* hslide/vslide/fade */
                    transition_delay:                   0,
                    transition_speed:                   500,
                    show_caption:			'onload', /* onload/onhover/show */
                    thumbnails:				false,
                    thumbnails_position:                'outside-last', /* outside-last/outside-first/inside-last/inside-first */
                    thumbnails_direction:               'vertical', /* vertical/horizontal */
                    thumbnails_slidex:                  1, /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
                    dynamic_height:			false, /* For dynamic height to work in webkit you need to set the width and height of images in the source. Usually works to only set the dimension of the first slide in the showcase. */
                    speed_change:			true, /* Set to true to prevent users from swithing more then one slide at once. */
                    viewline:				false, /* If set to true content_width, thumbnails, transition and dynamic_height will be disabled. As for dynamic height you need to set the width and height of images in the source. */
                    custom_function:                    null /* Define a custom function that runs on content change */
            });


            $("#showcase2").awShowcase(
            {
                    content_width:			600,
                    content_height:			240,
                    fit_to_parent:			false,
                    auto:				false,
                    interval:				3500,
                    continuous:				true,
                    loading:				true,
                    tooltip_width:			200,
                    tooltip_icon_width:                 32,
                    tooltip_icon_height:                32,
                    tooltip_offsetx:                    18,
                    tooltip_offsety:                    0,
                    arrows:				true,
                    buttons:				false,
                    btn_numbers:			true,
                    keybord_keys:			true,
                    mousetrace:				false, /* Trace x and y coordinates for the mouse */
                    pauseonover:			true,
                    stoponclick:			false,
                    transition:				'hslide', /* hslide/vslide/fade */
                    transition_delay:                   0,
                    transition_speed:                   500,
                    show_caption:			'onload', /* onload/onhover/show */
                    thumbnails:				false,
                    thumbnails_position:                'outside-last', /* outside-last/outside-first/inside-last/inside-first */
                    thumbnails_direction:               'vertical', /* vertical/horizontal */
                    thumbnails_slidex:                  1, /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
                    dynamic_height:			false, /* For dynamic height to work in webkit you need to set the width and height of images in the source. Usually works to only set the dimension of the first slide in the showcase. */
                    speed_change:			true, /* Set to true to prevent users from swithing more then one slide at once. */
                    viewline:				false, /* If set to true content_width, thumbnails, transition and dynamic_height will be disabled. As for dynamic height you need to set the width and height of images in the source. */
                    custom_function:                    null /* Define a custom function that runs on content change */
            });

  $('.twitter, .facebook, .linked-in, .flickr').tipsy();

  $('#cf-name').textboxhint({ hint: 'Walter Sobchak' });
  $('#cf-email').textboxhint({ hint: 'walter@sobchak.com' });

  var delay = 300;
  $("#f1").delay().fadeIn(900);
  $("#f2").delay(delay).fadeIn(900);
  $("#f3").delay(delay+=300).fadeIn(900);
  $('#menu').delay(delay+=300).animate({
      left: '+=431'
    }, 1000, function() {
      // Animation complete.
    });
    $("#f4").delay(delay+=300).fadeIn(900);
  
});


