var nag_handler;
var nag_first;
var nag_isGold;
var nag_group;
var nag_showGpBanner;
var nag_sex;
var nag_age;
var nag_counter = 0;
var nag_daysInPanfu;
var expandable = "";
var pop_under_hanler;

/**
 * Indicates if Zong popup is alraedy open
 */
var zong_open = false;

/**
 * Indicates if popunder banner has been shown
 */
var ads_popunder_popped = false;

/**
 * Indicates that it is first show of nag banner for user.
 * Used for showing nag banner with different rate (rate changes after first display)
 * true => banner will be shown on the 10. room change
 * false => banner will be shown on the 9. room change
 */
var nag_first_banner = false;

/**
 * Indicates if expandable banner has been initialized
 * @see expandable_init
 */
var expandable_init_done = false;

/**
 * Holds configuration passed to expandable_init function
 * @see expandable_init
 */
var expandable_config = null;

/**
 * Holds original values of css parameters, that are changed during expandable_init
 * These values are used during expendable_reset to restore original layout
 * @see expandable_init
 * @see expandable_reset
 */
var expandable_config_cache = {};

$(document).ready(function() {
    nag_first = true;
    nag_counter = 0;

    $(document).keyup(function(event) {
        if (event.keyCode == 27) {
            nag_handler = setTimeout("nag_hider()", 2000);
        }
    });

    $('#nag_close').click(function() {
        nag_handler = setTimeout("nag_hider()", 1000);
    });

    $(window).resize(function() {
        if (zong_open) {
            zong_center();
        }
    });
});

function loadMovieBasic(movieName, divId, width, height) {

    var flashvars = {};
    var params = {};
    var attributes = {};
    params.scale = "noscale";
    params.quality = "best";
    params.salign = "TL";
    params.menu = "false";
    params.wmode = "transparent";

    swfobject.embedSWF(movieName, divId, width, height, "9.0.0", false, flashvars, params, attributes);
}

/**
 * Loads game window
 *
 * TODO: describe all parameters
 *
 * @param addRandomParam
 * @param base string base URL indicating where all resources for flash client are located
 * @param referrer
 * @param iServer string URL to Information Server
 * @param langId string two-letter code of current language
 * @param refId
 * @param showRegScreen
 * @param code
 * @param user
 * @param pw
 * @param countryCode string two letter code indicating from which country visitor is, pass 'UNKNOWN' if value not known
 */
function reload(addRandomParam, base, referrer, iServer, langId, refId, showRegScreen, code, user, pw, countryCode) {
    // special case
    if (addRandomParam == 1) {
        window.location = 'index.php';//window.location.href;
    } else {
        var randomParam = addRandomParam ? "?rnd=" + Math.random() : "";
        var flashvars = {};
        var params = {};
        var attributes = {};
        params.scale = "noscale";
        params.quality = "best";
        params.salign = "TL";
        params.menu = "false";
        params.base = base;
        params.allowScriptAccess = "always";

        if (langId != 'RU' && langId != 'AR') {
            params.wmode = "transparent";
        }

        flashvars.referrer = referrer;
        flashvars.iServer = iServer;
        flashvars.langId = langId;
        flashvars.refId = refId;
        flashvars.showRegScr = showRegScreen;
        flashvars.code = code;
        flashvars.user = encodeURIComponent(user);
        flashvars.pw = encodeURIComponent(pw);
        flashvars.mode = "live";
        flashvars.countryCode = countryCode;

        if (langId != 'RU' && langId != 'AR') {
            flashvars.wmode = "transparent";
        }

        swfobject.embedSWF(base + "Panfu.swf?v=1.0.43" + randomParam, "flash_anmeldung", 772, 480, "9.0.0", false, flashvars, params, attributes);
        // Redirect users with flash player < 9.0.0
        var hasFlash = swfobject.hasFlashPlayerVersion("9.0.0");

        if (hasFlash == false) {
            window.location = "no_flash.php";
        }
    }
}

function getFlashVersion() {
    var playerVersion = swfobject.getFlashPlayerVersion();

    if (playerVersion == undefined || playerVersion == null) {
        return "no flash";
    }

    return playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release;
}

function reloadPage() {
    window.location = window.location.href;
}

function incInvitation(user) {
    window.frames['gc'].location = 'iframes/confirm_invitation.php?user=' + user;
}

function onLoginAfterRegistration() {
    window.frames['gc'].location = 'conversion.php';
}


