try{preTimer}catch(e){preTimer=10000;}
try{fakePreLoadedPercentage}catch(e){fakePreLoadedPercentage=30;}
try{movieType}catch(e){movieType="";}

var bannerHeight = 300;
var bannerWidth = 250;
var actPerc = 0;
var preFull = preTimer;
var pretimeout = null;
var sometime = null;
var preLang = new Array();
var flashLoadTries = 0;
var flashLoadTriesMax = 3;
var pre_load_procent = 0;
var pre_load_done = false;
preLang['whileloading'] = 'Game is being loaded';
preLang['clicktoclose'] = 'Close the advertisement and go on to the game';

function fake_pre_load_timer_temp(pTime){
	pre_load_procent = pre_load_procent + (100 / (pTime / 100));

	$("#pre_percent").html('<span>' + Math.round(pre_load_procent) + '%</span>');
    $("#pre_bar").css('width', Math.round(pre_load_procent * 3) + 'px');
};

function fake_pre_load_timer(pTime){
	pre_load_procent = pre_load_procent + (100 / (pTime / 100));

	if(pre_load_procent >= 100) pre_load_procent = 100;

	if(pre_load_done){
		pre_load_procent = 100;
	}

	if(pre_load_procent >= fakePreLoadedPercentage){
	    $("#pre_whilead").hide();
	    $("#pre_closead").show();
	}

	$("#pre_percent").html('<span>' + Math.round(pre_load_procent) + '%</span>');
    $("#pre_bar").css('width', Math.round(pre_load_procent * 3) + 'px');

	if((pre_load_procent < 100) && (pre_load_done == false)){setTimeout('fake_pre_load_timer(\''+pTime+'\')',100);}
	else{PreloaderCallbackAfter();}
};

function getFlashMovieObject(movieName) {
	if($.browser.opera)
	{
		if(movieType == "swf"){return window.document[movieName];}
		else{return false;}
	}
	if (window.document[movieName])	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName];
		}
	}
	else {
		return document.getElementById(movieName);
	}
};

function showGameNow(movieName, dWidth, dHeight, cbfoo) {
    clearTimeout(pretimeout);
    pretimeout = -1;
    try {
        var callback = eval(cbfoo);
        callback();
    } catch(e) {
        try {
            console.log('CANNOT CALL CALLBACK FUNCTION (after)');
        } catch(e) {}
    }
    showGameNow = function() {};
};

function check98percent(oldvalue, moviename, timer, dWidth, dHeight, cbfoo) {
    var showmoviename = moviename.substr(0, moviename.length - 3);
    var fromTimer = parseInt((preFull - timer) * 100 / preFull);
    var flashMovie = getFlashMovieObject("" + moviename);
    var loaded = flashMovie.PercentLoaded();
    if (oldvalue == loaded) {
        showGameNow(showmoviename, dWidth, dHeight, cbfoo);
        if (sometime != null) {
            clearTimeout(sometime);
            sometime = null;
        }
    }
};

function Preload(moviename, dWidth, dHeight, timer, bwidth, cbfoo) {
    var showmoviename = moviename.substr(0, moviename.length - 3);
    var fromTimer = parseInt((preFull - timer) * 100 / preFull);
    var flashMovie = getFlashMovieObject("" + moviename);
    var loaded = flashMovie.PercentLoaded();
    if (loaded < 0) loaded = 100;
    actPerc = fromTimer < loaded ? fromTimer: loaded;
    var barContainerWidth = bwidth;
    var barWidth = parseInt((actPerc * barContainerWidth) / 100);
    $("#pre_bar").css('width', barWidth + 'px');
    $("#pre_percent").html('<span>' + actPerc + '%</span>');
    preTimer -= 200;
    if (fromTimer >= 100) {
        sometime = setTimeout("check98percent('" + loaded + "','" + moviename + "','" + timer + "','" + dWidth + "', '" + dHeight + "', '" + cbfoo + "')", 2500);
    };
    if (actPerc < 100) {
        if (loaded >= 100) {
            $("#pre_whilead").hide();
            $("#pre_closead").show();
        }
        if (pretimeout != -1) {
            pretimeout = setTimeout("Preload('" + moviename + "','" + dWidth + "','" + dHeight + "','" + preTimer + "','" + bwidth + "','" + cbfoo + "')", 200);
        }
    } else {
        clearTimeout(pretimeout);
        pretimeout = -1;
        showGameNow(showmoviename, dWidth, dHeight, cbfoo);
    }
};

function startPreloaderIfMovieExist(mc, w, h, t, bw, cba) {
    flashLoadTries++;
    try {
        var flashMovie_temp = getFlashMovieObject(mc);
        var loaded_temp = flashMovie_temp.PercentLoaded();
        pretimeout = setTimeout("Preload('" + mc + "', '" + w + "','" + h + "','" + t + "','" + bw + "','" + cba + "')", 500);
    } catch(e) {
        if (flashLoadTries <= flashLoadTriesMax) {
            try {
            	PreloaderCallbackAfterMaxTemp();
                console.log('couldn\'t load preloader [' + flashLoadtries + ']');
            } catch(e) {}
            setTimeout("startPreloaderIfMovieExist('" + mc + "', '" + w + "','" + h + "','" + t + "','" + bw + "','" + cba + "')", 1000);
        } else {
            var mn = mc.substr(0, mc.length - 3);
            //showGameNow(mn, w, h, cba);
            try {
            	PreloaderCallbackAfterMax();
                console.log('couldn\'t load preloader after ' + flashLoadTries + ' tries.');
            } catch(e) {}
        }
    }
};

