﻿function LoadJpScript( idJp, idPackage, color, currency, siteUrl )
{
	if ( !currency )
	{
		currency = global.idCurrency;
	}

	if ( !siteUrl )
	{
		siteUrl = global.siteURL;
	}

	var protocol = ( window.location.href.indexOf( "https://" ) != -1 ) ? "https" : "http";
	var	id = "jackpot_" + idJp + "_" + idPackage;
	var url = siteUrl + '/Services/WebInfo/Jackpot/' + idPackage + '/' + idJp + '/' + currency + '/yes';

	document.write( "<div id=" + id + " style='color:" + color.replace( "0x", "#" ) + "'></div>" );

	$.ajax( {
		url: url,
		context: document.getElementById( id ),
		success: function ( value )
		{
			updateJackpotValue( value, $( this ) );
		}
	} );

	setInterval( function ()
	{
		$.ajax( {
			url: url,
			context: document.getElementById( id ),
			success: function ( value )
			{
				updateJackpotValue( value, $( this ) );
			}
		} );
	}, 30000 );
}


function updateJackpotValue( value, container )
{
	container.text( value );
}



function LoadJpMovie(idJp, idPackage, color, currency, siteUrl) {
    id = "jackpot_" + idJp + "_" + idPackage;

    if (!currency) {
        currency = global.idCurrency;
    }

    if (!siteUrl) {

        siteUrl = global.siteURL;
    }

    var protocol = (window.location.href.indexOf("https://") != -1) ? "https" : "http";



    var url = siteUrl + '/Includes/Flash/WebPageJP?' +
		'color=' + color +
		'&currency=' + currency +
		'&fractions=' + 2 +
		'&urlPath=' + escape(siteUrl + '/Services/WebInfo/Jackpot/' + idPackage + '/' + idJp + '/' + currency + '/');

    AC_FL_RunContent(
		'codebase', protocol + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '100%',
		'height', '100%',
		'src', url,
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'exactfit',
		'wmode', 'Transparent',
		'devicefont', 'false',
		'id', id,
		'bgcolor', '#ffffff',
		'name', id,
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess', 'always',
		'movie', url,
		'salign', 'lt');

    // Save object
    window[id] = document.getElementById(id);

}


function LoadJpOdometer( idJp, idPackage, classOdometer, classDigit, currency, siteUrl )
{
	var $this = this;
	var odometer = new Odometer();
	var bInitialized = false;

	if ( !currency )
	{
		currency = global.idCurrency;
	}

	if ( !siteUrl )
	{
		siteUrl = global.siteURL;
	}

	var protocol = ( window.location.href.indexOf( "https://" ) != -1 ) ? "https" : "http";
	var id = "jackpot_" + idJp + "_" + idPackage;
	var url = siteUrl + '/Services/WebInfo/Jackpot/' + idPackage + '/' + idJp + '/' + currency + '/yes';

	//document.write( "<div id=" + id + " style='color:" + color.replace( "0x", "#" ) + "'></div>" );
	document.write( "<div class='" + classOdometer + "' id='" + id + "'>" );
	for ( var i = 0; i < 10; ++i )
	{
		document.write( "<div data-type='digit' class='" + classDigit + "'>1<br/>2</div>" );
	}
	document.write( "</div>" );
	document.write( "<div style='clear:both; width: 0px; height:0px'></div>" );

	$.ajax( {
		url: url,
		context: document.getElementById( id ),
		success: function ( value )
		{
			$this.updateJpVal( value, id, odometer, bInitialized );
			bInitialized = true;
		}
	} );

	setInterval( function ()
	{
		$.ajax( {
			url: url,
			context: document.getElementById( id ),
			success: function ( value )
			{
				$this.updateJpVal( value, id, odometer, bInitialized );
			}
		} );
	}, 30000 );


}

Number.prototype.formatMoney = function ( c, d, t )
{
	var n = this, c = isNaN( c = Math.abs( c ) ) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt( n = Math.abs( +n || 0 ).toFixed( c ) ) + "", j = ( j = i.length ) > 3 ? j % 3 : 0;
	return s + ( j ? i.substr( 0, j ) + t : "" ) + i.substr( j ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + Math.abs( n - i ).toFixed( c ).slice( 2 ) : "" );
};

function updateJpVal( value, hldr, odo, bInitialized )
{

	var sign = value.substr( 0, 1 );
	var diggit = value.substr( 1, value.length - 1 );


	diggit = diggit.replace( /,/g, "" );
	var pointIndex = diggit.indexOf( "." );
	var power = diggit.length - pointIndex - 1;
	var nFragments = Math.pow( 10, power );
	diggit = diggit.replace( /\./g, "" );

	if ( !bInitialized )
	{
		aDigits = $( "#" + hldr + " [ data-type = 'digit']" );

		odo.init( aDigits, sign, nFragments, 20, 50 );
		odo.setInitialValue( diggit );
	}
	else
	{
		odo.updateValue( diggit )
	}
}

