// -- BEGIN LICENSE BLOCK -------------------------------
//
// This file is part of Guild Roster.
//
// Copyright © 2009 Simon Pottier and contributors
// Licensed under the GPL version 3.0 license
// http://www.gnu.org/licenses/gpl-3.0.html
//
// -- END LICENSE BLOCK ---------------------------------

$(document).ready(function()
{	
	////////////////////////////////////////
	//////////        SCORE       //////////
	////////////////////////////////////////
	$.nyroModalSettings({
		width: 700,
		height: 270,
		minHeight: 0,
		widthFixed: true,
		bgColor: '',
		showBackground: function (elts, settings, callback) {elts.bg.css({opacity:0}).fadeTo(300, 0.4, callback);},
		ajax: {cache:false, contentType:"application/x-www-form-urlencoded; charset=utf-8"},
		endFillContent: function()
		{
			$("#score_table").hide();
		},
		endShowContent: function()
		{
			$("#score_table").show();
			
			$("#score_cont a.modal_char").nyroModal(
			{
				closeButton: '<a href="#" id="backBut" class="get_back">Test</a>',
				width: 700,
				height: 385,
				bgColor: '',
				showBackground: function (elts, settings, callback) {elts.bg.css({opacity:0}).fadeTo(300, 0.4, callback);},
				ajax: {cache:false, contentType:"application/x-www-form-urlencoded; charset=utf-8"},
				endShowContent: function()
				{
					$('.get_back').click(function(e)
					{
						e.preventDefault();
						$.nyroModalManual({url: '?query=score'});
						return false;
					});
					
					$.get("index.php", {query: "3d_model", char: $("#td_3D strong").html()}, function(data)
					{
						$("#cont_3D").html(data);
					});
				}
			});
			
			$('#score_table')
			.tablesorter({sortList: [[4,1]], headers: {1:{sorter: 'digit'}, 2:{sorter: 'digit'}, 3:{sorter: 'digit'}}, widgets: ['zebra']})
			.tablesorterPager({ container: "#score_header .pager", size: $("#score_header .pager .pagesize").attr("value"), positionFixed: false});
			
			// BACKGROUND UPDATE
			$.getJSON("index.php", {query: "score_inf", step: 0}, function(data)
			{
				$("#score_inf").html(data.text);
				if (data.update == "true")
				{
					$.getJSON("index.php", {query: "score_inf", step: 1}, function(data)
					{
						$("#score_inf").html(data.text);
						$('#refresh_score').click(function(e)
						{
							e.preventDefault();
							$.nyroModalManual({url: '?query=score'});
							return false;
						});
					});
				}
			});
		}
	});
	$('.modal_score').click(function(e)
	{
		e.preventDefault();
		$.nyroModalManual({url: '?query=score'});
		return false;
	});
});