jQuery.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

var week = 1;
var page = 0;
var nation = -1;
var series = -1;
var more = 0;

function getFullRanking() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 1, page: page, perpage: 20, week: week, nation: nation, series: series}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
             jQuery(".pointsajax").colorbox({title:' '});
         }
     });
     
     
}

function simpleTop() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
         }
     });
}

function homeTop() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 2, perpage: 10, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
         }
     });
}

function smallTop() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 3, perpage: 5, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
         }
     });
}

function profileHighlight(driver) 
{
	if(more == 0)
	{
		//default
		var per = 5
		more = per;
	}
	else
	{
		var per = more;
	}
	
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 11, perpage: per, week: week, driver: driver}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
         }
     });
}

function simpleSeries(series) 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 4, perpage: 5, series: series, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#seriescontent').html(response);
         }
     });
}

function movers(positive) 
{
	if(positive)
	{
		var type = 5;
	}
	else
	{
		var type = 6;
	}
	
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : type, perpage: 10}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
         }
     });
}

function nationTop() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 7, perpage: 5, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#nationcontent').html(response);
         }
     });
}

function nationFull() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 8, page: page, perpage: 20, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
             jQuery(".pointsajax").colorbox({title:' '});
         }
     });
}

function seriesTop() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 9, perpage: 5, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#series-content').html(response);
         }
     });
}

function seriesFull() 
{
     jQuery.ajax({
         url: '/rankings/rankings.php',
         dataType: "html",
         type: "GET",
         data: ({type : 10, page: page, perpage: 20, week: week}),
         success: function(response) 
         {
             // update element
             jQuery('#rankcontent').html(response);
             jQuery(".pointsajax").colorbox({title:' '});
         }
     });
}

function resetFilters()
{
	nation = -1;
	series = -1;
	resetPage();
	resetWeek();
}

function nationFilter()
{
	nation = jQuery('#select-nationality').val();
	resetPage();
	getFullRanking();
}

function setNation(nationId)
{
	nation = nationId;
	resetPage();
	getFullRanking();
}

function setSeries(seriesId)
{
	series = seriesId;
	resetPage();
	getFullRanking();
}

function seriesFilter()
{
	series = jQuery('#select-series').val();
	resetPage();
	getFullRanking();
}

function toggleOtherRankings()
{
	jQuery(".medium-alt").slideToggle("slow");
}

function pageForward()
{
	page++;
}

function pageBack()
{
	page--;
}

function setPage(newPage)
{
	page = newPage;
}

function resetPage()
{
	page = 0;
}

function lastWeek()
{
	week = 2;
}

function thisWeek()
{
	week = 1;
}

function resetWeek()
{
	week = 1;
}

function showMore(manyMore)
{
	more+=manyMore;
}

function redirect(url)
{
	window.location = url;
}

function openCountry(form) 
{ 
	var newIndex = jQuery("#select-country option:selected").val(); 

	if ( newIndex == 0 ) 
	{ 
		alert( "Please select a country!" ); 
	} 
	else 
	{ 
		cururl = jQuery("#select-country option:selected").val(); 
		window.open( cururl, 'newwindow' );  
	} 
}

function setCompName(driver)
{
	$("#driver").attr("value", driver);
}

function setCompareName(driver)
{
	$("#compname").attr("value", driver);
}
