Hello,
I have this JavaScript that works for a rollover/expandable Flash ad. The problem I'm having is that initially, when the page loads, the ad is not displayed in the correct position in Internet Explorer. The ad moves to the correct position as soon as I mouse over it. However, in other browsers like Firefox and Opera it displays in the correct position of the placed code.

I'll link some screenshots of this, including the link to a working page and the HTML and JavaScript code of it.

Here is how it looks in IE when the page loads:



Here is how it looks when you mouse-over on the ad or in the area where is supposed to appear.
After that, the ad appears in the correct position, until the next page reload.



Here is the rollover/expandable ad showing the video.




This is the HTML where I call the ad in the page:

Code HTML4Strict:
<script language="javascript" type="text/javascript">
    // Create Random ID
    AdRandom = new String (Math.random());
    AdRandom = AdRandom.substring(2,11);
 
    // Default Ad Size
    var AdWidth = "120";
    var AdHeight = "600";
 
    // Expanded Ad Size
    var AdExpWidth = "300";
    var AdExpHeight = "600";
    var AdExpDiff = "180"; // Difference in pixels (AdExpWidth - AdWidth)
 
    // Ad Details
    var AdMovieUrl = "banner.swf";
    var AdMovieLink = "?clickTAG=http://www.domain.com/";
    document.write('<scr' + 'ipt language="javascript" type="text/javascript" src="ExpandableAd.js"></scr'+'ipt>');
</script>

These lines of code set some variables that will be used to call the JS code.

Here is the JS file that does the work:
Code JavaScript:
// JavaScript Document
function adexpanding(AdRandom, AdWidth, AdHeight, AdExpWidth, AdExpHeight, AdExpDiff, AdMovieUrl, AdMovieLink){
 
    var openExp = 180;
    var closeExp = 90;
    var ExpHeight = 90;
    var timeDelay = 30;
    var d = document;
 
    var sAd = AdMovieUrl + AdMovieLink;
 
    // =======================================================================
    var thisExpandingAd=new Array()
    this.preloadimages = function(){
        var i=0;
        for (i=0;i<this.preloadimages.arguments.length;i++){
            thisExpandingAd[i]=new Image();
            thisExpandingAd[i].src=this.preloadimages.arguments[i];
        }
    }
    this.preloadimages(AdMovieUrl + AdMovieLink);    
 
    // =======================================================================
    this.initPos = function(){
        var obj = d.getElementById("AdExpanding"+AdRandom);
        var showExp = d.getElementById("AdExpanded"+AdRandom);
        var skySwf = d.getElementById("adExp"+AdRandom);
        if(showExp && skySwf){
            // Position SWF
            skySwf.style.marginLeft = "-"+AdExpDiff+"px";
 
            // ReSet Position
            showExp.style.left = "0px";
 
            // Resize
            showExp.style.width = AdExpWidth+"px";
 
            // X
            var _X = parseInt(this.findPosX(obj));
            showExp.style.left = _X+"px";
 
            // Y
            var _Y = parseInt(this.findPosY(obj));
            showExp.style.top = _Y+"px";
 
            // SHOW
            showExp.style.visibility="visible";
        }
    }
    // =======================================================================
    this.showAdExpanding = function(obj){
        var showExp = d.getElementById("AdExpanded"+AdRandom);
        var skySwf = d.getElementById("adExp"+AdRandom);
        if(showExp && skySwf){
            // Position SWF
            skySwf.style.marginLeft = "0px";
 
            // Resize
            showExp.style.width = AdExpWidth+"px";
 
            // X
            var _X = parseInt(this.findPosX(obj)) - AdExpDiff;
            showExp.style.left = _X+"px";
 
            // Y
            var _Y = parseInt(this.findPosY(obj));
            showExp.style.top = _Y+"px";
 
            // SHOW
//            showExp.style.visibility="visible";
        }
    }
 
    // =======================================================================
    this.hideAdExpanding = function(obj){ 
        var expDiv = d.getElementById("AdExpanded"+AdRandom);
 
        var skySwf = d.getElementById("adExp"+AdRandom);
 
        if (skySwf){
            skySwf.style.marginLeft = "-"+AdExpDiff+"px";
        }
 
        if (expDiv){
            // Resize
            expDiv.style.width = AdWidth+"px";
            var _X = parseInt(this.findPosX(obj));
            expDiv.style.left = _X+"px";
        }
    }
 
    // =======================================================================
    this.findPosX = function(obj){
        var curleft = 0;
        if (obj.offsetParent){
            while (obj.offsetParent){
                curleft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }
 
    // =======================================================================
    this.findPosY = function(obj){
        var curtop = 0;
        if (obj.offsetParent){
            while (obj.offsetParent){
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }
 
    // =======================================================================
    this.printSWF = function(){
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+AdExpWidth+'" height="'+AdExpHeight+'" id="adExp'+AdRandom+'" style="margin-left:0px;">');
        document.write('  <param name="movie" value="'+sAd+'" />');
        document.write('  <param name="quality" value="high" />');
        document.write('  <param name="wmode" value="transparent" />');
        document.write('  <embed src="'+sAd+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="'+AdExpWidth+'" height="'+AdExpHeight+'" name="adExp'+AdRandom+'" style="margin-left:0px;"></embed>');
        document.write('</object>');
    }
 
    // =======================================================================
    this.printBanner = function(){
        document.write('<div id="AdExpanding'+AdRandom+'" style="width:'+AdWidth+'px;height:'+AdHeight+'px;z-index:100000;">');
        document.write('<div id="AdExpanded'+AdRandom+'" onmouseover="javascript:mmAdBanner.showAdExpanding();" onmouseout="javascript:mmAdBanner.hideAdExpanding();" style="visibility:visible;padding:0px;position:relative;z-index:101000;left: 0px;top: 0px;width:'+AdWidth+'px;height:'+AdHeight+'px;overflow:hidden;">');
        this.printSWF();
        document.write('</div>');
        document.write('</div>');
    }
    // =======================================================================
    this.printBanner_ = function(){
        document.write('<div id="AdExpanding'+AdRandom+'" style="width:'+AdWidth+'px;height:'+AdHeight+'px;z-index:99000;" onmouseover="javascript:mmAdBanner.showAdExpanding(this);" onmouseout="javascript:mmAdBanner.hideAdExpanding(this);">');
        document.write('<div id="AdExpanded'+AdRandom+'" style="padding:0px;position:absolute;z-index:100000;left:0px;top:0px;width:'+AdWidth+'px;height:'+AdHeight+'px;overflow:hidden;visibility:visible;">');
        this.printSWF();
        document.write('</div>');
        document.write('</div>');
        this.initPos();
    }
}
 
    var mmAdBanner = new adexpanding(AdRandom, AdWidth, AdHeight, AdExpWidth, AdExpHeight, AdExpDiff, AdMovieUrl, AdMovieLink);
 
    // =======================================================================
    mmAdBanner.printBanner_();


You can see a live test of the page here:
http://65.38.219.91/rg/test_ad.html

What I need is to fix is that in IE show in the correct position when the page loads.

I also have another issue (but not as critical and not that important for now) but is that if I try to use that HTML code more than once on the page (and changing the AdMovieUrl & AdMovieLink variables to display another ad), none of the ads work. When I rollover one of them, it starts the effects of the second one, and so on. But that's not as important for now. What I need to find a solution urgent is that works fine in Internet Explorer (as it does with Firefox and Opera).


If anymore information is needed, please let me know.

Thanks!