$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};


var featureCount;
var featureInterval;
var oldFeature = 0;
var currentFeature = 0;

function doRotate(old) {
	if(old){oldFeature = old};
   currentFeature = (oldFeature + 1) % featureCount; 
   $("#feature-screens li:eq(" + oldFeature + ")").fadeOut('slow');
   $('#feature li').removeClass('active');
   $("#feature-screens li:eq(" + currentFeature + ")").fadeIn('slow');
   $('#feature li:eq(' + currentFeature + ')').addClass('active');
   oldFeature = currentFeature;
 }

var featureRotate = function(clicked){
	var whichselected = clicked.attr('id');
	$('#feature-screens li').fadeOut('slow');
	$('#feature-screens li.' + whichselected).fadeIn('slow');
	$('#feature li').removeClass('active');
	clicked.parent().addClass('active');
	var featuresAfter = clicked.parent().nextAll().length
	oldFeature = ((featureCount - featuresAfter)-1);
	clearInterval(featureInterval);
	featureInterval = setInterval('doRotate(oldFeature)',7000)
};
$('#feature li a').click(function(event) {
	var clicked = $(this);
	event.preventDefault();
	featureRotate(clicked);
});

$('a[rel="boxy"]').click(function(event){
	event.preventDefault();
	theSRC = $(this).attr('href');
	theTitle = $(this).text();
	Boxy.load(theSRC, {title: theTitle, modal:true});
})

$('#tabbed-nav li a').click(function(event){
	$('#tabbed-nav li').removeClass('active')
	$(this).parent().addClass('active');
	var whichtab = $(this).attr('href');
	whichtab = whichtab.slice(1);
	$('#content>div').hide();
	$('#'+whichtab).show();
	$('.plan-wrap').equalHeights();
	return false;
});

function oddify(){
	$('.plan-details ul').each(function(){
		$(this).find('li:odd').addClass('odd');
	});
}

$(function(){
	//$('#enterprise-plans').hide();
	$('.plan-wrap').equalHeights();
   featureCount = $("#feature-screens li").size();
   featureInterval = setInterval('doRotate()',5000); //time in milliseconds
   Cufon.replace('#content h2, #content h3, #content h4, #offers table thead th, #offers table tbody th');
   $('table.stripe-me').each(function(){
   	$(this).find('tbody tr:odd').addClass('odd');
   	$(this).find('tbody tr').each(function(){
   		var i = 0;
   		$(this).find('td').each(function(){
   			$(this).addClass('col-'+i);
   			i = i+1
   		});
   	})
   });
 oddify();   
});