function IT_Action(action) {
    var tracking_object = createITT();
    tracking_object.ACTION = "" + action;
    tracking_object.submit_action();
}


function getGet(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return null;
    else
        return results[1];
}

function getLocale() {
    var url = window.location.href;
    var url2 = url.substring(0, url.lastIndexOf('/'));
    var domain = url2.substring(url2.lastIndexOf('/') + 1);

    if (url.lastIndexOf('debby') > 0 && url.lastIndexOf('langId') > 0) {
        locale = getGet("langId").toLowerCase();
    } else if (url.lastIndexOf('.dev.debby') > 0) {
        locale = domain.substring(0, domain.indexOf('.'));
    } else {
        locale = url2.substring(url2.lastIndexOf('.') + 1);
    }

    return locale;
}

function flash_callback_ads_show(isGold, group, showGpBanner, sex, age, daysInPanfu, roomId) {
    var locale = getLocale();
    if (locale == 'com') locale = 'en';
    var langId = "&langId=" + locale.toUpperCase();

    var age_group = ads_get_age_group(parseInt(age));

    YI.debug("Showing ads [isGold=" + isGold + "], [daysInPanfu=" + daysInPanfu + "], [locale=" + locale + "] " +
            "[roomId=" + roomId + "]");

    if (isGold == undefined || isGold == false) {
        if (ads_enabled(locale, daysInPanfu)) {
            if (group == "Rooms" || group == "Games") {
                var show_banners = {
                    skyscraper : locale != 'es', // disabling showing banners for ES - MA-258
                    leaderboard : true,
                    popunder : !ads_popunder_popped && locale == "de"
                };

                var event_parameters = [show_banners.skyscraper, show_banners.leaderboard, show_banners.popunder];

                $(document).trigger('ads.show.before', event_parameters);

                try {
                    if (show_banners.skyscraper) {
                        frames.banner.location.href = "banner.php?id=" + Math.random() + "&sex=" + sex + "&age=" + age_group + "&showGpBanner=" + showGpBanner + "&roomId=" + roomId + langId;
                    }

                    if (show_banners.leaderboard) {
                        frames.banner2.location.href = "banner2.php?id=" + Math.random() + "&sex=" + sex + "&age=" + age_group + "&showGpBanner=" + showGpBanner + "&roomId=" + roomId + langId;
                    }

                    if (show_banners.popunder) {
                        frames.banner3.location.href = "banner3.php?id=" + Math.random() + "&sex=" + sex + "&age=" + age_group + "&showGpBanner=" + showGpBanner + "&roomId=" + roomId + langId;
                        ads_popunder_popped = true;
                    }
                } catch(err) {
                }

                if (show_banners.skyscraper) {
                    $("#bannerArea").css("display", "block").css("width", "160px");
                }

                $("#bannerArea_inside").css("display", "block").css("width", "160px");
                $("#bannerArea_inside").css("position", "absolute").css("right", "0px");
                $("#bannerArea_inside").css("text-align", "right");

                $("#bannerArea2").css("display", "block");
                $("#goldpic").css("display", "none");

                if (show_banners.skyscraper) {
                    $("#empty_left").css("width", "50px");
                    $("#empty_right").css("width", "160px");
                    $("#footer").css("margin-right", "0px");
                    $("#footer").css("margin-left", "0px");

                    $("#footer").css("left", "-55px");
                }

                // special advertising format
                if (locale == 'es') {
                    $.getScript('http://www.smartadserver.com/call/pubj/11792/86455/4068/S/' + YI.generateRandomNumber());
                }

                $(document).trigger('ads.show.after', event_parameters);
            }
        }
    }
}

/**
 * Return age group based on age
 *
 * Age groups:
 * 0 ->  0 - 5
 * 1 ->  6 - 12
 * 2 -> 13 - 17
 * 3 -> 18 - 25
 * 4 -> 26 - 35
 * 5 -> 36 - 45
 * 6 -> 45 - ...
 *
 * @param age integer
 * @return integer number indicating group age
 */
function ads_get_age_group(age) {
    if (age > 5) {
        return 1;
    } else if (age > 12) {
        return 2;
    } else if (age > 17) {
        return 3;
    } else if (age > 25) {
        return 4;
    } else if (age > 35) {
        return 5;
    } else if (age > 45) {
        return 6;
    } else {
        return 0;
    }
}

