(function($) {
	$.fn.reportprogress = function(val, maxVal, text) {
		var max = 100;
		if (maxVal)
			max = maxVal;
		return this.each(function() {
			var div = $(this);
			var innerdiv = div.find(".progress");
			if (innerdiv.length != 1) {
				innerdiv = $("<div class='progress'></div>");
				div.append("<div class='text'>&nbsp;</div>");
				$("<span class='text'>&nbsp;</span>").css("width",
						div.css("width")).appendTo(innerdiv);
				div.append(innerdiv)
			}
			var width = Math.round(val / max * 100);
			innerdiv.css("width", width + "%");
			if (text) {
				div.find(".text").html(text)
			}
		})
	}
})(jQuery);
(function($) {
    var settings = {
        adWidth: 300,
        adHeight: 250,
        showAd: true,
        forcePreroll: false,
        usePercentsInPreroll: true,
        loadingBar: true,
        fileType: 'swf',
        contentId: '#flashobj',
        preloadId: '#flashobj_mc',
        beforeCallback: null,
        afterCallback: null,
        gameInsertCallback: null,
        skipLinkCallback: null,
        loadingText: "Loading game...",
        afterLoadingText: "Game loaded. Click here to start the game\u2026",
        progressbarText: 'The game will start in %d seconds',
        closeText: 'Close the advertisement and go on to the game.',
        advertisementText: 'Advertisement',
        tickInterval: 200,
        progressTime: 15000,
        showSkipTime: 0,
        barWidth: 300,
        adType: 'iframe',
        adCode: ''
    };
    var percent = 0;
    var timeElapsed = 0;
    var linkShowTimeElapsed = 0;
    var that = this;
    var flashLoadTries = 0;
    var skipTextInserted = false;
    var skipLinkInserted = false;
    var neoedgeAd = false;
    var afterWarning = true;
    var intervalHandle, target, check98PercentHandle, preTimer, preloaderWidth, preloaderHeight, preroll, neoedgeHandler, startPreloaderHandler;
    var showGame = function() {
        if (settings.afterCallback != null) {
            settings.afterCallback.call(that, settings)
        }
        if (settings.fileType != 'swf' || settings.forcePreroll
				|| !settings.showAd) {
            settings.gameInsertCallback.call(that)
        } else {
            $(settings.contentId).css({
                width: preloaderWidth,
                height: preloaderHeight
            })
            if (settings.afterShow != null) {
                settings.afterShow.call(that, settings)
            }
        }
    };
    var cleanupAndShowGame = function() {
        if (intervalHandle != null) {
            clearInterval(intervalHandle);
            intervalHandle = null
        }
        if (neoedgeHandler != null) {
            clearTimeout(neoedgeHandler);
            neoedgeHandler = null
        }
        if (check98PercentHandle != null) {
            clearTimeout(check98PercentHandle);
            check98PercentHandle = null
        }
        if (startPreloaderHandler != null) {
            clearTimeout(startPreloaderHandler);
            neoedgeHandler = null
        }
        if (target != null) {
            target.remove();
            target = null
        }
        if (afterWarning) {
            showGame()
        }
    };
    var insertSkipLink = function(innerText) {
        var a = $('<a href="javascript:void(0);">' + innerText + '</a>');
        if (settings.skipLinkCallback != null) {
            a.click(settings.skipLinkCallback)
        }
        a.click(cleanupAndShowGame);
        $('#ap_skiptext').empty().append(a);
        skipLinkInserted = true
    };
    var skipTextAddOrDecrement = function(afterLoading) {
        skipTextInserted = afterLoading ? false : skipTextInserted;
        if (linkShowTimeElapsed <= 0 && !skipTextInserted) {
            if (preroll) {
                if (!skipLinkInserted) {
                    insertSkipLink(settings.closeText)
                }
            } else if (afterLoading) {
                if (!skipLinkInserted) {
                    insertSkipLink(settings.afterLoadingText)
                }
            } else {
                $('#ap_skiptext').empty().append(settings.loadingText)
            }
            skipTextInserted = true;
            return
        } else if (linkShowTimeElapsed > 0 && !preroll && !afterLoading
				&& !skipTextInserted) {
            $('#ap_skiptext').empty().append(settings.loadingText);
            skipTextInserted = true
        }
        linkShowTimeElapsed -= settings.tickInterval
    };
    var insertAd = function() {
        target.css({
            width: (settings.adWidth + 'px')
        });
        target
				.prepend('<div id="ap_adtext">' + settings.advertisementText + '</div>');
        if (settings.adType == 'iframe') {
            target.append('<div id="ap_adframe"></div>');
            $('#ap_adframe').css({
                width: (settings.adWidth + 'px'),
                height: (settings.adHeight + 'px')
            });
            $('#ap_adframe').append(settings.adCode)
        } else {
            $('#ap_adframe').css({
                width: (settings.adWidth + 'px'),
                height: (settings.adHeight + 'px')
            })
        }
        if (settings.loadingBar && !neoedgeAd) {
            target.append('<div id="ap_progressbar"></div>');
            $('#ap_progressbar').css('width', settings.barWidth + 'px');
            if (preroll && !settings.usePercentsInPreroll) {
                $("#ap_progressbar").reportprogress(
						0,
						100,
						SPI.sprintf(settings.progressbarText, Math
								.ceil(settings.progressTime / 1000)))
            } else {
                $("#ap_progressbar").reportprogress(0, 100, '0%')
            }
        }
        if (!neoedgeAd) {
            target.append('<div id="ap_skiptext"></div>')
        }
        skipTextAddOrDecrement()
    };
    var progressUpdatePreroll = function() {
        timeElapsed += settings.tickInterval;
        percent = Math.round(100 * timeElapsed / settings.progressTime);
        if (settings.usePercentsInPreroll) {
            $("#ap_progressbar").reportprogress(percent, 100, percent + '%')
        } else {
            $("#ap_progressbar")
					.reportprogress(
							percent,
							100,
							SPI
									.sprintf(
											settings.progressbarText,
											Math
													.ceil((settings.progressTime - timeElapsed) / 1000)))
        }
        skipTextAddOrDecrement();
        if (percent >= 100) {
            if (!neoedgeAd) {
                cleanupAndShowGame()
            }
        }
    };
    var check98Percent = function(oldvalue) {
        var loaded = $(settings.preloadId)[0].PercentLoaded();
        if (oldvalue == loaded) {
            if (!neoedgeAd) {
                cleanupAndShowGame()
            }
            if (check98PercentHandle != null) {
                clearTimeout(sometime);
                check98PercentHandle = null
            }
        }
    };
    var progressUpdatePreloader = function() {
        var fromTimer = parseInt((settings.progressTime - preTimer) * 100
				/ settings.progressTime);
        var loaded = $(settings.preloadId)[0].PercentLoaded();
        if (loaded < 0) {
            loaded = 100
        }
        percent = fromTimer < loaded ? fromTimer : loaded;
        $("#ap_progressbar").reportprogress(percent, 100, percent + '%');
        preTimer -= settings.tickInterval;
        if (fromTimer >= 100) {
            check98PercentHandle = setTimeout(function() {
                check98Percent(loaded)
            }, 2500)
        }
        if (percent < 100) {
            if (loaded >= 100) {
                skipTextAddOrDecrement(true)
            } else {
                skipTextAddOrDecrement()
            }
        } else if (!neoedgeAd) {
            cleanupAndShowGame()
        }
    };
    var startPreloader;
    startPreloader = function() {
        flashLoadTries++;
        try {
            var loaded_temp = $(settings.preloadId)[0].PercentLoaded();
            intervalHandle = setInterval(progressUpdatePreloader,
					settings.tickInterval);
            insertAd()
        } catch (e) {
            if (flashLoadTries <= 3) {
                startPreloaderHandler = setTimeout(startPreloader, 1000)
            } else {
                if (!neoedgeAd) {
                    cleanupAndShowGame()
                }
            }
        }
    };
    var showAd = function() {
        if (settings.beforeCallback != null) {
            settings.beforeCallback.call(that, settings)
        }
        linkShowTimeElapsed = settings.showSkipTime;
        if (settings.fileType != 'swf' || settings.forcePreroll) {
            preroll = true;
            intervalHandle = setInterval(progressUpdatePreroll,
					settings.tickInterval);
            insertAd()
        } else {
            settings.gameInsertCallback.call(that);
            preloaderHeight = $(settings.contentId).css('height');
            preloaderWidth = $(settings.contentId).css('width');
            $(settings.contentId).css({
                width: '0px',
                height: '0px'
            });
            preroll = false;
            preTimer = settings.progressTime;
            startPreloader()
        }
    };
    $.spiPreloaderNeoEdge = function(timeout) {
        return function(_cmd) {
            if (_cmd == "AD_STARTED") {
                if (parent)
                    neoedgeAd = true;
                neoedgeHandler = setTimeout(cleanupAndShowGame,
						timeout || 30000)
            }
            if (_cmd == "AD_COMPLETED") {
                cleanupAndShowGame()
            }
        }
    };
    $.fn.spiPreloader = function(options) {
        target = $(this);
        $.extend(settings, options);
        if (settings.showAd) {
            if (settings.adultWarning) {
                setupAdultWarning()
            }
            showAd()
        } else {
            if (settings.adultWarning) {
                setupAdultWarning();
                target.remove();
                target = null
            }
            if (settings.beforeCallback != null) {
                settings.beforeCallback.call(that, settings)
            }
            settings.gameInsertCallback.call(that, settings);
            if (settings.afterCallback != null) {
                settings.afterCallback.call(that, settings)
            }
        }
    }
})(jQuery);

