// Random content box

var counter = 1;
function fill_random_box() {
	
	if(counter == 1) var url = "http://amateurgalore.net/index/most_clicked_1?page=week";
	if(counter == 2) var url = "http://amateurgalore.net/index/most_clicked_1?page=month";
	if(counter == 3) var url = "http://amateurgalore.net/index/most_clicked_1?page=year";
	
	// Ajax request
	$("#random_content").load(url);
	
	if(counter == 3) counter = 1;
	else counter++;
}

//setInterval('fill_random_box();',8000);

// Extra search menu

var toggled;

function toggle_extra_search(override) 
{
	var url = '/index/ajax_search';
	var loading = '<center><img src=/images/site/2008/loading_form.gif></center>';
	
	if(toggled != true)
	{
		$(".extra_search").toggle();
		$(".extra_search").html(loading);
		$(".extra_search").load(url);
		toggled = true;
	}
	else if (override == true)
	{
		$(".extra_search").toggle();
		toggled = false;
	}
}

// Logout callback

function callback_logout(v,m)
{
  // get URL from logout element
  var url = $("#logout").attr("url");

  // Logout 
  if(v == true) location.href = url;

}

$(document).ready(function(){
   	
	// Like / hate functions

	$('a[class^=like]').click(function() {
		

		var entry_id = $(this).attr('entry_id');

		$.ajax({
		  url: "/index/ajax_like_or_hate?vote=like&entry_id="+entry_id,
		  cache: false,
		  success: function(data){
			$("#like_result_"+entry_id).html(data);
		  }
		});	

	});

	$('a[class^=dislike]').click(function() {
		
		var entry_id = $(this).attr('entry_id');

		$.ajax({
		  url: "/index/ajax_like_or_hate?vote=dislike&entry_id="+entry_id,
		  cache: false,
		  success: function(data){
			$("#like_result_"+entry_id).html(data);
		  }
		});		

	});

    $("#logout").click(function () {
		$.prompt('Are you really want to logout?',
		{ 
			callback: callback_logout,
			buttons: { Yes: true, No: false}
		});		
	});

});
