/*
 * Jquery library - Rigorix CORE
 */

var action_queue = [];
var win = false;

jQuery(document).ready(function(){
	
	/* Create Dialog */
	win = jQuery("<div></div>").dialog({
		autoOpen: false,
		modal: true,
		title: "Rigorix",
		maxWidth: '1000',
		resizable: false,
		buttons: {
			"Chiudi": function() {
				win.dialog("close");
			}
		}
	});
	jQuery(win).dialog( "option", "height", "auto" );
	jQuery(win).dialog( "option", "width", "auto" );
	
	jQuery(".rx-ui-button").button();
	jQuery(".rx-page-loader").each(function() {
		jQuery(this).attr("page-ref", jQuery(this).attr("href"));
		jQuery(this).removeAttr("href").css("cursor", "pointer");
		jQuery(this).click(function() {
			Game.loadStaticPageDialog(jQuery(this).attr("page-ref"), { title: jQuery(this).attr("title")}, function(xhr) {
				if (jQuery(win).find('.static-page-dialog-content h1').size() > 0) 
					jQuery(win).dialog( "option", "title", jQuery(win).find('.static-page-dialog-content h1').html());
				jQuery(win).find('.static-page-dialog-content h1').remove();
			});
			return false;
		});
	});
	
	jQuery('strike').each(function() {
		jQuery(this).parent("a").removeAttr("href").click(function() {
			jQuery(win).html("Impossibile lanciare la sfida!<br /><br /><strong>Utente già sfidato.</strong><br /><br />Aspetta la fine del campionato in corso.").dialog("open");
		});
	});

	if (jQuery(action_queue).size() > 0) 
		jQuery(action_queue).each(function() {
			(jQuery(this))();
		});
	
	/* Set external link */
	jQuery(".external-link").click(function() {
		Game.loadStaticPageDialog(jQuery(this).attr("href"));
		return false;
	});
	
	jQuery (".rx-username").bind ("contextmenu", function(el) {
		jQuery(document).append (jQuery('<div class="user-menu">asdads</div>'));
		jQuery(".user-menu").position ();
		return false;
	});
	
	/* Game loaded */
	jQuery(".rx-loading-panel-progress").progressbar({ value: 90 });
	setTimeout(function() {
		jQuery(".rx-loading-panel").remove();
		jQuery("#page").removeClass("rx-loading");
	}, 300);
	
});

var Game = {
		
	loadStaticPageDialog: function(page, options, callback)
	{
		jQuery(win).load (page, function() {
			jQuery(win).html(jQuery('<div class="static-page-dialog-content">' + jQuery(win).find(".staticPage").html() + '</div>'));
			jQuery(win).dialog( "option", "width", 670 );
			jQuery(win).dialog( "option", "height", 500 );
			if (options != null) 
				jQuery(win).dialog( "option", options );
			jQuery(win).dialog( "open" );
			if (callback)
				(callback)();
		});
	}
		
}

function viewLastPlayoff(id_playoff) 
{
	jQuery(win).html('<iframe width="645" height="430" src="responders/view_playoff.php?id_playoff=' + id_playoff + '"></iframe>');
	jQuery(win).dialog( "open" );
}


function viewPlayoffByDate ( date ) 
{
	jQuery(win).html('<iframe width="645" height="430" src="responders/view_playoff.php?date=' + date + '"></iframe>');
	jQuery(win).dialog( "open" );
}

function vediFotofinish(data) 
{
	jQuery(win).html('<iframe width="480" height="460" src="responders/vedi_fotofinish.php?data=' + data + '"></iframe>');
	jQuery(win).dialog( "open" );
}

function vediArchivioCampionati()
{
	jQuery(win).html('<iframe width="480" height="460" src="responders/archivioCampionati.php"></iframe>');
	jQuery(win).dialog( "open" );
}





