// Код реализующий функции "плавающего" окна код для MSIE4 и выше
var isIE     = document.all && navigator.userAgent.indexOf('Opera')==-1;
var saveLoad = null;
var saveSize = null;
var zPos     = 0x0200;
var yMax     = 241;

function SetAllPosition() {
        for (i in document.DHTMLcarts) SetPosition(document.DHTMLcarts[i].rootDocObj);
        if (saveSize) saveSize();
}

function SetPosition(obj,x,y) {
    if(!x) x = obj.style.pixelLeft;
    if(!y) y = obj.style.pixelTop;
    obj.style.pixelLeft = Math.max(0,Math.min(x,document.body.clientWidth-obj.offsetWidth));
    obj.style.pixelTop = Math.max(yMax,Math.min(y,document.body.clientHeight-obj.offsetHeight));
}

function StartBaner() {
        var tp = 0;
        for (i in document.DHTMLcarts) {
                SetPosition(document.DHTMLcarts[i].rootDocObj,9999,tp);
        document.DHTMLcarts[i].rootDocObj.style.visibility = 'visible';
        tp += document.DHTMLcarts[i].rootDocObj.offsetHeight + 2;
        }
    window.onresize = SetAllPosition;
    if(saveLoad) saveLoad();
}

function DHTMLcartMove(e) {
    var obj = document.draggedDHTMLcart;
        if(event.button == 0) {
        DHTMLcartDrop();                        
        return true;
        }
        SetPosition(obj.rootDocObj,event.clientX-obj.dragXOffset,event.clientY-obj.dragYOffset);
        event.returnValue = false;      
    return false;
}

function DHTMLcartDrop() {       
    var obj = document.draggedDHTMLcart;
        document.onmousemove = obj.oldonmousemove;
    document.onmouseup   = obj.oldonmouseup;            
    document.draggedDHTMLcart = null;
    return true;               
}

function DHTMLcartDrag(e) {
    var obj = document.DHTMLcarts[this.DHTMLcart];
        obj.dragXOffset = event.clientX - obj.rootDocObj.style.pixelLeft;
    obj.dragYOffset = event.clientY - obj.rootDocObj.style.pixelTop;  
        obj.oldonmousemove = document.onmousemove;
    obj.oldonmouseup   = document.onmouseup;
        document.onmousemove = DHTMLcartMove;
    document.onmouseup   = DHTMLcartDrop;
    document.draggedDHTMLcart = obj;  
    return true;
}

//конструктор
function DHTMLcart(swf1,swf2,yspace) {
        if(isIE) {
            var id = "bn"+zPos
            document.write('<div style="visibility:hidden;position:absolute;left:0;top:'+yMax+';width:1;padding:0;z-index:'+(zPos++)+';background-color:black;" id="'+id+'"><table cellpadding=0 cellspacing=0 border=0 border="1"><tr height=18>');
            document.write('<td align="right" valign="center" id="'+id+'h" style="cursor:hand; COLOR: #ffc801; FONT-FAMILY: arial,verdana; FONT-WEIGHT: bold; FONT-SIZE: 9pt;">реклама&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="'+id+'.style.visibility=\'hidden\';return false;">');
            document.write('<img src="pics/bc.gif" onmouseout="this.src=\'pics/bc.gif\';" onmouseover="this.src=\'pics/bcw.gif\';" title="Закрыть" alt="Закрыть" width=9 height=9 border=0></a>&nbsp;</td></tr>');
            document.writeln('<tr bgcolor=#ffc801><td>'+insertSWF(swf1)+'</td></tr>');
            if(swf2) document.writeln('<tr bgcolor=#ffc801><td style="border-top:solid '+yspace+'px black;">'+insertSWF(swf2)+'</td></tr>');
            document.writeln('</table></div>');
            document.draggedDHTMLcart = null;
            if (!document.DHTMLcarts) document.DHTMLcarts = Array();
            document.DHTMLcarts.push( this );
            this.id = id;
                this.rootDocObj = document.all[this.id];
            this.rootDocHead = document.all[this.id+'h'];
                this.rootDocHead.onmousedown = DHTMLcartDrag;
            this.rootDocHead.DHTMLcart = document.DHTMLcarts.length - 1;
    }
}

function insertSWF(name) {
    return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'+
    ' width="100" height="100">'+
    ' <param name="movie" value="'+name+'">'+
    ' <param name="menu" value="false">'+
    ' <param name="quality" value="high">'+
    ' <param name="bgcolor" value="#FFC801">'+
    ' <embed src="'+name+'" menu="false" quality="high" bgcolor="#FFFFFF" '+
    '  width="100" height="100" type="application/x-shockwave-flash" '+
    '  pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'+
    '</object>';
}

if(isIE) {
        saveLoad = window.onload;
        saveSize = window.onresize;
    window.onload = StartBaner;
}
