// JavaScript Document
// Copyright Oates Associates 2010+
// Web Design & Development by McCord Design Group (mccorddesign.com)

$(function() {
  //show header once loaded
  $('h2.hide').hide();
  $(window).load(function () {
    $('h2.hide').show();
    $('h2.hide').removeClass('hide');
  });

  // For custom scroll bar
  $('#main-body').jScrollPane({
    showArrows: true,
    horizontalGutter: 10
  });

  //For homepage slider
  $('#home-slider').cycle({
    fx: 'fade',
    timeout: 4000,
    speed: 1000
  });

  //sidebar links on same page
  //var pathname = window.location.pathname;
  //$('#news-links a').click(function(){
   // if (pathname.substring(0, 9) == "/articles") {
      //location.reload();
    //}
  //});
  $('#news-links a').click(function(){
    var href = $(this).attr('href').split(/=/)[1]
    var td   = $('td#' + href).selector;
    $(td).find('.articleBody').slideToggle();
    $('#news-body').scrollTo(td);
  });

});

//Pretty Photo Video Pop Up
$(function() {
  $("a[class^='prettyPhoto']").prettyPhoto();
});

//For next/previous in biography section
$(function() {
  var last_item   = $('#nav-biographies ul li:last'),
      last_href   = $(last_item).children().attr('href'),
      first_item  = $('#nav-biographies ul li:first'),
      first_href  = $(first_item).children().attr('href'),
      prev_li     = $('#nav-biographies ul li.selected').prev(),
      prev_href   = $(prev_li).children().attr('href'),
      next_li     = $('#nav-biographies ul li.selected').next(),
      next_href   = $(next_li).children().attr('href');

  $('#previous-bio').click(function(e){
    if ($(prev_li).length) {
      window.location = prev_href;
      return false;
    } else {
      window.location = last_href;
      return false;
    }
  });

  $('#next-bio').click(function(){
      if ($(next_li).length) {
        window.location = next_href;
        return false;
      } else {
        window.location = first_href;
        return false;
      }
    });
});

//For next/previous in projects
$(function() {
  //general for all
  var prev_li     = $('.projects.' + window.location.hash.substring(1) + ' ul li.selected').prev('li'),
      prev_href   = $(prev_li).children().attr('href'),
      next_li     = $('.projects.' + window.location.hash.substring(1) + ' ul li.selected').next('li'),
      next_href   = $(next_li).children().attr('href');

  if ($(prev_li).length == 0) {
    $('#previous-project').css('opacity','0.25').removeAttr("href");
  }
  if ($(next_li).length == 0) {
    $('#next-project').css('opacity','0.25').removeAttr("href");
  }

  $('#previous-project').click(function(){
    if ($(prev_li).length) {
      window.location = prev_href;
      return false;
    } else {
      return false;
    }
  });

  $('#next-project').click(function(){
    if ($(next_li).length) {
      window.location = next_href;
      return false;
    } else {
      return false;
    }
  });

});