/**
 * Check if ads are enabled for this country
 *
 * @param lang two letter language code
 */
function ads_enabled(lang, daysInPanfu) {
    var ads_enabled = lang == "de" || lang == "nl" || lang == "fr" || lang == 'es' || lang == 'pl' || lang == 'en';

    return ads_enabled;
}

function IT_Page(name, group, memberid) {
    var tracking_object = createITT();
    tracking_object.DOCUMENTNAME = "" + name;
    tracking_object.DOCUMENTGROUP = "" + group;

    if (memberid != "") tracking_object.MEMBERID = "" + memberid;

    tracking_object.submit();
}

// Boot Analyze begin
var BootStr = "";
var TXTL = false;
var FNTL = false;
var TID = -1;
function BootLog(key) {
    if (TID == -1) {
        BootStr = key;
        TID = setTimeout('TooSlow(true)', 8000);
    } else {
        BootStr += "&" + key + "=1";
        switch (key) {
            case 'FNTL': TXTL = true; if (FNTL) {
                TooSlow(false);
            }; break;
            case 'TXTL': FNTL = true; if (TXTL) {
                TooSlow(false);
            }; break;
        }
    }
}

function TooSlow(b) {
    if (b) {
        window.location.href = 'low_bandwidth.php&' + BootStr;
    } else clearTimeout(TID);
}
// Boot Analyze end

/**
 * Called from flash client - after first login
 *
 * @param lang two letter uppercase language code
 */
function flash_callback_after_registration(lang) {
    if (lang == 'FR') {
        YI.debug('Loading tracking pixel: putAdvertStream');
        x = document.createElement('script');
        x.src = 'http://ad.advertstream.com/track_conversion.php?annonceurid=6755';
        x.type = "text/javascript";
        document.body.appendChild(x);
    }

    if (YI.partners.isFromPartner('gtw') && (lang == 'EN' || lang == 'DK' || lang == 'FI' || lang == 'NL' || lang == 'NO' || lang == 'SE')) {
        YI.debug('Loading tracking pixel: Games2Win');
        var image = document.createElement('img');
        image.src = 'http://o1.inviziads.com/www/delivery/ti.php?trackerid=4&amp;cb=' + YI.generateRandomNumber();
        image.width = 0;
        image.height = 0;
        document.body.appendChild(image);
    }

    if (YI.partners.isFromPartner('fox')) {
        YI.debug('Loading tracking pixel: Fox');
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'http://ad.foxnetworks.com/pixel?id=914509&t=1';
        document.body.appendChild(script);
    }
}

// TODO: remove after deployment client for flash_callback_after_registration
function putAdvertStream() { // FR only
    x = document.createElement('script');
    x.src = 'http://ad.advertstream.com/track_conversion.php?annonceurid=6755';
    x.type = "text/javascript";
    document.body.appendChild(x);
}

function nag_hider() {
    $("#nag_screen").fadeOut(200);

    clearTimeout(nag_handler);

    var locale = getLocale();
    if (locale == 'com') locale = 'en';
    var langId = "&langId=" + locale.toUpperCase();

    var age_group = ads_get_age_group(parseInt(nag_age));

    if (nag_isGold == undefined || !nag_isGold) {
        if (ads_enabled(locale, nag_daysInPanfu)) {
            try {
                frames.nag_banner.location.href = "banner_nag.php?id=" + Math.random() + "&sex=" + nag_sex + "&age=" + age_group + "&showGpBanner=" + nag_showGpBanner + langId;
            } catch(err) {
            }
        }
    }
}

function nag_hide() {
    //baner is removed after few seconds no matter what, this function (from flash) is ignored atm
}


/**
 * Show the over game ads.
 *
 * Ads are shown after 10 first room changes.
 * Then for scandinavia countries every 15 room changes, for other - every 9.
 *
 * As a side effect 'nag_counter' gets incremented and 'nag_first' is set to false after the first call.
 * 'nag_first_banner' is set to false after first display of ad.
 *
 * Banners are disabled temporarily for Webkit browsers.
 *
 * FIXME: explain the arguments
 *
 * @param isGold
 * @param group
 * @param showGpBanner
 * @param sex
 * @param age
 * @param daysInPanfu integer indicates how many days ago player has registered
 */
