

function vote(post_id, size) {
	var cookieName = "penscrappers" + post_id;
	var currentTime = new Date();
	
	var cYear = currentTime.getFullYear();
	
	var cMonth = String(currentTime.getMonth() + 1); // Adding 1 because 0 = January, 11 = December
	if (cMonth < 10) { cMonth = "0" + cMonth; }
	
	var cDay = String(currentTime.getDate());
	if (cDay < 10) { cDay = "0" + cDay; }
	
	var cHour = String(currentTime.getHours());
	if (cHour < 10) { cHour = "0" + cHour; }
	
	var cMinute = String(currentTime.getMinutes());
	if (cMinute < 10) { cMinute = "0" + cMinute; }
	
	var cSecond = String(currentTime.getSeconds());
	if (cSecond < 10) { cSecond = "0" + cSecond; }
	
	var timestamp = cYear + "-" + cMonth + "-" + cDay + " " + cHour + ":" + cMinute + ":" + cSecond;
		
	// Check for existing cookie
	if ($.cookie(cookieName) != null) {
		alert("You have already voted for " + $.cookie(cookieName));
		$("#vote"+post_id).html("There was something wrong with voting");
	} else {
		// Set cookie
		$.cookie(cookieName, timestamp, { expires: 365*5, path: "/" } );
		
		// Test cookie
		$.getJSON("http://www.penscrappers.com/wp/wp-content/themes/penscrappers/vote.php", { post_id: post_id, cookieName: cookieName, timestamp: timestamp, randomizer: "20061363" }, function(json){
			
			if (json.response == "vote success") {
				$("#vote"+post_id).html("<img src=\"http://www.penscrappers.com/wp/wp-content/themes/penscrappers/img/season/vote-thanks-" + size + ".gif\" alt=\"Thanks\" />");
			} else {
				alert("There was a problem casting your vote. Make sure you have cookies turned on.");
			}
			
		});
	}
}


