// when the DOM is ready...
$(window).load(function(){  




var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');

var loop = false;
// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = true;

// float the panels left if we're going horizontal
if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative' // IE fix to ensure overflow is hidden
  });
 
  $container.css('width', $panels[0].offsetWidth * $panels.length);
	
}
var $scroll = $('#slider .scroll');

// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('.navigation').find('a').click(function(){
	selectNav;
	clearInterval(interval);
});

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('.navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  //$('ul.navigation a:first').click();
}

var offset = parseInt((horizontal ? $container.css('paddingTop') : $container.css('paddingLeft')) || 0) * -1;

var scrollOptions = {
  target: $scroll, // the element that has the overflow
  items: $panels,  
  navigation: '.navigation a',
  prev: 'img.left', 
  next: 'img.right',
  axis: 'xy',
  onAfter: trigger, // our final callback
  offset: offset,
  duration: 500,
  easing: 'swing'
};

$('#slider').serialScroll(scrollOptions);
	$.localScroll(scrollOptions);
	scrollOptions.duration = 1;
	$.localScroll.hash(scrollOptions);
	interval = setInterval("banner_animation()", 3000);
});

function banner_animation() {
	if(!$('.left').length > 0 ) {
		$('.right').click();
	}
}