function nag_show(isGold, group, showGpBanner, sex, age, daysInPanfu) {
    var locale = getLocale();

    if (locale == 'com') {
        locale = 'en';
    }

    if (ads_enabled(locale, daysInPanfu) && !$.browser.safari) {
        nag_isGold = isGold;
        nag_group = group;
        nag_showGpBanner = showGpBanner;
        nag_sex = sex;
        nag_age = age;
        nag_daysInPanfu = daysInPanfu;

        clearTimeout(nag_handler);

        if (nag_first) {
            nag_hider();
            nag_first = false;
            nag_first_banner = true;

        } else {
            nag_counter += 1;

            var frequency;

            if (nag_first_banner) {
                frequency = 10;
            } else if (!nag_first_banner) {
                if (locale == 'fi' || locale == 'se' || locale == 'dk' || locale == 'no') {
                    frequency = 15;
                } else if (locale == 'en' || locale == 'de' || locale == 'nl') {
                    frequency = 8;
                } else {
                    frequency = 9;
                }
            }

            if (nag_counter == frequency) {
                nag_counter = 0;

                $("#nag_screen").fadeIn(300);
                nag_handler = setTimeout("nag_hider()", 20000);
                nag_first_banner = false;
            }
        }
    }
}


function flash_callback_videoplayer_click() {
    $(".flash_callback_videoplayer_click").remove();
    $("#table_right").append('<img class="flash_callback_videoplayer_click" src="http://ads.publicidad.net/call/pubimppixel/3168463/' + (("" + Math.random()).substring(2)) + '" width="1" height="1"/>');
}

/**
 * Stores publicId from happyhour promo, called from flash when player clicks on popup
 *
 * @param public_id string happyhour public id
 */
function flash_callback_happyhour(public_id) {
    $.cookie('happyhour', public_id, { expires: 7, path: '/payment/' });
}

/**
 * Show popup with Zong (SMS Provider) entry point page where player can process payment
 *
 * @param url {string} Zong Entry Point URL
 */
function flash_callback_zong(url) {
    YI.logger.debug("Displaying zong popup for URL [" + url +"]");

    if (zong_open) {
        YI.logger.debug("Zong popup is already opened");
        return;
    }

    zong_open = true;

    var width = 500;
    var height = 370;

    var $div = $('<div id="zongEntryPointPopup"><div class="close"><a href="#">' +
            YI.get('snippet.popup_close') + '</a></div><div class="preloader"><iframe></iframe></div></div>');

    $("#zongEntryPointPopup", $div).css('width', width + 'px')
            .css('height', height + 15 /* close button height */ + 'px');

    $("iframe", $div).attr('src', url)
            .attr('width', width - 10 /* margins */)
            .attr('height', height - 10 /* margins */)
            .attr('frameborder', 0)
            .attr('scrolling', 'no')
            .attr('marginwidth', 0)
            .attr('marginheight', 0)
            .attr('allowtransparency', 'true');

    $("a", $div).click(zong_close);

    $div.dialog({
        modal: true,
        resizable: false,
        draggable: false,
        position: 'center',
        width: width,
        height: height,
        closeOnEscape: false
    });

    zong_center();
}

/**
 * Center Zong popup according to flash client
 */
function zong_center() {
    $("#zongEntryPointPopup").dialog('widget').position({
        at: "center center",
        of: $("#flash_anmeldung")
    });
}

/**
 * Close Zong popup and destroy element created during opening
 * @see flash_callback_zong
 */
function zong_close() {
    YI.logger.debug("Closing zong popup");

    $("#zongEntryPointPopup").dialog('close');
    $("#zongEntryPointPopup").dialog('destroy');
    $("#zongEntryPointPopup").remove();

    zong_open = false;

    return false;
}

/**
 * Initialize expandable banner
 *
 * @param config array containing configuration:
 *
 * string expandable_element /required/ - contains banner and space used when banner is expanded, by default hidden
 *                                          under game e.g. #bannerArea_inside
 *
 * string frame /required/ - element that contains banner. After mouseover its z-index increases, so it is
 *                                          shown above game e.g. #bannerArea
 *
 * string expanded_type /required/ - how default size of expandable area defined by expandable_element will be
 *                                          changed. Possible values:
 *                                              - skyscraper
 *                                              - leaderboard
 *
 * string expanded_value /required/ - whats new value for dimension defined by expanded_dimension e.g. 480px
 *
 * string expandable_size /required for leaderboard/ - what is added size of expandable banner
 * string placeholder /required for leaderboard/ - element that will save space when expandable banner floats
 * boolean hide_on_mouseout /optional/ - if banner area should be hidden on mouseout
 */