var actualWidth = 0;
var actualHeight = 0;
var startWidth = 0;
var startHeight = 0;
var ratio = 1.1;
zoom = function(inout) {
	var obj = $('#flashobj');
	if (actualWidth == 0 || actualHeight == 0) {
		actualWidth = obj.width();
		actualHeight = obj.height();
		startWidth = actualWidth;
		startHeight = actualHeight
	}
	switch (inout) {
	case 1:
		var temp = actualWidth;
		actualWidth = Math.ceil(ratio * actualWidth);
		actualHeight = Math.ceil((actualHeight * actualWidth) / temp);
		break;
	case -1:
		var temp = actualWidth;
		actualWidth = Math.ceil(actualWidth / ratio);
		actualHeight = Math.ceil((actualHeight * actualWidth) / temp);
		break
	}
	obj.width(actualWidth);
	obj.height(actualHeight);
};
resetZoom = function() {
	if (startWidth > 0 && startHeight > 0) {
		var obj = $('#flashobj');
		actualWidth = 0;
		actualHeight = 0;
		obj.width(startWidth);
		obj.height(startHeight);
	}
};

(function($) {
	$.flashPlayerVersion = function() {
		var flashVersion, activeX = null, fp6Crash = false, shockwaveFlash = 'ShockwaveFlash.ShockwaveFlash';
		if (!(flashVersion = navigator.plugins['Shockwave Flash'])) {
			try {
				activeX = new ActiveXObject(shockwaveFlash + '.7')
			} catch (errorA) {
				try {
					activeX = new ActiveXObject(shockwaveFlash + '.6');
					flashVersion = [ 6, 0, 21 ];
					activeX.AllowScriptAccess = 'always'
				} catch (errorB) {
					if (flashVersion && flashVersion[0] === 6) {
						fp6Crash = true
					}
				}
				if (!fp6Crash) {
					try {
						activeX = new ActiveXObject(shockwaveFlash)
					} catch (errorC) {
						flashVersion = 'X 0,0,0'
					}
				}
			}
			if (!fp6Crash && activeX) {
				try {
					flashVersion = activeX.GetVariable('$version')
				} catch (errorD) {
				}
			}
		} else {
			flashVersion = flashVersion.description
		}
		flashVersion = flashVersion
				.match(/^[A-Za-z\s]*?(\d+)(\.|,)(\d+)(\s+r|,)(\d+)/);
		return [ flashVersion[1] * 1, flashVersion[3] * 1, flashVersion[5] * 1 ]
	}();
	$.flashExpressInstaller = 'expressInstall.swf';
	$.hasFlashPlayer = ($.flashPlayerVersion[0] !== 0);
	$.hasFlashPlayerVersion = function(options) {
		var flashVersion = $.flashPlayerVersion;
		options = (/string|integer/.test(typeof options)) ? options.toString()
				.split('.') : options;
		return (options) ? (flashVersion[0] >= (options.major || options[0] || flashVersion[0])
				&& flashVersion[1] >= (options.minor || options[1] || flashVersion[1]) && flashVersion[2] >= (options.release
				|| options[2] || flashVersion[2]))
				: (flashVersion[0] !== 0)
	};
	$.flash = function(options) {
		if (!$.hasFlashPlayer) {
			return false
		}
		var movieFilename = options.url || '', contentType = options.type || 'swf', paramAttributes = options.params
				|| {}, buildDOM = document.createElement('body'), aArr, bArr, cArr, dArr, a, b, c, d;
		options.height = options.height || 180;
		options.width = options.width || 320;
		if (options.hasVersion && !$.hasFlashPlayerVersion(options.hasVersion)) {
			$.extend(options, {
				id : 'SWFObjectExprInst',
				height : Math.max(options.height, 137),
				width : Math.max(options.width, 214)
			});
			movieFilename = options.expressInstaller || $.flashExpressInstaller;
			paramAttributes = {
				flashvars : {
					MMredirectURL : window.location.href,
					MMplayerType : ($.browser.msie && $.browser.win) ? 'ActiveX'
							: 'PlugIn',
					MMdoctitle : document.title.slice(0, 47) + ' - Flash Player Installation'
				}
			}
		}
		if (options.flashvars && typeof paramAttributes === 'object') {
			$.extend(paramAttributes, {
				flashvars : options.flashvars
			})
		}
		for (a in (b = [ 'url', 'type', 'expressInstall', 'hasVersion',
				'params', 'flashvars' ])) {
			delete options[b[a]]
		}
		aArr = [];
		for (a in options) {
			if (typeof options[a] === 'object') {
				bArr = [];
				for (b in options[a]) {
					bArr.push(b.replace(/([A-Z])/, '-$1').toLowerCase() + ':'
							+ options[a][b] + ';')
				}
				options[a] = bArr.join('')
			}
			aArr.push(a + '="' + options[a] + '"')
		}
		options = aArr.join(' ');
		if (typeof paramAttributes === 'object') {
			aArr = [];
			for (a in paramAttributes) {
				if (typeof paramAttributes[a] === 'object') {
					bArr = [];
					for (b in paramAttributes[a]) {
						if (typeof paramAttributes[a][b] === 'object') {
							cArr = [];
							for (c in paramAttributes[a][b]) {
								if (typeof paramAttributes[a][b][c] === 'object') {
									dArr = [];
									for (d in paramAttributes[a][b][c]) {
										dArr.push(d.replace(/([A-Z])/, '-$1')
												.toLowerCase()
												+ ':'
												+ paramAttributes[a][b][c][d]
												+ ';')
									}
									paramAttributes[a][b][c] = dArr.join('')
								}
								cArr.push(c + '{' + paramAttributes[a][b][c]
										+ '}')
							}
							paramAttributes[a][b] = cArr.join('')
						}
						bArr.push(window.escape(b) + '='
								+ window.escape(paramAttributes[a][b]))
					}
					paramAttributes[a] = bArr.join('&amp;')
				}
				aArr.push('<PARAM NAME="' + a + '" VALUE="'
						+ paramAttributes[a] + '">')
			}
			paramAttributes = aArr.join('')
		}
		if (contentType == 'swf') {
			if (!(/style=/.test(options))) {
				options += ' style="vertical-align:text-top;"'
			}
			if (!(/style=(.*?)vertical-align/.test(options))) {
				options = options.replace(/style="/,
						'style="vertical-align:text-top;')
			}
		}
		if ($.browser.msie) {
			if (contentType == 'swf') {
				options += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
				paramAttributes = '<PARAM NAME="movie" VALUE="' + movieFilename
						+ '">' + paramAttributes
			} else {
				options += ' classid="clsid:233C1507-6A77-46A4-9443-F871F945D258"';
				paramAttributes = '<PARAM NAME="src" VALUE="' + movieFilename
						+ '">' + paramAttributes
			}
		} else {
			if (contentType == 'swf') {
				options += ' type="application/x-shockwave-flash" data="' + movieFilename + '"'
			} else {
				options += ' type="application/x-director" data="' + movieFilename + '"'
			}
		}
		return '<OBJECT ' + options + '>' + paramAttributes + '</OBJECT>'
	};
	$.fn.flash = function(options) {
		if (!$.hasFlashPlayer) {
			return this
		}
		var a = 0, each;
		while ((each = this.eq(a++))[0]) {
			each.html($.flash($.extend( {}, options)));
			if (each[0].firstChild.getAttribute('id') === 'SWFObjectExprInst') {
				a = this.length
			}
		}
		return this
	}
}(jQuery));