$(document).ready(function(){

  $('#nav_main li')
	.css( {backgroundPosition: "100% bottom"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(50% bottom)"}, 
			{duration:200})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(100% bottom)"}, 
			{duration:100})
		})

  $('.text_tiles a')
	.css( {backgroundPosition: "0 -40px"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 -300px)"}, 
			{duration:600})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 0)"}, 
			{duration:500})
		})

  $(".slidetabs").tabs(".slides > div", {
  	effect: 'fade',
  	fadeOutSpeed: 1000,
  	fadeInSpeed: 1000,
  	rotate: true,
  	history: true
  }).slideshow();
  
  var api = $(".slidetabs").tabs()
  
  //set the backward and forwards buttons
  api.onClick(function(index) {
      setForwardBackward();
  });

});

function setForwardBackward(){

    var api = $(".slidetabs").tabs();

    var index = api.getIndex();      //active tab index
    var last = api.getTabs().length; //# of tabs
    var theTabs = api.getTabs();     //tabs

    var fIndex,bIndex = 0;

    if (index == 0)
    {   //start of tabs, wrap around
        fIndex = index + 1;
        bIndex = last - 1;
    }
    else if ((index + 1) == last)
    {   //end of tabs, wrap around
        fIndex = 0;
        bIndex = index - 1;
    }
    else
    {   //middle of tabs
        fIndex = index + 1;
        bIndex = index - 1;
    }

    //gets and sets the href values
    var forward  = theTabs.eq(fIndex).attr('href');
    var backward = theTabs.eq(bIndex).attr('href');
    $("a.forward").attr('href',forward);
    $("a.backward").attr('href',backward);
}
