function rankingsByDate(){	
	   $.post("/pocketfives/rankings.php", { date: $("#rankingsDate option:selected").val() },
	   function(data){
		   $("#content").html(data);
	   });
}

function showSortableLocation(countryID, regionID, cityID) {
	$.cookie("countryID", countryID, { path: '/' });
	$.cookie("regionID", regionID, { path: '/' });
	$.cookie("cityID", cityID, { path: '/' });
	window.location.href = '/pocketfives/sortablerankings.php';
}

function playPodcast(filename, action) {
    // If there is already a podcast being played... just changes the URL
    if ((window.parent != null) && (window.parent != window) && (window.parent.frames["podcastFrame"] != null))
    {
        window.parent.frames["podcastFrame"].location = "/pocketfives/browseandpodcast.php?reference=" + filename;
    }
    else
    {
    	$.post(action, { reference: filename }, function(data){
    		window.location.href = action;
    	});
	    
	}
}
function addMeToContest(vcid, vuid){
	$.post("/pocketfives/contests.php", { cid: vcid, uid: vuid },
	   function(data){
		if(data == "true"){
			$("#addCakeName").show();
			$("#AddCakeNameSection").hide();
			location.reload();
		}else{
			alert("Opps please try again.");
		}
	});
	
};

function updateCakeName(vuid){
	
	if($("#new_name").val() == ""){
		alert("Please write your Cake Poker username.");
		$("#new_name").focus();
	}else{
		$.post("/pocketfives/contests.php", { uid: vuid, name: $("#new_name").val() }, function(data){
			if(data == "true"){
				$("#addCakeName").hide();
				$("#AddCakeNameSection").hide();
				$("#getRakeBack").hide();
				location.reload();
			}else{
				alert("Opps please try again.");
			}
	});
		
		
	}
	
	
}

/*$(function() {
	if($('#slideshow').html() != null){
	    $('#slideshow').before('<div id="nav_rotator">').cycle({
	        fx:     'none',
	        speed:  'slow',
	        timeout: 5000,
	        pager:  '#navigation_rotator',
	        pagerAnchorBuilder: function(idx, slide) {
	            return '<div class="ads_thumb"><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></div>';
	        }
	    });
	}
});*/


$(document).ready(function($){
	$("#calculateplb").click(function(){
		$("#PLBScore").html('<font color="#990000"><strong>' + (Math.round(Math.pow(parseFloat($("#prizePool").val()), .5) / Math.pow(parseFloat($("#placeFinished").val()), .6) * 100) / 100) + '</strong></font>');
	});
	$("#sortableCountries").change(function(){
		$("#getSortableResults").attr("disabled", "true");
		$("#sortableCountries").attr("disabled", true);
		$('#sortableRegions').attr("disabled", true); 
		$('#sortableCities').attr("disabled", true); 
		$("#sortableRegions").empty();
		$("#sortableCities").empty();
		$("#sortableRegions").append($('<option></option>').html("Loading..."));
		 
		 $.getJSON("/pocketfives/sortablerankings.php", { cid: $("#sortableCountries option:selected").val() },
				   function(data){
						$("#sortableRegions").empty();
						$.each(data.items, function(i,item){
							$("#sortableRegions").append(
									$('<option></option>').val(item.Value).html(item.Name)
							);
				          });
						
						 $("#sortableCountries").removeAttr("disabled");
						 
						 if ($("#sortableCountries option:selected").val() != '')
							 $('#sortableRegions').removeAttr("disabled");
						 
						 $("#getSortableResults").removeAttr("disabled");
					});
	});

	$("#sortableRegions").change(function(){

		$("#getSortableResults").attr("disabled", "true");
		$("#sortableCountries").attr("disabled", true);
		$('#sortableRegions').attr("disabled", true); 
		$('#sortableCities').attr("disabled", true); 
		$("#sortableCities").empty();
		$("#sortableCities").append($('<option></option>').html("Loading..."));
		
		$.getJSON("/pocketfives/sortablerankings.php", { rid: $("#sortableRegions option:selected").val(), cid: $("#sortableCountries option:selected").val() },
				   function(data){
						$("#sortableCities").empty();
						$.each(data.items, function(i,item){
							$("#sortableCities").append(
									$('<option></option>').val(item.Value).html(item.Name)
							);
				          });

						 $("#sortableCountries").removeAttr("disabled"); 
						 $('#sortableRegions').removeAttr("disabled");  

						 if ($("#sortableRegions option:selected").val() != '')
							 $('#sortableCities').removeAttr("disabled");
						 
						 $("#getSortableResults").removeAttr("disabled");
		 		});
	});
	$("#getSortableResults").click(function(){
		$("#getSortableResults").attr("disabled", "true");
		var vcid   = ($("#sortableCountries option:selected").val() != null) ? $("#sortableCountries option:selected").val() : "";  
		var vrid   = ($("#sortableRegions option:selected").val() != null) ? $("#sortableRegions option:selected").val() : "";
		var vcity  = ($("#sortableCities option:selected").val() != null) ? $("#sortableCities option:selected").val() : "";
		var vmonth = ($("#sortableMonthlyMonths option:selected").val() != null) ? $("#sortableMonthlyMonths option:selected").val() : "";
		var vyear  = ($("#sortableYears option:selected").val() != null) ? $("#sortableYears option:selected").val() : "";	
		 $.post("/pocketfives/sortablerankings.php", { cid: vcid, rid: vrid, city: vcity, format: $("#sortableFormats option:selected").val(), year: vyear, month: vmonth },
			   function(data){
			 	   $("#resultsContent").html(data);
			 	   $("#getSortableResults").removeAttr("disabled");
			   });
	});
	  
	$("#sortableFormats").change(function(){
		if($("#sortableFormats option:selected").val() == "sd"){
			$("#sortableMonthlyMonths").hide();
			$("#sortableYears").hide();
			$("#slidingDate").show();
		}else if($("#sortableFormats option:selected").val() == "mt"){
			$("#slidingDate").hide();
			$("#sortableMonthlyMonths").show();
			$("#sortableYears").show();
		}else if($("#sortableFormats option:selected").val() == "yl"){
			$("#sortableMonthlyMonths").hide();
			$("#slidingDate").hide();
			$("#sortableYears").show();
		}
	});
	$("#addCakeName").click(function(){
		$("#addCakeName").hide();
		$("#getRakeBack").hide();
		$("#notsigned").hide();
		$("#AddCakeNameSection").fadeIn("fast");
	});
	
});





