// Cufon
var memphis = [
  '#tagline',
  '#primaryNavigation li a',
  '#contactInfo h4',
  '#contactInfo a',
  '#contactInfo span',
  '#splash p',
  '#splash a'
];
Cufon.replace(memphis); 

// Center Postit
function postIt() {
  var $parent = $('#primaryContent'),
      $child =  $('#projectInfo');
  var parentX = $parent.outerWidth(),
      parentY = $parent.outerHeight(),
      childX = $child.outerWidth(),
      childY = $child.outerHeight();
  if ($child.length) {
    $child
    .append('<a class="close" href="#">Close</a>')
    .css({
      'top' : ((parentY - childY) / 2) - 17,
      'left' : (parentX - childX) / 2
    })
    .fadeIn(500);
    
    $parent
      .find('.slide, .postIt')
      .fadeTo(500, 0.5);  
  }
  $child.find('.close').click(function(){ // Close Button
    $child
    .fadeOut(500);
    $parent
      .find('.slide, .postIt')
      .fadeTo(500, 1); 
    return false;
  });
   return false;    
}

// Slide Show
function slideShow(elem) {
  var len = $(elem).find('>*').length;

  var slideNav = ' ';
  slideNav += '<div class="slideNav">';
  slideNav += '<ul>'; 
  slideNav += '<li class="prev"><a href="#">Previous</a></li> ';
  slideNav += '<li class="next"><a href="#">Next</a></li>'; 
  slideNav += '</ul>'; 
  slideNav += '</div>';

  var slidePager = ' ';
  slidePager += '<div class="slidePager">';
  slidePager += '<ul></ul>';
  slidePager += '</div>';

  var cycleOpts = {};
  cycleOpts.fx = 'fade';
  cycleOpts.timeout = 0;
  cycleOpts.prev = '.slideNav .prev';
  cycleOpts.next = '.slideNav .next, .slide img';
  cycleOpts.pager = '.slidePager ul';
  cycleOpts.pagerAnchorBuilder = function(idx, slide) {
    return '<li><a href="#">'+ (idx + 1) +'</a></li>';
  };
  if (len > 1) {
    $(elem)
      .parent()
      .prepend(slideNav)
      .append(slidePager)
    .end()  
    .cycle(cycleOpts);
  }
}

// Center Splash
function centerSplash(elem) {
  var elemY = $(elem).height(),
      winY = $(window).height();
  $(elem).css({
    'height' : elemY,
    'marginTop' : ((winY - elemY) / 2) + 40
  });
}

// Document Ready
$(document).ready(function(){

  // Links in New Window  
  $('a[rel*=external]').click(function(){ 
    window.open(this.href);
    return false;
  });
  
  //  Center Splash
  if ($('#splash').length) {
    centerSplash('#splash');
  }

  // Post It Note
  if ($('#projectInfo').length) {
    $('#primaryContent').append('<a class="postIt" href="#">Project Info</a>')
    $('.postIt').click(postIt);
  }
  
  // Slide Show
  if ($('#slideShow').length) {
    slideShow('.slide');
  }

});

$(window).bind('resize', function(){
  centerSplash('#splash');
});

// Key Bindings
$(document).keyup(function(e){ 
  if (e.keyCode == 39) { // Right    
     $('.slideNav .next a').trigger('click');  
     return false;
  } else if (e.keyCode == 37) { // Left
    $('.slideNav .prev a').trigger('click');  
    return false;
  } else if (e.keyCode == 38) { // Up
    var url = $('#secondaryNavigation a.current').parents('li').prev('li').find('a').attr('href');
    alert(url);
    return false;
  } else if (e.keyCode == 40) { // Down
    var url = $('#secondaryNavigation a.current').parents('li').next('li').find('a').attr('href');
    alert(url);
    return false;
  }  
    
}); 

//process slideshow
$(function(){
$('#SlideshowCaption').cycle({ 
		fx: 'fade',
	        speed: 1000,
		timeout: 0,
		next: '.slideNav li.next, .slide img',
		prev: '.slideNav li.prev',
       pager: '.slidePager ul',
        pagerAnchorBuilder: function(i) {
	        return $('.slidePager li:eq('+i+')');
	    }
});
	
	$("#12490958471").validate();

});

