Tabs = function (local_conf)
{
    if (typeof jQuery === 'undefined')
    {
         throw 'Tabs exception: jQuery not found.';
    }

	// input params
    var conf = {};
    
    conf.boxId = null;
	conf.cLang = null;
    
	/**
	 * @param {Object} data
	 */
    var init = function (local_conf)
    {
		conf = jQuery.extend(conf, local_conf);
		
		//
        init = function () { };

		jQuery( '#' + conf.boxId + ' ul.tabs li' ).click( function()
		{
			var tabId = this.id;

			removeActive();

			if( tabId == 'g5' )
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#' + tabId + ' span' ).addClass( 'activeLast' );
			}
			else
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#' + tabId + ' span' ).addClass( 'active' );
			}

			jQuery( '#' + conf.boxId + ' div.' + tabId ).show();
			jQuery( '#' + conf.boxId + ' div.listPages li.' + tabId ).addClass( 'active' );
		});

		jQuery( '#' + conf.boxId + ' div.listPages li.number' ).click( function()
		{
			var gameNumber = this.className[1];

			removeActive();

			if( gameNumber == '5' )
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + gameNumber + ' span' ).addClass( 'activeLast' );
			}
			else
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + gameNumber + ' span' ).addClass( 'active' );
			}

			jQuery( '#' + conf.boxId + ' div.g' + gameNumber ).show();

			jQuery( this ).addClass( 'active' );
		});

		jQuery( '#' + conf.boxId + ' div.listPages li.prev' ).click( function()
		{
			var tabActiveClass = jQuery( '#' + conf.boxId + ' div.listPages ' ).find('li.active').attr('class');
			var activeGameNumber = tabActiveClass[1];
			var prevValue = null;

			if( activeGameNumber == '1' )
			{
				prevValue = 5;
			}
			else
			{
				prevValue = parseInt( activeGameNumber ) - 1;
				prevValue = prevValue + '';
			}

			removeActive();
			
			if( activeGameNumber == '5' )
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + prevValue + ' span' ).addClass( 'activeLast' );
			}
			else
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + prevValue + ' span' ).addClass( 'active' );
			}

			jQuery( '#' + conf.boxId + ' div.g' + prevValue ).show();
			jQuery( '#' + conf.boxId + ' div.listPages li.g' + prevValue ).addClass( 'active' );
		});

		jQuery( '#' + conf.boxId + ' div.listPages li.next' ).click( function()
		{
			var tabActiveClass = jQuery( '#' + conf.boxId + ' div.listPages ' ).find('li.active').attr('class');
			var activeGameNumber = tabActiveClass[1];
			var nextValue = null;

			console.log(tabActiveClass);

			if( activeGameNumber == '5' )
			{
				nextValue = 1;
			}
			else
			{
				nextValue = parseInt( activeGameNumber ) + 1;
				nextValue = nextValue + '';
			}

			removeActive();

			if( activeGameNumber == '5' )
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + nextValue + ' span' ).addClass( 'activeLast' );
			}
			else
			{
				jQuery( '#' + conf.boxId + ' ul.tabs li#g' + nextValue + ' span' ).addClass( 'active' );
			}

			jQuery( '#' + conf.boxId + ' div.g' + nextValue ).show();
			jQuery( '#' + conf.boxId + ' div.listPages li.g' + nextValue ).addClass( 'active' );
		});
    };

	var removeActive = function()
	{
		jQuery( '#' + conf.boxId + ' div.listPages li' ).removeClass( 'active' );

		jQuery( '#' + conf.boxId + ' ul.tabs li span' ).removeClass( 'active' );
		jQuery( '#' + conf.boxId + ' ul.tabs li span' ).removeClass( 'activeLast' );
		jQuery( '#' + conf.boxId + ' div.game' ).hide();
	}

    jQuery(document).ready(
	    function ()
	    {
	        init(local_conf);
	    }
    );
}
