var check = false;
$(document).ready(function(){
	
	$('.block.blue .expand_close').live('click', function(e){
		e.preventDefault();
		
		var elem = $(this).parent().next().next();
		var block = $(this).parent().parent();
		var text = $(this).next();
		
		openPane(elem, block, text);
	});
	
	$('.block > ul.block_nav > li > a').live('click', function(e) {
		e.preventDefault();
		
		var elem = $(this).parent().parent().next();
		var block = $(this).parent().parent().parent();
		var item = block.children('div.block_content').children('h3');
		var tab = $(this);
		
		selectTab(tab, block);
		openPane(elem, block, item);
	});
	
	$('.block.green .expand_close').live('click', function(e) {
		e.preventDefault();
		
		var elem = $(this).parent().next().next();
		var block = $(this).parent().parent();
		var text = $(this).next();
		
		closePane(elem, block, text);
	});
	
	$('.block.green > div.block_drop_down > a.close_drop').live('click', function(e) {
		e.preventDefault();
		
		var elem = $(this).parent();
		var block = $(this).parent().parent();
		var text = block.children('div.block_content').children('h3');
		
		closePane(elem, block, text);
	});
	
});

function openPane(elem, block, text)
{
	block.animate({color:"white"});
	text.animate({color:"white"});
	block.addClass('green');
	block.removeClass('blue');
	block.children('.green_bg').fadeIn('slow');
	elem.slideDown('normal', function() {
		$(this).children('a').show();
		$('#footer').addClass('matt');
		$('#footer').removeClass('matt');
	});
	
	if(block.attr('id') == $('.block').length) { 
		block.children('ul').removeClass('block_nav2'); 
	}
}

function closePane(elem, block, text)
{
	elem.children('a').hide();
	block.animate({color:"boakgray"});
	block.children('ul.block_nav').children().next('li').children('a.faq').children('span').animate({color:"boakgray"});
	text.animate({color:"boakgray"}, function() {	
		block.removeClass('green');
		block.addClass('blue');
	});
	block.children('.green_bg').fadeOut('slow');
	elem.slideUp('normal', function() {
		$('#footer').addClass('matt');
		$('#footer').removeClass('matt');
	});
	
	if(block.attr('id') == $('.block').length) { 
		block.children('ul').addClass('block_nav2'); 
	}
}

function selectTab(tab, block)
{
	var toShow = tab.attr('href');
	toShow = toShow.substr(1);
	
	block.children('div.block_drop_down').children('div').hide();
	block.children('ul.block_nav').children('li').children('a').removeClass('active');

	block.children('div.block_drop_down').children('div.'+toShow).show();
	
	tab.addClass('active');
}