jQuery(document).ready( function () {
    if(getCorp()) {
        runEE();
    }
});

var timeout;
var EEwaitMin = 12;
var EEwaitMax = 60;
var EEwidth = 400;
var EEheight = 150;
var EErun = false;
var EEcont = "<div id=\"EE\"><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"/images/ueberwacht.swf?corp={%CORP%}\" width=\"400\" height=\"150\" FlashVars=\"corp={%CORP%}\"><!--<![endif]--><!--[if IE]><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"400\" height=\"150\" align=\"middle\"><param name=\"FlashVars\" value=\"corp={%CORP%}\"><param name=\"movie\" value=\"/images/ueberwacht.swf?corp={%CORP%}\"><!--><!--dgx--><param name=\"quality\" value=\"high\"><param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"allowFullScreen\" value=\"false\"><param name=\"wmode\" value=\"transparent\"><param name=\"scale\" value=\"noborder\"></object><!-- <![endif]--></div>";

var getCorp = function () {
    var agent = navigator.userAgent.toLowerCase();
    if (agent.indexOf("macintosh") > -1) {
        return "Apple Inc.";
    } else if (agent.indexOf("chrome") > -1 && agent.indexOf("chromium") == -1) {
        return "Google Inc.";
    } else if (agent.indexOf("safari") > -1 && agent.indexOf("chrom") == -1) {
        return "Apple Inc.";
    } else if (agent.indexOf("windows") > -1) {
        return "Microsoft";
    } else if(window.location.href.indexOf("?GOOGLE") > -1 || window.location.href.indexOf("?CHROME") > -1) {
        return "Google Inc.";
    } else if(window.location.href.indexOf("?APPLE") > -1 || window.location.href.indexOf("?SAFARI") > -1) {
        return "Apple Inc.";
    } else if(window.location.href.indexOf("?WINDOWS") > -1 || window.location.href.indexOf("?MICROSOFT") > -1) {
        return "Microsoft";
    }
    return false;
}
var showEE = function () {
    var EEposXmin = jQuery("html").scrollLeft();
    var EEposXmax = EEposXmin + jQuery(window).width() - EEwidth;
    var EEposYmin = jQuery("html").scrollTop();
    var EEposYmax = EEposYmin + jQuery(window).height() - EEheight;
    while(EEcont.indexOf("{%CORP%}") > -1) {
        EEcont = EEcont.replace("{%CORP%}", getCorp())
    }
    jQuery("body").append(EEcont);
    jQuery("#EE").css({"position":"absolute",
                       "top": (Math.random() * (EEposYmax - EEposYmin) + EEposYmin) + "px",
                       "left": (Math.random() * (EEposXmax - EEposXmin) + EEposXmin) + "px",
                       "z-index":"10000"});
}
var runEE = function () {
    if(!EErun) {
        EErun = true;
        var t = getEEtimeout()
        timeout = window.setTimeout("runEE()", t);
        return false;
    }
    showEE();
    timeout = window.setTimeout("runEE()", getEEtimeout());
}
var getEEtimeout = function () {
    return (Math.random() * (EEwaitMax - EEwaitMin) + EEwaitMin) * 1000;
}
var removeEE = function () {
    jQuery("#EE").remove();
}

