TopList =
{
	init:function()
    {
		this.removeRequirementsLink();
	},

	removeRequirementsLink:function()
    {
		$('p.requirements').remove();
		this.addRequirementsLink();
    },

	addRequirementsLink: function()
    {
		$('.high-roller span.requirements').each(
        function()
        {
			var box = $('div.requirements', this).slideUp();

			$( '<p class="requirements"><a href="#" class="requirements">View requirements</a></p>' ).insertBefore(box).find('a').toggle(function()
            {
				$(this).text('Hide requirements').addClass('hide-req');
				box.slideDown( 300 );
			}, function() {
				$(this).text('View requirements').removeClass('hide-req');
				box.slideUp( 300 );
			}
            );
		});
	}
};

$(document).ready(function()
{
	TopList.init();
});

function showPage( urlStr, targetDivId, getParam, link, callbackOnDone )
{
    changeCurrencyIcon( link );
    $("div#" + targetDivId).fadeTo(100, 0.01);

	ajaxUrlString = "/ajax/" + urlStr  + '.shtml';

	if( getParam )
	{
		ajaxUrlString = ajaxUrlString + "?" + getParam;
	}

    /* If the Currency was changed, change the selected icon */

	$.post( ajaxUrlString, function( data )
    {

        $("div#" + targetDivId).html( data );

        $("div#" + targetDivId ).unbind( "ajaxComplete" );

        $("div#" + targetDivId).ajaxComplete( function( e, xhr, settings )
        {

            $("div#" + targetDivId).fadeTo(500, 1);

			TopList.init();
			
            /* Add sitecatalyst events on urls */
            if(  settings.url == ajaxUrlString )
			{
	           	addClickCountOnLink();
			}

            if(callbackOnDone)
            {
                callbackOnDone();
            }
	 	});

	});
}

/*
 * Changes the currency icon when the user clicks on that icon
 *
 */
function changeCurrencyIcon( link )
{

    if( typeof $(link).parent().parent().attr('class') == 'undefined' )
	{
        return false;
    }
    else if( $(link).parent().parent().attr('class').indexOf("currency-selector") != -1 )
    {
        $('.currency-selector > .selected').removeClass( 'selected' );
        $(link).parent().addClass( 'selected' );
        return true;
    }
}

function addClickCountOnLink()
{	
	ClickTracker.init('#extraContent a');
}
