/*
 * This file loads param from the url
 * and is also in charge of setting cookie values for the test
 * Dependance on the jquery.cookie.js plugin being loaded
 */
(function($) {
  // plugin code here, use $ as much as you like
  	var __defaultQuestion 	= 1;
  	var __defaultModuleUUID	= "";
  	var __questionPrefix	= "__CURRENTQUESTION_";
  	
  	var CURRENTQUESTION = "TESTCONFIG.CURRENTQUESTION";
  	var TESTVISIBLE		= "TESTCONFIG.TESTVISIBLE_";
  	var TESTSTATE		= "TESTCONFIG.TESTSTATE";
	
	if( !$.cookie( CURRENTQUESTION ) )	$.cookie( CURRENTQUESTION , __defaultQuestion );
	if( !$.cookie( TESTVISIBLE ))		$.cookie( TESTVISIBLE , true );
	if( !$.cookie( TESTSTATE ))			$.cookie( TESTSTATE , "LOGGEDOUT" );//default it to logged out
	$.extend
	(
		{
			testconfig : 
			{
				//properties getters/setters
				currentQuestion	: function( value , moduleUUID )
				{
				  	var sKey	= __questionPrefix + moduleUUID;

				  	if( !$.cookie( sKey ) )
				  	{
				  		$.cookie( sKey , __defaultQuestion );
				  	}
				  	
				  	if( value ) $.cookie( sKey , value ); //set it to the value
				  	return $.cookie( sKey );
				  }
				, testState	: function( value )
				  {
				  	if( value ) $.cookie( TESTSTATE , value ); //set it to the value
				  	return $.cookie( TESTSTATE );
				  }
				, testVisible			: function( uuid , value )
				  {
				  	if( value == true || value == false ) $.cookie( TESTVISIBLE + uuid , value );
				  	return ( $.cookie( TESTVISIBLE + uuid ) == 'true' );
				  }
			}
		}
	); 
})(jQuery);