$( document ).ready( function()
	{
		/* First, make all the entries in the vote table disappear */
		var vote_table = $( "#vote_table" );
		var hrefLinks = new Object;

		/* remove the links + images */
		vote_table.find( "td > a" ).each( function()
			{
				/* get the name of the img element */
				var imgName = $( this ).children( "img" ).attr( "src" );
                if( imgName != null )
                {
                    hrefLinks[ imgName ] = $( this ).hide();
                    $( this ).remove();
                }
			}
		);

		/* remove the text and just trash it */
		vote_table.find( "td" ).each( function()
			{
				$( this ).text( "" );
			}
		);

		/* the data is now loaded via external JS file */
		try
		{
			for( var index = 0; index < results.length; index++ )
			{
				var column = ( ( index * 2 ) + 1 ) % 10; /* 1, 3, 5, 7, 9 */
				var row = ( index >= 5 )?( 4 ):( 1 );
                /*
                var column = index + 1;
                var row = 1;
                */

				/* put the link BACK into the table */
				var href = hrefLinks[ results[ index ].imgName ];
                href.attr( 'href', 'http://vote.helpconquercancer.ca' + results[ index ].link );
				vote_table.find( "tr:nth-child(" + row + ")" ).find( "td:nth-child(" + column +")" ).append( href );
				href.fadeIn( "slow" );

				/* put the number of votes in too */
				vote_table.find( "tr:nth-child(" + ( row + 1 ) + ")" ).find( "td:nth-child(" + column +")" ).text( results[ index ].votes + " votes" );
			}
		}
		catch( error )
		{
			vote_table.html( "<tr><td align='center'>Unable to retrieve current voting results.  Please try again later.</td></tr>" );
		}
	}
);


