	var activeOddsCalcChooserChoice = 'choice1';
	jQuery(document).ready(function(){
		jQuery('#chooser li a').click(function(event){
				var idParts = this.id.split('-', 2);
				showOddsCalcChooserChoice(idParts[0]);
				return false;
			}
		)

		var tmr = setInterval(function(){
			jQuery('#canvas-odds-calc-choice').removeClass('hide');
			jQuery('#canvas-loading').addClass('hide');
		}, 500);
	});

	function showOddsCalcChooserChoice(choiceID) {
		if (activeOddsCalcChooserChoice == choiceID) {
			return;
		}

		activeOddsCalcChooserChoice = choiceID;
		jQuery('#chooser li a').each(function(i){
			var idParts = this.id.split('-', 2);

			jQuery('#' + idParts[0]).addClass('hide');
			jQuery('#' + this.id).removeClass('active');
		});

		jQuery('#' + activeOddsCalcChooserChoice).removeClass('hide');
		jQuery('#' + activeOddsCalcChooserChoice + '-link').addClass('active');
	}

	function regenerateOddsCalcCode() {
		jQuery('#frm_code').addClass('hide');
		generateOddsCalcCode();
	}

	var generatedOddsCalcCodes = new Array();
	function generateOddsCalcCode() {
		var skins = new Array('', '390x320', '200x500', '556x122');
		var userEmail = jQuery('#user_e_mail').val();
		var userWeb = jQuery('#user_web').val();
		var skin = skins[activeOddsCalcChooserChoice.replace(/choice/, '')];

		if (userEmail == '') {
			alert(STR['enter_email']);
			return false;
		}
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(userEmail)) {
			alert(STR['enter_valid_email']);
			return false;
		}
		if (userWeb == '') {
			alert(STR['enter_website']);
			return false;
		}

		if (generatedOddsCalcCodes[skin]) {
			jQuery('#gen_code').val(generatedOddsCalcCodes[skin]);
			jQuery('#frm_loading').addClass('hide');
			jQuery('#frm_code').removeClass('hide');
			return;
		}

		jQuery('#frm_loading').removeClass('hide');
		jQuery('#frm_generator').addClass('hide');
		jQuery.post(
			document.location.href,
			{
				event: "widgets.odds_calculator#generate_odds_calc",
				email: userEmail,
				website: userWeb,
				skin: skin
			},
			function(response) {
				if (!response) {
					return;
				}
				var hash = response;
				var oddsCalcCode = getOddsCalcHTML(hash, skin, '', STR['lang'], 2);
				generatedOddsCalcCodes[skin] = oddsCalcCode;
				jQuery('#gen_code').val(oddsCalcCode);
				jQuery('#frm_loading').addClass('hide');
				jQuery('#frm_code').removeClass('hide');

		  	}
		);
	}

	function getOddsCalcHTML(hash, skin, promo, lang, version) {
		var codeTemplate = {
			'200x500' : '<style type="text/css">' +
						' #calculator_%HASH%, #calculator_%HASH% .skin200x500, #calculator_%HASH% .text {width: 192px}' +
						' #calculator_%HASH% *, #calculator_%HASH% {border: 0px none}' +
						' #calculator_%HASH% {position: relative; background: #fff}' +
						' #calculator_%HASH% .skin200x500 {height: 50px; position: absolute; top: 5px; left: 5px}' +
						' #calculator_%HASH% .skin200x500 a {font: 11px/150% arial; color: #034EA2; letter-spacing: -1px; text-decoration: none; display: block; margin-top: 3px}' +
						' #calculator_%HASH% .skin200x500 img {border: none; margin-right: 3px; float: left}' +
						' #calculator_%HASH% .text {height: 15px; text-align: center; position: absolute; top: 470px; left: 0px; font: 11px verdana}' +
						' #calculator_%HASH% .text a {font: 11px verdana; color: #034EA2; text-decoration: underline}' +
						'</style>\n' +
						'<div id="calculator_%HASH%">' +
						'<script type="text/javascript" src="%URLJS%"></script>' +
						'<script type="text/javascript">pokernews.widget.OddsCalculator.createFlash( "%HASH%", "200x500", "%PROMOID%", "%LANG%", ' + version + ' );</script>' +
						'<div class="skin200x500"><a href="%HEADIMGURL%" title="%HEADIMGURLTITLE%"><img src="http://www.pokernews.com/i/odds_calculator/skin.200x500.html.logo.jpg" alt="%HEADIMGALT%" /></a><a href="%HEADTXTURL%" title="%HEADTXTTITLE%">%HEADTXT%</a></div>' +
						'<div class="text">%PROMO200500%</div>' +
						'</div>\n' +
						'<noscript>%NOSCRIPT%</noscript>',
			'390x320' : '<style type="text/css">' +
						' #calculator_%HASH%, #calculator_%HASH% .skin390x320 {width: 390px}' +
						' #calculator_%HASH% *, #calculator_%HASH% {border: 0px none}' +
						' #calculator_%HASH% {position: relative; background: #fff}' +
						' #calculator_%HASH% .skin390x320 {height: 50px; position: absolute; top: 5px; left: 5px}' +
						' #calculator_%HASH% .skin390x320 a {font: 15px/140% arial; color: #034EA2; letter-spacing: -1px; text-decoration: none; display: block; margin-top: 3px}' +
						' #calculator_%HASH% .skin390x320 img {border: none; margin-right: 5px; float: left}' +
						' #calculator_%HASH% .text {width: 270px; height: 15px; position: absolute; top: 290px; left: 15px; font: 11px verdana}' +
						' #calculator_%HASH% .text a {font: 11px verdana; color: #034EA2; text-decoration: underline}' +
						'</style>\n' +
						'<div id="calculator_%HASH%">' +
						'<script type="text/javascript" src="%URLJS%"></script>' +
						'<script type="text/javascript">pokernews.widget.OddsCalculator.createFlash( "%HASH%", "390x320", "%PROMOID%", "%LANG%", ' + version + ' );</script>' +
						'<div class="skin390x320"><a href="%HEADIMGURL%" title="%HEADIMGURLTITLE%"><img src="http://www.pokernews.com/i/odds_calculator/skin.390x320.html.logo.jpg" alt="%HEADIMGALT%" /></a><a href="%HEADTXTURL%" title="%HEADTXTTITLE%">%HEADTXT%</a></div>' +
						'<div class="text">%PROMO390320%</div>' +
						'</div>\n' +
						'<noscript>%NOSCRIPT%</noscript>',
			'556x122' : '<style type="text/css">' +
						' #calculator_%HASH% *, #calculator_%HASH% {border: 0px none}' +
						' #calculator_%HASH% {width: 556px; position: relative; background: #fff}' +
						' #calculator_%HASH% .skin556x122 {width: 195px; height: 16px; position: absolute; top: 5px; left: 5px}' +
						' #calculator_%HASH% .skin556x122 a {font: 11px/150% arial; color: #034EA2; letter-spacing: -1px; text-decoration: none; display: block; margin-top: 3px}' +
						' #calculator_%HASH% .skin556x122 img {border: none; margin-right: 3px; float: left}' +
						' #calculator_%HASH% .text {width: 80px; height: 25px; position: absolute; top: 90px; left: 10px; font: 11px/110% verdana}' +
						' #calculator_%HASH% .text a {font: 11px verdana; color: #034EA2; text-decoration: underline}' +
						'</style>\n' +
						'<div id="calculator_%HASH%">' +
						'<script type="text/javascript" src="%URLJS%"></script>' +
						'<script type="text/javascript">pokernews.widget.OddsCalculator.createFlash( "%HASH%", "556x122", "%PROMOID%", "%LANG%", ' + version + ' );</script>' +
						'<div class="skin556x122"><a href="%HEADIMGURL%" title="%HEADIMGURLTITLE%"><img src="http://www.pokernews.com/i/odds_calculator/skin.556x122.html.logo.jpg" alt="%HEADIMGALT%" /></a><a href="%HEADTXTURL%" title="%HEADTXTTITLE%">%HEADTXT%</a></div>' +
						'<div class="text">%PROMO556122%</div>' +
						'</div>\n' +
						'<noscript>%NOSCRIPT%</noscript>\n'
		}

		var defaultCode = '200x500';
		if (codeTemplate[skin]) {
			var code = codeTemplate[skin];
		}
		else {
			var code = codeTemplate[defaultCode];
		}

		code = code.replace(/%HASH%/gi, hash);
		code = code.replace(/%HEADIMGURL%/gi, STR['url_home']);
		code = code.replace(/%HEADIMGURLTITLE%/gi, STR['head_url_title']);
		code = code.replace(/%HEADIMGALT%/gi, STR['head_img_alt']);
		code = code.replace(/%HEADTXTURL%/gi, STR['head_txt_url']);
		code = code.replace(/%HEADTXTTITLE%/gi, STR['head_txt_title']);
		code = code.replace(/%HEADTXT%/gi, STR['head_txt']);
		code = code.replace(/%NOSCRIPT%/gi, STR['text_noscript']);
		code = code.replace(/%PROMO390320%/gi, STR['text_promo_390320']);
		code = code.replace(/%PROMO200500%/gi, STR['text_promo_200500']);
		code = code.replace(/%PROMO556122%/gi, STR['text_promo_556122']);
		code = code.replace(/%URLJS%/gi, STR['url_js']);
		code = code.replace(/%PROMOID%/gi, 'hpromo');
		code = code.replace(/%LANG%/gi, STR['lang']);
		return code;
	}