$(document).ready(function()
{

	$('#example').dataTable( {
		"aoColumns": [
			null, 
			null,
			null,
			null,
			null,
			null,
			null,
			{ "bSortable": false },
			{ "bSortable": false },
			null
			], 
		"bPaginate": true,
		"bProcessing": true,
		"bServerSide": true,
		"iDisplayLength": 25, 
		"bLengthChange": false, 
		"sAjaxSource": "../includes/userlist/server_processing.php"
	} );


	function toggleButtons(scope)
	{
		$(".toggleButton", scope).click(function()
		{
			var menuDiv = $(this).attr("id").replace("Button","");
			$("#"+menuDiv).toggle("fast");
			
			var imageName = $(this).attr("id").replace("Button","Image");
			imageName = $("#"+imageName).attr("src");
			if(imageName == "images/arrow_up_white.png")
			{
				$("#"+menuDiv+"Image").attr("src", "images/arrow_down_white.png");
				$.cookie(menuDiv, 'hidden', { path: '/', expires: 1000 });
			}
			else
			{
				$("#"+menuDiv+"Image").attr("src", "images/arrow_up_white.png");
				$.cookie(menuDiv, null, { path: '/' });
			}
	
			return false;
		});
	}	
	function mailToUpdate()
	{
		$("div#mail_to :text").blur(function(){
			var userid = $("div#mail_to :text").val();
			$("#mail_to").load("includes/mailbox/touser.php?u="+userid, "", function(){
				mailToUpdate();
			});
		}); 
	}	
	function userToUpdate()
	{
		$("div#user_to :text").blur(function(){
			var userid = $("div#user_to :text").val();
			$("#user_to").load("includes/touser.php?u="+userid, "", function(){
				userToUpdate();
			});
		}); 
	}
	
	$.ajaxSetup({
			cache: false
	});
	chatInterval = window.setInterval("chat_caller()",5000);
	window.clearInterval(chatInterval);
	
	var divs = new Array('homeInfo','homeFriends','homeSlaves', 'homeMenu', 'homeStats');
	for(i=0; i<divs.length;i++){
		div = divs[i];
		if($.cookie(div) == "hidden"){
			$("#"+div).hide();
			$("#"+div+"Image").attr("src", "images/arrow_down_white.png");
		}
	}
	
	mailToUpdate();
	toggleButtons();
	userToUpdate();

	$('.rounded').corners();

});

