/* == Terms Hover Javascript == */
/**
 * A Terms object
 *
 * @param string closeCallbackFunction	a callback function (or function name) to utilise when closing the share options hover
 */
var Terms = function( closeCallbackFunction )
{
	var _closeCallbackFunction;


	/**
	 * Initialisation
	 *
	 * @param string closeCallbackFunction	a callback function (or function name) to utilise when closing the share options hover
	 */
	this.init = function( closeCallbackFunction )
	{
		_closeCallbackFunction = closeCallbackFunction;
	}

	/**
	 * Displays the hover for the share options
	 *
	 * @param string type	'competition'|'use'
	 */
	this.show = function( type )
	{
		var self = this;

		$('#hoverContainer').load('/lead/hover/terms/' + type, function()
		{
			// Center the container using the jquery.center plugin
			// http://andreaslagerkvist.com/jquery/center/
			//$("#hoverContainer").center();
			centerPanel($("#hoverContainer"));

			// Fade in the container for the form
			$('#hoverContainer').fadeIn('fast', function()
			{
				// Make the terms content scrollable
				$('#termsContent').jScrollPane({scrollbarWidth:39, scrollbarMargin:10, topCapHeight: 16, bottomCapHeight: 16, dragMaxHeight: 52});

				// Cause the heading to be redrawn for the sake of IE6
				$('#termsContainer h2').css('margin-left', '0px');

				// Ensure the close button closes the hover
				$("#btnCloseTermsOfUse, #btnCloseTermsAndConditions").click( function()
				{
					self.close();
				});

			});
		});
	}

	/**
	 * Closes the Share Options hover
	 */
	this.close = function()
	{
		$('#hoverContainer').fadeOut('fast', function()
		{
			$('#hoverContainer').empty();

			// Issue the callback function if exists
			if( typeof _closeCallbackFunction == 'function' )
			{
				_closeCallbackFunction();
			}
		});
	}


	// Initialise
	this.init(closeCallbackFunction);
}
