if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return - 1;
    };
}

function show_concept(i) {
  var imgs = ["05.jpg", "01.jpg","02.jpg", "03.jpg", "04.jpg", "06.jpg", "07.jpg", "08.jpg", "09.jpg", "10.jpg"];

  var text = [ 
  "Humorous messages can encourage users to finish reading and thoroughly consider text, which they might otherwise ignore. In this case, please do not litter.",
  "Resist the overuse of labels which don't enrich your interface. Some interactions should not need to be explained.",
  "Clever placement of interface items can suggest an intended sequence to the user. For example, positioning your body in front of this urinal triggered the towel dispenser&#39;s motion sensor. The dispensed towel is a subtle contextual reminder to wash your hands after using the bathroom.",
  "The locus of one&#39;s focus is the point of highest concentration. A person can only have one locus at a time.",
  "The use of arrows to guide a user can be a sign that your interface is not easily intuited, and its affordances for the user need clarification.",
  "Users want to personalize interfaces to aid in their task completion. If your interface does not allow users to perform tasks in a manner they prefer, they will find a way to subvert your design.",
  "Graphic labels which mimic interface controls will confuse novice users; they will invariably become frustrated trying to manipulate the label. Any interface elements that look the same should function the same. This gas pump&#39;s step three was marred by fingerprints of the customers who tried to push &#8220;yes&#8221;.",
  "Eliminate all unnecessary steps in your process, or users will find a way to marginalize your design.",
  "A context for interaction is essential even if it merely highlights the boundaries. However, the interface should empower the user wherever possible.",
  "The Bauhaus said &#8220;Form follows function&#8221;, which means the form exists to honor the function. However, in this case a user needed to add their own visible clues to highlight important items on the otherwise obtusely designed interface.",
  "Use status messages, which clearly express the state or actions of the application. In this example, the label &#8220;Dry&#8221; is ambiguous because readers can interpret it as an action (the washer is drying the dishes) or a state (the dishes are dry)."
  ];
  $("#processSlideCount").text(imgs.length);
  $("#processSlideId").text(i);
  $("#processSlide .slide").html("<img src='/images/concepts/"+imgs[i-1]+"'/>");
  $('#processSlideDescription').html(text[i-1]);
  if(i <= imgs.length -1) {
    HUMANSIZED.slideIndex++;
  }else{
    HUMANSIZED.slideIndex = 1;
  }
}

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function($) {
    $('a[rel*=facebox]').facebox();
    jQuery.ajaxSetup({
        'beforeSend': function(xhr) {
            xhr.setRequestHeader("Accept", "text/javascript");
        }
    });

    $('.nav li').bind('click', function(event){
      event.preventDefault();
      $('.nav li').removeClass('selected');
      $(event.target).addClass('selected');
      var id = $(event.target).attr('title');
      var targetOffset = $('#'+id).offset().top - 82;
      $('html,body').animate({scrollTop: targetOffset}, 1000);
    });

    $('.projectImage ul').cycle({
       fx:     'fade',
       timeout: 15000,
       next:   'fade',
       pause:   0,
       pagerAnchorBuilder: function(idx, slide) { 
               return '<li><a href="#">&bull;</a></li>'; 
           },
       pager:  '.bullets',
       before:  function(){
         var id = $(this).attr('id').split('_')[1];
         $('.project').hide();
         $('#project_' + id).show();
         return false;
       }
     });

    HUMANSIZED.slideIndex = 1;
    show_concept(HUMANSIZED.slideIndex);
    $(".nextButton a").bind('click', function(event){
      event.preventDefault();
      show_concept(HUMANSIZED.slideIndex);
    });

    $("#processSlide .slide").bind('click', function(event){
      event.preventDefault();
      show_concept(HUMANSIZED.slideIndex);
    });

    $("#contactForm .submit").bind('click', function(event){
      var errors = [];
      event.preventDefault();
      var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
      if( $("#contactName").attr("value") === ""){
        errors.push("<dd>You must specify a name.</dd>");
      }
      if( $("#contactEmail").attr("value") === "" || !filter.test($("#contactEmail").attr("value"))){
        errors.push("<dd>You must specify a valid email address.</dd>");
      }
      if( $("#contactBody").val() === ""){
        errors.push("<dd>You cannot send an empty message.</dd>");
      }
      if(errors.length > 0) {
        $(".errors").html("<dl><dt>There were errors submitting your form.</dt>" + errors.join('') + "</dl>");
        var targetOffset = $('.errors').offset().top - 82;
        $('html,body').animate({scrollTop: targetOffset}, 500);
      } else {
        $("#contactForm").submit();
      }
    });
});

