$(document).ready(function() {

  /* Open External Links in New Window */
	$("a[rel=external]").attr('target','_blank');
	$("a[rel=nofollow]").attr('target','_blank');
	
  /* Cufon Font Replacement */
	Cufon.replace("ul#home-slideshow .description h3, .content p.call-to-action em, .content .left-column h4, .content p.elevator, #footer h5 em");
	
	/* Home Slideshow */
	$("ul#home-slideshow li .description, ul#home-slideshow li .image").hide();
	$("ul#home-slideshow") 
    .after("<ul id='home-slideshow-navigation'></ul>")
    .cycle({ 
      fx: "fade",
      speed: 400,
      timeout: 6000,
      pause: 1,
      cleartypeNoBg: true,
      pauseOnPagerHover: 1,
      before: homeBefore,
      after: homeAfter,
      pager: "ul#home-slideshow-navigation",
      activePagerClass: "current",
      pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="javascript:void(0)">'+$(slide).attr("data-title")+'</a></li>';
      }
    });
  $("ul#home-slideshow-navigation li a:last").addClass("last");
  function homeBefore(curr, next, opts) {
    $("ul#home-slideshow li .image").slideUp(300, "easeInCirc");
    $("ul#home-slideshow li .description").delay(100).slideUp(300, "easeInCirc");
  }
  function homeAfter(curr, next, opts) {
    $("ul#home-slideshow li:visible").find(".image").delay(100).slideDown(300, "easeOutCirc");
    $("ul#home-slideshow li:visible").find(".description").delay(200).slideDown(300, "easeOutCirc");
  }
  
  /* Work Slideshow */
	$("ul#work-slideshow li .description, ul#work-slideshow li .image").hide();
	$("ul#work-slideshow") 
    .after("<ul id='work-slideshow-navigation'></ul>", "<div id='next-prev'><a class='previous' href='#'>Previous Project</a><a class='next' href='#'>Next Project</a></div>")
    .cycle({ 
      fx: "fade",
      speed: 400,
      timeout: 0,
      pause: 1,
      pauseOnPagerHover: 1,
      before: workBefore,
      after: workAfter,
      prev: "#next-prev a.previous",
      next: "#next-prev a.next",
      pager: "ul#work-slideshow-navigation",
      activePagerClass: "current",
      pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="javascript:void(0)"><img src="'+$(slide).attr("data-thumbnail")+'" width="50" height="50"/></a></li>';
      }
    });
  function workBefore(curr, next, opts) {
    $("ul#work-slideshow li .image").slideUp(300, "easeInCirc");
    $("ul#work-slideshow li .description").delay(100).slideUp(300, "easeInCirc");
  }
  function workAfter(curr, next, opts) {
    $("ul#work-slideshow li:visible").find(".image").delay(100).slideDown(300, "easeOutCirc");
    $("ul#work-slideshow li:visible").find(".description").delay(200).slideDown(300, "easeOutCirc");
  }
  var workslide = window.location.hash.slice(1);
  if (window.location.hash) {
    $("ul#work-slideshow").cycle(workslide - 1);
  }
	
});
