$(document).ready(function(){
	
	$(window).bind( 'hashchange', function(e) {
		
		$('.tabs').each(function(e){
			
			if($(this).children('li').children('a[href="'+window.location.hash+'"]').length > 0)
			{
				$(this).children('li').removeClass('active');
				active_tab = $(this).children('li').children('a[href="'+window.location.hash+'"]').parents('li').addClass('active').children('a').attr('href');
				$(this).next('.tab-views').children(active_tab).show().siblings().hide();
			}
			else
			{
				active_tab = $(this).children('li:first').addClass('active').children('a').attr('href');
				$(this).next('.tab-views').children(active_tab).show().siblings().hide();
			}
			
		});
		
	});
	
	$(window).trigger( 'hashchange' );
	
	$('.tabs a').click(function(){
		if($(this).parent('li').hasClass('active')){
			return false;
		}
		
		active_tab = $(this).attr('href');
		$(this).parents('.tabs').children('li').removeClass('active');
		$(this).parent('li').addClass('active');
		$(this).parents('.tabs').next('.tab-views').children(active_tab).show().siblings().hide();
		var loc = document.documentElement.scrollTop;
		window.location.hash = active_tab.replace('#', '');
		$(document).scrollTop(loc);
		return false;
	});
	
});
