var slideshow_interval;


function get_outer_height(elem) {
	return parseInt($(elem).height()) + parseInt($(elem).css('padding-top').replace('px', '')) + parseInt($(elem).css('padding-bottom').replace('px', ''));
}

$(document).ready(function(){
	var selected_menuitem = $('#featured .tabs .selected');
	var bubble = $('#featured .tabs .bubble');
	var arr = $('#featured .tabs .arrow');

	$("#" + selected_menuitem.attr('id') + "-content").show();

	bubble.animate({
		height: selected_menuitem.height(),
		top: selected_menuitem.position().top
	});
	
	arr.animate({
		top: parseInt(selected_menuitem.position().top + (get_outer_height(selected_menuitem) - 13) / 2) + 'px'
	})
	
	slideshow_interval = window.setInterval(slideSwitch, 10000);
	
	$('#featured .tabs .menuitem').click(function(ev) {
		$('#featured .tabs .menuitem').removeClass('selected')
		var selecteditem=$(this);
		bubble.css("z-index",5);	
		bubble.animate({
			height: $(this).height(),
			top: $(this).position().top
		}, function() {
			//animation complete callback
			bubble.css("z-index",0);	
			selecteditem.addClass('selected');
		  });
		arr.animate({
			top: parseInt($(this).position().top + (get_outer_height($(this)) - 13) / 2) + 'px'
		})
		var box_id = "#" + $(this).attr('id') + "-content";
		$('#featured .container .featured:visible').fadeOut('normal', function() {
			$('#featured .container ' + box_id).fadeIn('normal');
		});

		switch (box_id)
		{
		case "#featured-1-content":
			changeBackground("#89b9eb");
			break;
		case "#featured-2-content":
			changeBackground("#bba589");
			break;
		case "#featured-3-content":
			changeBackground("#c78e77");
			break;
		case "#featured-4-content":
			changeBackground("#e2ce9d");
			break;
		case "#featured-5-content":
			changeBackground("#75aea2");
			break;
		case "#featured-6-content":
			changeBackground("#8e9abb");
			break;
		case "#featured-7-content":
			changeBackground("#accf70");
			break;
		}
	
		if (typeof ev.originalEvent != "undefined") {
			window.clearInterval(slideshow_interval);
			//slideshow_interval = window.setInterval(slideSwitch, 10000);
		}
		return false;
	});
});

function changeBackground(color) 
{
	$("body").animate({ backgroundColor: color }, 'slow');
	$("#topedge").animate({ backgroundColor: color }, 'slow');
}

function slideSwitch() {
	var active = $('#featured .tabs .selected');
	
	if ( active.length == 0 ) {
		active = $('#featured .tabs .menuitem:eq(0)');
	}
	var next =  active.next().length ? active.next() : $('#featured .tabs .menuitem:eq(0)');
	
	next.addClass('selected');
	next.click();
   	active.removeClass('selected');
};


$(document).ready(function(){
    jQuery.validator.addMethod("checkhuman", function(value, element) { return value == "human"; }, jQuery.format("You must type the word human"));
});

