$(document).ready(function () {
	var order = location.hash;
	if (order != null && order != '') {
		if (order.match(/questions/i)) {
			if (order.match(/latest/i)) {
				showQuestionsLatest();
			} else if (order.match(/noAnswer/i)) {
				showQuestionsNoAnswer();
			} else if (order.match(/popular/i)) {
				showQuestionsPopular();
			}
		}
		
		if (order.match(/answers/i)) {
			if (order.match(/latest/i)) {
				showAnswersLatest();
			} else if (order.match(/rating/i)) {
				showAnswersRating();
			}
		}
	}
});

function showQuestionsLatest()
{
	if (!$('#questionsLatestSpan').hasClass('current')) {
		$('#questionsLatestSpan').addClass('current');
		$('#questionsNoAnswerSpan').removeClass();
		$('#questionsPopularSpan').removeClass();
		
		$('#questionsLatestDiv').show();
		$('#questionsNoAnswerDiv').hide();
		$('#questionsPopularDiv').hide();
		
		$('#questionsLatestPaginate').show();
		$('#questionsNoAnswerPaginate').hide();
		$('#questionsPopularPaginate').hide();
		
		location.hash = '#questions/latest/';
	}
}

function showQuestionsNoAnswer()
{
	if (!$('#questionsNoAnswerSpan').hasClass('current')) {
		$('#questionsLatestSpan').removeClass();
		$('#questionsNoAnswerSpan').addClass('current');
		$('#questionsPopularSpan').removeClass();
		
		$('#questionsLatestDiv').hide();
		$('#questionsNoAnswerDiv').show();
		$('#questionsPopularDiv').hide();
		
		$('#questionsLatestPaginate').hide();
		$('#questionsNoAnswerPaginate').show();
		$('#questionsPopularPaginate').hide();
		
		location.hash = '#questions/noAnswer/';
	}
}

function showQuestionsPopular()
{
	if (!$('#questionsPopularSpan').hasClass('current')) {
		$('#questionsLatestSpan').removeClass();
		$('#questionsNoAnswerSpan').removeClass();
		$('#questionsPopularSpan').addClass('current');
		
		$('#questionsLatestDiv').hide();
		$('#questionsNoAnswerDiv').hide();
		$('#questionsPopularDiv').show();
		
		$('#questionsLatestPaginate').hide();
		$('#questionsNoAnswerPaginate').hide();
		$('#questionsPopularPaginate').show();
		
		location.hash = '#questions/popular/';
	}
}

function showAnswersLatest()
{
	if (!$('#answersLatestSpan').hasClass('current')) {
		$('#answersLatestSpan').addClass('current');
		$('#answersRatingSpan').removeClass();
		
		$('#answersLatestDiv').show();
		$('#answersRatingDiv').hide();
		
		$('#answersLatestPaginate').show();
		$('#answersRatingPaginate').hide();

		location.hash = '#answers/latest/';
	}
}

function showAnswersRating()
{
	if (!$('#answersRatingSpan').hasClass('current')) {
		$('#answersLatestSpan').removeClass();
		$('#answersRatingSpan').addClass('current');
		
		$('#answersLatestDiv').hide();
		$('#answersRatingDiv').show();
		
		$('#answersLatestPaginate').hide();
		$('#answersRatingPaginate').show();
		
		location.hash = '#answers/rating/';
	}
}