function expandable_init(config) {
    YI.debug("expandable_init");

    if (config != undefined) {
        expandable_config = config;
    }

    // skipping init if banner area is not shown
    if (!('expandable_element' in expandable_config) || !$(expandable_config.expandable_element)
            || $(expandable_config.expandable_element).css('display') == 'none') {
        return;
    }

    expandable_config.is_skyscraper = expandable_config.expanded_type == 'skyscraper';
    expandable_config.is_leaderboard = expandable_config.expanded_type == 'leaderboard';

    // extend area and hide it below game
    expandable_config_cache.frame_expanded_value =
            change_css_get_previous_value(expandable_config.frame, expandable_config.is_skyscraper ? 'width' : 'height', expandable_config.expanded_value);

    $(expandable_config.expandable_element).addClass("expandable");
    expandable_hide();

    if (expandable_config.is_leaderboard) {
        expandable_config_cache.expandable_element_height =
                change_css_get_previous_value(expandable_config.expandable_element, 'height', expandable_config.expanded_value);

        $(expandable_config.placeholder).css('height', expandable_config_cache.expandable_element_height);
        $(expandable_config.expandable_element).css('top', '-' + expandable_config.expandable_size);
        $(expandable_config.expandable_element).css('position', 'absolute');
        $("body center:first", $(expandable_config.frame).contents()).css('padding-top', expandable_config.expandable_size);
    }

    if ('hide_on_mouseout' in expandable_config && expandable_config.hide_on_mouseout) {
        $(expandable_config.expandable_element).mouseout(function() {
            YI.debug("expandable_element.mouseout");
            expandable_hide();
        });
    }

    expandable_init_done = true;
}

/**
 * Show expandable banner (brings to front banner area)
 */
function expandable_show() {
    YI.debug("expandable_show");

    $(expandable_config.expandable_element).addClass('expandable_show');
    $("body", $(expandable_config.frame).contents()).append('<a href="#" class="expandable_close"></a>');
    $(".expandable_close", $(expandable_config.frame).contents()).click(function() {
        expandable_hide();
        return false;
    });

    if (expandable_config.is_leaderboard) {
        $("#under_game_content").css("z-index", "30");
    } else {
        $(expandable_config.frame).css("z-index", "30");
    }
}

/**
 * Hide expandable banner (brings to back banner area)
 */
function expandable_hide() {
    YI.debug("expandable_hide");

    if (expandable_config.is_leaderboard) {
        $(expandable_config.expandable_element).removeClass('expandable_show');
        $(".expandable_close", $(expandable_config.frame).contents()).remove();
        $("#under_game_content").css("z-index", '5');
    } else {
        $(expandable_config.frame).css("z-index", $.browser.msie && $.browser.version == "6.0" ? "-1" : "0");
    }
}

/**
 * Restores layout for banners
 */
$(document).bind('ads.show.before', function () {
    YI.debug("expandable_reset");

    if (expandable_init_done) {
        expandable_hide();

        $(expandable_config.expandable_element).removeClass("expandable");

        $(expandable_config.expandable_element).unbind('mouseout');
        $(expandable_config.expandable_element).unbind('click');

        $(expandable_config.frame).css(expandable_config.is_skyscraper ? 'width' : 'height', expandable_config_cache.frame_expanded_value);

        if (expandable_config.is_leaderboard) {
            $(expandable_config.placeholder).css('height', '0');
            $(expandable_config.expandable_element).css('top', 'auto');
            $(expandable_config.expandable_element).css('position', 'relative');
            $(expandable_config.expandable_element).css('height', expandable_config_cache.expandable_element_height);
        }

        expandable_config = null;
        expandable_config_cache = {};
    }

    expandable_init_done = false;
});

/**
 * Changes css value of element and return previous value
 *
 * @param element element that will be changed
 * @param css css parameter
 * @param value new value
 */
function change_css_get_previous_value(element, css, value) {
    var old_value = $(element).css(css);

    $(element).css(css, value);

    return old_value;
}

