var portAutoDelay = 40; //in tenths of seconds
var portAutoCount = 0;
var portAutoInterval;

function portAutoAdvance() {
  if(++portAutoCount == portAutoDelay) {
    clickNextThumbnail();
    portAutoCount = 0;
  }
}

function clickNextThumbnail() {
  if(jQuery("#side-port li.selected").next().length) {
    jQuery("#side-port li.selected").next().find("a").trigger("click");
  } else {
    jQuery("#side-port li:first").find("a").trigger("click");
  }
}

jQuery(document).ready(function($){
  
  $(".lightbox a").lightBox();

  $("button, #sprite-follow, #sprite-rss")
    .mouseover(function(){ $(this).addClass("hover"); })
    .mouseout(function(){ $(this).removeClass("hover"); });
  
  $("input, textarea")
    .focus(function(){ $(this).addClass("focus"); })
    .blur(function(){ $(this).removeClass("focus"); });
  
  //corners
  $(".wpcf7-form-control-wrap, .wpcf7-button-wrap inputz, .post h2 small").corners("5px");
  $(".button").corners("5px transparent");
  $(".wpcf7-button-wrap")
    .corners("5px transparent")
    .find("*")
    .focus(function(){ $(this).blur(); });
  $(".mapp-div")
    .css({ border: '0px' })
    .wrap("<div class='mapp-div-wrap'></div>")
    .parent()
    .corners("5px");
  
  //portfolio pages
  if($("#side-port").length) {
    $("#side-port li:first").addClass("selected");
    $(".main-display img").load(function(){
      $(this).fadeTo(500, 1, function(){
        clearInterval(portAutoInterval);
        portAutoInterval = setInterval(portAutoAdvance, 100);
      });
    });
    $("#side-port li a").click(function() {
      portAutoCount = 0;
      clearInterval(portAutoInterval);
      selectedImage = $(this).attr("rel");
      selectedLink = $(this).attr("href");
      $(".main-display img").fadeTo(500, 0, function(){
        $(this).attr("src", selectedImage);
        //$(this).parent().attr("href", selectedLink);
      });
      $("#side-port li").removeClass("selected");
      $(this).parent().addClass("selected");
      return false;
    });
    $("#side-port li:first").trigger("click");
  }

});