
jQuery(document).ready(function()
{

if ($('#jchess').length != 0)
{

	var pgn_input = jQuery('#jpgn').chess({pgn : jQuery('#pgn').html()});


	jQuery('#jpgn-home').click(function()
	{
		var i = pgn_input.game.transitions.length;
		while (i >= 0)
		{
			i--;
			pgn_input.transitionBackward();
		}
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-rewind').click(function()
	{
		for (var i = 0; i < 10; i++)
		{
			pgn_input.transitionBackward();
		}
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-back').click(function()
	{
		pgn_input.transitionBackward();
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-next').click(function()
	{
		pgn_input.transitionForward();
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-forward').click(function()
	{
		for (var i = 10; i > 0; i--)
		{
			pgn_input.transitionForward();
		}
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-end').click(function()
	{
		var i = 0;
		while (i <= pgn_input.game.transitions.length)
		{
			pgn_input.transitionForward();
			i++;
		}
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-play').click(function()
	{
		var i = 0;
		while (i <= pgn_input.game.transitions.length)
		{
			pgn_input.transitionForward();
			i++;
		}
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

	jQuery('#jpgn-flip').click(function()
	{
		pgn_input.flipBoard();
		return false;
	});

	jQuery(".move").click(function()
	{
		var idMove = $(this).attr("id");
		pgn_input.transitionMoves(idMove);
		jQuery("#jchess-annotation").text( pgn_input.annotation() );
		return false;
	});

}

})