var apiPage = {};

function init(){
    apiSetBrowser();
}

function apiSetBrowser(){
    apiPage.browser = _apiDB();
    apiPage.browser.isIe = false;
    apiPage.isIe = (apiPage.browser=="ie5" || apiPage.browser=="ie6" || apiPage.browser=="ie7");
    apiPage.isIeLt7 = (apiPage.browser=="ie5" || apiPage.browser=="ie6");
    apiPage.Body = document.getElementsByTagName("body")[0];
}

function _apiDB() { // Detect Browser
    var b='', ua = navigator.userAgent.toLowerCase();
    if(ua.indexOf("opera") != -1) { b="opera"; }
    else if(ua.indexOf("safari") != -1) { b="safari";}
    else if(ua.indexOf("msie 7") != -1) { b="ie7";}
    else if(ua.indexOf("msie 6") != -1) { b="ie6";}
    else if(ua.indexOf("msie 5") != -1) { b="ie5";}
    else if(ua.indexOf("netscape") != -1) { b="netscape";}
    else if(ua.indexOf("firefox") != -1) { b="firefox";}
    else if(ua.indexOf("gecko") != -1) { b="mozilla";}
    return b;
}

function moveAd(adPlacement, jsUrl) {
    // set browser
    if (apiPage.browser == null) { apiSetBrowser(); }
    var pos = document.getElementById(adPlacement);
    var ad = document.getElementById(adPlacement + '_hidden');

    
    /*if (pos.id == 'Skyskraper1')
        alert('adplacement='+adPlacement+' pos='+pos.id+' and ad='+ad.id);*/
    if (pos && ad) {
        // setting height of sorrounding div to "auto" to enable expanding ads   commentet out pos.style.height = "auto";
      //  pos.style.height = "auto";

        // traverse all script elements and set src to null to make sure IE doesn't reload the scripts
        var x = ad.getElementsByTagName('script');
        if (x != null) {
            for (i = 0; i < x.length; i++) {
                var t = x[i];
                if (apiPage.isIe) { t.src = jsUrl + "nothing.js"; }
                else { t.src.replace = jsUrl + "nothing.js"; }
            }
        }

        var body = ad.parentNode;
        body.removeChild(ad);
        pos.innerHTML = '';
        pos.appendChild(ad);
        ad.style.display = "block";
    }
}
