$(document).ready(function(){
	// start tab section
	
	$('.tabs a').click(function(){
		
		var title = $(this).attr('title');
		if( title == '' ) return true;
		
		var parent = $(this).attr('rel');
		
		$('a[rel=' + $(this).attr('rel') + ']').removeClass('active');
		$(this).addClass('active');
		
		$('.' + parent + ' > *').hide();
		$('#' + $(this).attr('title')).show();
		
		return false;
	});
	//end tab section
	
	//start popup section
	$('#navigation a').click(function(){
		
		var parent = $(this).attr('rel');
		
		$('#' + $(this).attr('title')).show();
		
	});
	
	$('.popup a.close').click(function(){
		$('.popup').hide();
	});
	//end popup section
	
	
	//start popup section
	$('#navigation li a').click(function(){
		
		var parent = $(this).attr('rel');
		
		$('#' + $(this).attr('title')).show();
		
	});
	
	$('.popup a.close').click(function(){
		$('.popup').hide();
	});
	//end popup section
	
	//start paragraph section
	$('.questions p').click(
		function(e){$(this).toggleClass('blue');}
	);
	//end paragraph section
	
	//start info bubble section
	$('.content h2 .info').mouseover(
		function(){$('.infobox').show();}
	);
	$('.content h2 .info').mouseout(
		function(){$('.infobox').hide();}
	);
	//end info bubble section
	
	//start input section
	$('.blink')
		.focus(function(){
			if( $(this).attr('value') == $(this).attr('title') ) {
				$(this).attr({ 'value': '' });
		}
	})
	.blur(function(){
		if( $(this).attr('value') == '' ) {
			$(this).attr({ 'value': $(this).attr('title') })
		}
	});
	//end input section
	
	// Rotating Headings;
	num_headings = $('.rotating-headings h2').length;
	
	$('.next-heading').click(function(){
		current_heading++;
		if( current_heading == num_headings) current_heading = 0;
		_show_heading( current_heading );
		return false;
	});
	
	$('.prev-heading').click(function(){
		current_heading--;
		if( current_heading == -1 ) current_heading = num_headings - 1;
		
		_show_heading( current_heading );
		return false;
	});
	
	_start_anim();
	
});
var current_heading = 0;
var num_headings;
var interval;
function _show_heading( index ) {
	$('.rotating-headings h2').hide();
	$('.rotating-headings h2').eq(index).fadeIn('slow');
}

function _start_anim() {
	interval = window.setInterval(function(){
		current_heading++;
		if( current_heading == num_headings) current_heading = 0;
		
		_show_heading( current_heading );
	}, 4000);
}