function showPreloader(flashDivId, ad, width, height, barwidth, cbfooBefore, cbfooAfter, connectionType) {
    if (cbfooBefore != null) {
        try {
            var callbackBefore = eval(cbfooBefore);
            callbackBefore();
        } catch(e) {
            try {
                console.log('CANNOT CALL CALLBACK FUNCTION (before)');
            } catch(e) {}
        }
    }
    try {
        if (js_pre_whileloading != '' && js_pre_whileloading != null && js_pre_whileloading != "undefined") {
            preLang['whileloading'] = js_pre_whileloading;
        }
        if (js_pre_click2close != '' && js_pre_click2close != null && js_pre_click2close != "undefined") {
            preLang['clicktoclose'] = js_pre_click2close;
        }
    } catch(e) {}

    var barWidth = barwidth;
    var tempBannerHeight = height;
    if(tempBannerHeight < 310){tempBannerHeight = 310;$("#sp_game_middle").css('height', tempBannerHeight + 'px');}
    $("#" + flashDivId).css('width', '0px');
    $("#" + flashDivId).css('height', '0px');
    $("#" + flashDivId).after('<div id="pre_ad"><div id="pre_loader"><div id="pre_bar">&#160;</div></div></div>');
    $("#pre_ad").css('width', width + 'px');
    $("#pre_ad").css('height', tempBannerHeight + 'px');
    if(tempBannerHeight < 310){}else{$("#pre_ad").css('marginTop', Math.round((tempBannerHeight/2)-(bannerHeight/2)-2) + 'px');}

	//check for ajax or iframe
	//iframe or ajax (if ajax then var ad must be the ajax url)
	if(connectionType == "ajax"){
		$("#pre_ad").prepend('<div id="pre_adcont"></div><center><div style="margin: 0px; margin-top: -10px; padding: 0px; width: 300px; text-align: right; font-family: verdana; font-size: 10px;">Advertisement Titter.com</div></center><br/>');
		//laad de advertentie
		var ajaxManager = $.manageAjax({manageType: 'queue', maxReq: 0, blockSameRequest: true});
		ajaxManager.add({
			success: function(htmlCode) {
				document.getElementById('pre_adcont').innerHTML = htmlCode;
			},
			data: '',
			type: 'post',
			url: ad
		});
		ajaxManager = null;
	}
    else{$("#pre_ad").prepend('<div id="pre_adcont">' + ad + '</div><center><div style="margin: 0px; margin-top: -10px; padding: 0px; width: 300px; text-align: right; font-family: verdana; font-size: 10px;">Advertisement Titter.com</div></center><br/>');}

    $("#pre_ad").append('<div id="pre_c2c_container"></div>');
    $("#pre_c2c_container").css('width', barWidth + 'px');
    $("#pre_c2c_container").append('<div id="pre_click2close"><div id="pre_whilead">' + preLang['whileloading'] + '</div></div>');
    $("#pre_c2c_container").append('<div id="pre_percent">&#160;</div>');
    $("#pre_click2close").css('width', (barWidth - 35) + 'px');
    $("#pre_percent").css('width', '35px');
    $("#pre_c2c_container").after('<div id="pre_clear">&#160;</div>');
    $("#pre_loader").css('width', barWidth + 'px');
    $("#pre_click2close").append('<a id="pre_closead" href="javascript:void(0);" onClick="showGameNow(\'' + flashDivId + '\',\'' + width + '\',\'' + height + '\',\'' + cbfooAfter + '\'); return false;" style="display: none;">' + preLang['clicktoclose'] + '</a>');

	setTimeout("startPreloaderIfMovieExist('" + flashDivId + "_mc', '" + width + "','" + height + "','" + preTimer + "','" + barWidth + "','" + cbfooAfter + "')", 1000);

	$("#postroll_advertisement_ajax").hide();
	$("#postroll_advertisement_ajax_468x60").hide();
};

function resize_game(newWidth, newHeight) {
	if($.browser.mozilla)
	{
		$("#game_container").css('width', newWidth);
		$("#game_container").css('height', newHeight);
	}
	else
	{
		$("#game_container").animate({
			width: newWidth,
			height: newHeight
		}
		);
	}
};

// callback function invoked before the SWF is (pre)loaded
function PreloaderCallbackBefore() {

};

// callback function invoked after the SWF couldn't (pre)loaded
function PreloaderCallbackAfterMaxTemp() {
	fake_pre_load_timer_temp(preTimer);
};

function PreloaderCallbackAfterMax() {
	fake_pre_load_timer(preTimer);
};

// callback function invoked after the SWF is (pre)loaded
function PreloaderCallbackAfter() {
	try{$("#pre_ad").hide();}catch(e){}
	try{document.getElementById("pre_ad").innerHTML = "";}catch(e){}
	$("#flashobj").css('width', '100%');
    $("#flashobj").css('height', '100%');
    try{pre_load_done = true;}catch(e){}
    //$("#sp_game_middle").css('height', '');
	$("#postroll_advertisement_ajax").show();
	$("#postroll_advertisement_ajax_468x60").show();
};