jQuery.noConflict();

var currentTab = 0;
var numTabs;
var autoRotate;

jQuery(document).ready(function() {
	// fix z-index for ie6/ie7
	jQuery('.tabbed_content .tabs').css('z-index','20');
	jQuery('.tabbed_content .slide_content').css('z-index','10');

	jQuery(".tab_item").mouseover(function() {
		window.clearInterval(autoRotate);
		currentTab = jQuery(".tab_item").index(jQuery(this));
		var background = jQuery(this).parent().parent().find(".moving_bg");
		jQuery(background).stop().animate({
			left: jQuery(this).position()['left']
		}, {
		duration: 1500
		});
		slideContent(jQuery(this));
	});

	numTabs = jQuery(".tab_item").length;
	autoRotate = setInterval('rotateContent()', 7000);
});

function slideContent(obj) {
  // incorrect width in ie6/ie7 for now hardcoded
  var margin = 526; //jQuery(obj).parent().parent().parent().find(".slide_content").width();
  margin = margin * (jQuery(obj).prevAll().size()-1);
  margin = margin * -1;

  jQuery(obj).parent().parent().parent().find(".tabslider").stop().animate({
    marginLeft: margin + "px"
  }, {
    duration: 1500
  });
}

function rotateContent() {
  var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
  var objectTab = jQuery(".tab_item").get(nextTab);
  currentTab = nextTab;

  var background = jQuery(objectTab).parent().parent().find(".moving_bg");

  jQuery(background).stop().animate({
    left: jQuery(objectTab).position()['left']
  }, {
    duration: 1500
  });

  slideContent(jQuery(objectTab));
}