var ads_shrek = new function() {
    this.background_width = 1440;
    this.restore_values = {};

    this.shown = false;

    this.show = function() {
        this.shown = true;
        this.change_background();
        this.move_background();
        this.move_body();
        this.hide_banner();
        this.add_tracking_pixels();
    };

    this.change_background = function() {
        this.restore_values.background_image =
                change_css_get_previous_value('body', 'background-image', "url('" + YI.staticContent('/images/ads/shrek/background.jpg') + "')");

        this.restore_values.background_repeat =
                change_css_get_previous_value('body', 'background-repeat', 'no-repeat');

        this.restore_values.background_position = $('body').css('background-position');

        this.restore_values.background_attachment =
                change_css_get_previous_value('body', 'background-attachment', 'fixed');
    };

    this.move_background = function() {
        var move = ($(window).width() - this.background_width) / 2;
        $('body').css('background-position', move + 'px 0');
    };

    this.restore_background = function() {
        $("body").css('background-image', this.restore_values.background_image);
        $("body").css('background-repeat', this.restore_values.background_repeat);
        $("body").css('background-position', this.restore_values.background_position);
        $("body").css('background-attachment', this.restore_values.background_attachment);
    };

    this.move_body = function() {
        // spaces - moving little bit to right and adding margin on top
        $("body").addClass("ads_shrek");
        $("table td:last").after($('<td></td>').attr('id', 'ads_shrek_table_spacer'));

        // adding movie
        $("#under_game_content").before('<div id="ads_shrek_movie"><div id="ads_shrek_movie_embedd"></div></div>');
        YI.flash.load(YI.staticContent('/images/ads/shrek/player.swf'), 'ads_shrek_movie_embedd', '300', '125', {
            skin: YI.staticContent('/images/ads/shrek/skins/classic.swf'),
            video: YI.staticContent('/images/ads/shrek/Shrek_200x250.flv'),
            autoplay: 1
        });

        // moving footer
        this.restore_values.footer_left =
                change_css_get_previous_value('#footer', 'left', '0');

        $(document).click(function(event) {
            if (ads_shrek.is_ad_element(event)) {
                window.open('http://www.eyewonderlabs.com/ct.cfm?ewbust=' + YI.generateRandomNumber() + '&file=http://cdn.eyewonder.com/100125/763520/1298789/NOSCRIPTfailover.&eid=1298789&name=Clickthru-clickTag1&num=1&time=0&diff=0&click=http%3A//adsfac.eu/link.asp%3Fcc%3DPPG016.46709.0%26creativeID%3D60019');
            }
        });

        $("body").mouseover(function(event) {
            if (ads_shrek.is_ad_element(event)) {
                $("body").css('cursor', 'pointer');
            } else {
                $("body").css('cursor', 'auto');
            }
        });
    };

    this.add_tracking_pixels = function() {
        $("#ads_shrek_table_spacer").append('<img src="http://cdn.eyewonder.com/100125/763520/1298789/ewtrack.gif?ewbust=' + YI.generateRandomNumber() + '" width="1" height="1"/>');
        $("#ads_shrek_table_spacer").append('<img src="http://adsfac.eu/trk.asp?cc=PPG016.46709.0&creativeID=60019&ord=' + YI.generateRandomNumber() + '" width="1" height="1"/>');
    };

    this.restore_body = function() {
        $("body").removeClass("ads_shrek");
        $("#ads_shrek_table_spacer").remove();
        $("#ads_shrek_movie").remove();
        $("#footer").css('left', this.restore_values.footer_left);

        $(document).unbind('click');
        $("body").unbind('mouseover');
        $("body").css('cursor', 'auto');
    };

    this.hide_banner = function() {
        $("#table_right").hide();
    };

    this.restore_banner = function() {
        $("#table_right").show();
    };

    this.is_ad_element = function(event) {
        var element = event.toElement ? event.toElement : event.originalTarget;

        if (!element) {
            // for IE
            element = event.srcElement;
        }

        if (!element || !element.tagName) {
            return false;
        }

        return element.tagName == 'BODY' || element.tagName == 'CENTER'
                || (element.tagName == 'DIV' && $(element).attr('id') == 'ads_shrek_movie')
                || (element.tagName == 'TD' && $(element).attr('id') == 'ads_shrek_table_spacer');
    };

    $(function() {
        $(document).bind('ads.show.before', function(event) {
            if (ads_shrek.shown) {
                ads_shrek.restore_background();
                ads_shrek.restore_body();
                ads_shrek.restore_banner();
                ads_shrek.shown = false;
            }
        });

        $(window).bind('resize', {ad: this}, function(event) {
            if (ads_shrek.shown) {
                ads_shrek.move_background();
            }
        });
    });
};

