$(function () {
    // This is to animate the navigation background
  $('ul#navbar li')
    .css({ backgroundPosition: '50% 77px'})
    .mouseover(function() {
     $(this).stop().animate({ backgroundPosition: '(50% 0px)'  }, {duration: 500})
     })
    .mouseout(function() {
     $(this).stop().animate({ backgroundPosition: '(50% 77px)' }, {duration: 250})
     });
  
  $('ul#navbar li.current_page_item, ul#navbar li.current_page_parent, body.blog li#blog-page, body.single li#blog-page')
    .css({ backgroundPosition: '50% 0px' })
    .mouseover(function() {
        $(this).stop()})
    .mouseout(function() {
        $(this).stop()
    });

  // This makes the whole navbar li clickable. Awesome. 
  $("ul#navbar li").css("cursor", "pointer").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
  });
  
  //This is for the addition of the omega class to the last member of the footer UL
  $('ul.footer_bar > li:last').addClass('omega');
  
  // This is for the scrolling-slider effect in the portfolio area.
  
    var $panels = $('div.case_study');
    var $container = $('folio_disp');
    var horizontal = false;

    if (horizontal) {
      $panels.css({
        'float' : 'left',
        'position' : 'relative'
      });
      if ($panels !== undefined) {
        $container.css('width', $panels[0].offsetWidth * $panels.length);
      }
    }
    
    var $scroll = $('div.folio_disp').css('overflow', 'hidden');
    
    function selectNav() {
      $(this)
        .parents('ul:first')
          .find('a')
            .removeClass('selected')
          .end()
        .end()
        .addClass('selected');
    }
    
    $('#folio_nav .thumbs').find('a').click(selectNav);
    

    function trigger(data) {
      var el = $('#folio_nav .thumbs').find('a[href$="' + data.id + '"]').get(0);
      selectNav.call(el);
    }
    
    if (window.location.hash) {
      trigger({ id : window.location.hash.substr(1) });
    } else {
      $('ul.thumbs a:first').click();
    }

    var offset = parseInt((horizontal ? 
      $container.css('paddingTop') : 
      $container.css('paddingLeft')) 
      || 0) * -1;
    
    
    var scrollOptions = {
      target: $scroll, 
      items: $panels,
      navigation: '.thumbs a',
      axis: 'xy',
      onAfter: trigger,
      offset: offset,
      duration: 500,
      easing: 'swing'
    };

    $('#folio_disp').serialScroll(scrollOptions);

    $.localScroll(scrollOptions);

    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);
  
});

//This is the image replacement for the Fonts on the page.
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4');
Cufon.replace('h5');
Cufon.replace('h6');
Cufon.replace('div#header h1 a');
Cufon.replace('div#header p');
Cufon.replace('ul#navbar li a');
Cufon.replace('div.post h2');
Cufon.replace('div.post h2 a');
