function Anim(anim_type, maxx, maxy) {

    
    // 1 - left - right
    // 2 - right to left
    // 3 - top to bottom
    // 4 - bottom to top

    // if maxx && maxy == 0 then maxx = maxx = 
    //var self = this;
    // flash must change variables below. If object moves by Y axis then this.Xmax should be 0, if object moves by X axis, then Ymas should be 0


    //alert (anim_type);

    var self = this;

    

    Ymax=0;                                //MAX # OF PIXEL STEPS IN THE "X" DIRECTION
    this.Xmax = 11;
    //this.Xmax=11;                                //MAX # OF PIXEL STEPS IN THE "Y" DIRECTION
    Tmax=10000;                        //MAX # OF MILLISECONDS BETWEEN PARAMETER CHANGES

    //FLOATING IMAGE URLS FOR EACH IMAGE. ADD OR DELETE ENTRIES. KEEP ELEMENT NUMERICAL ORDER STARTING WITH "0" !!

    this.floatimages=new Array();
    this.floatimages[0]='/PopUpBanner/PopUpBanner.swf';

    //this.playIt = playIt;

    NS4 = (navigator.appName.indexOf("Netscape")>=0 && parseFloat(navigator.appVersion) >= 4 && parseFloat(navigator.appVersion) < 5)? true : false;
    IE4 = (document.all)? true : false;
    NS6 = (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape")>=0 )? true: false;
    wind_w ='' , wind_h='', t='', this.IDs=new Array();

    for(var i=0; i<this.floatimages.length; i++)
    {
        t+=(NS4)?'<layer name="pic'+i+'" visibility="visible" width="10" height="10">' : '<div id="pic'+i+'" style="position:absolute; visibility:visible;width:10px; height:10px">';
        t+='<embed src="'+this.floatimages[i]+'" name="p'+i+'" width="100" height="100" wmode="transparent" bgcolor="#ffffff" base="/PopUpBanner/" align="middle"/>';
        t+=(NS4)? '</layer>':'</div>';
    }
    document.write(t); 
    
        if (NS4||NS6||IE4){

        window.onresize = function(){ 
            wind_w=self.getwindowwidth(); 
         
            wind_h=self.getwindowheight(); 
        }
    }
    

}

Anim.prototype = {

    getscrollx: function()
    {
        if(NS4 || NS6)return window.pageXOffset;
        if(IE4)return document.body.scrollLeft;
    },

    getscrolly: function()
    {
        if(NS4 || NS6)return window.pageYOffset;
        if(IE4)return document.body.scrollTop;
    },

    getid: function(name)
    {
        if(NS4)return document.layers[name];
        if(IE4)return document.all[name];
        if(NS6)return document.getElementById(name);
    },

    moveidto: function(num,x,y)
    {
        if(NS4)this.IDs[num].moveTo(x,y);
        if(IE4 || NS6){
            this.IDs[num].style.left=x+'px';
            this.IDs[num].style.top=y+'px';
        }
    },

    getidleft: function(num)
    {
        if(NS4)return this.IDs[num].left;
        if(IE4 || NS6)return parseInt(this.IDs[num].style.left);
    },

    getidtop: function(num)
    {
        if(NS4)return this.IDs[num].top;
        if(IE4 || NS6)return parseInt(this.IDs[num].style.top);
    },

    moveidby: function(num,dx,dy)
    {
        if(NS4)this.IDs[num].moveBy(dx, dy);
        if(IE4 || NS6)
        {
            this.IDs[num].style.left=(this.getidleft(num)+dx)+'px';
            this.IDs[num].style.top=(this.getidtop(num)+dy)+'px';
        }
    },

    getwindowwidth: function()
    {
        if(NS4 || NS6)return window.innerWidth;
        if(IE4)return document.body.clientWidth;
    },

    getwindowheight: function ()
    {
		return 800;
//        if(NS4 || NS6)return window.innerHeight;
//		if(IE4)return document.body.clientHeight;
    },

    moveimage: function(num)
    {

        if (this.IDs[num].maxy > 0)
        {
            //right
            //alert (-1* this.IDs[num].maxy);
            
            var stepY = this.IDs[num].Ystep;

            if(this.getidtop(num) <= this.IDs[num].maxy && this.IDs[num].maxy < this.IDs[num].inity)this.IDs[num].Ydir=false;
            if(this.getidtop(num) >= this.IDs[num].maxy && this.IDs[num].maxy > this.IDs[num].inity)this.IDs[num].Ydir=false;
            if(this.getidtop(num)-stepY<=this.getscrolly())this.IDs[num].Ydir=true;

            if (this.IDs[num].maxy < this.IDs[num].inity ) stepY = -1*stepY;

            this.moveidby(num, (this.IDs[num].Xdir)? this.IDs[num].Xstep :  this.IDs[num].Xstep , (this.IDs[num].Ydir)?   stepY:0 );

        } 
        else if (this.IDs[num].maxx > 0) 
        {
	
	        var stepX = this.IDs[num].Xstep;
	
            if(this.getidleft(num) >= this.IDs[num].maxx && this.IDs[num].maxx > this.IDs[num].initx)this.IDs[num].Xdir=false;
            if(this.getidleft(num) <= this.IDs[num].maxx && this.IDs[num].maxx < this.IDs[num].initx)this.IDs[num].Xdir=false;

            if(this.getidleft(num)-stepX<=this.getscrollx())this.IDs[num].Xdir=true;

            if (this.IDs[num].maxx < this.IDs[num].initx ) stepX = -1*stepX;

            this.moveidby(num, (this.IDs[num].Xdir)? stepX :  0 , (this.IDs[num].Ydir)?  this.IDs[num].Ystep:  -this.IDs[num].Ystep);
         }
    },
    
    getnewprops: function(num)
    {
var self  = this;
        if (self.__anim_type == 1 && (self.__maxx==0 && self.__maxy == 0)) {
	        this.IDs[num].maxx = this.getwindowwidth()/2-this.IDs[num].W/2;
	        this.IDs[num].inity = this.getwindowheight()/2-this.IDs[num].H/2;
	        this.IDs[num].maxy = 0;
	        this.IDs[num].initx = 0;
        } else if (self.__anim_type == 2 && (self.__maxx==0 && self.__maxy == 0)) {
	        this.IDs[num].maxx = this.getwindowwidth()/2-this.IDs[num].W/2;
	        this.IDs[num].inity = this.getwindowheight()/2-this.IDs[num].H/2;
	        this.IDs[num].maxy = 0;
	        this.IDs[num].initx = this.getwindowwidth()-this.IDs[num].W/2;
        } else if (self.__anim_type == 3 && (self.__maxx==0 && self.__maxy == 0)) {
	        this.IDs[num].maxx = 0;
	        this.IDs[num].inity = 0;
	        this.IDs[num].maxy = this.getwindowheight()/2-this.IDs[num].H/2;
	        this.IDs[num].initx = this.getwindowwidth()/2-this.IDs[num].W/2;
        } else if (self.__anim_type == 4 && (self.__maxx==0 && self.__maxy == 0)) {
	        this.IDs[num].maxx = 0;
	        this.IDs[num].inity = this.getwindowheight()-this.IDs[num].H/2;
	        this.IDs[num].maxy = this.getwindowheight()/2-this.IDs[num].H/2;
	        this.IDs[num].initx = this.getwindowwidth()/2-this.IDs[num].W/2;
        }  else if (self.__anim_type == 1 && (self.__maxx!=0 || self.__maxy != 0)) {
	        this.IDs[num].maxx = self.__maxx-this.IDs[num].W/2;
	        this.IDs[num].inity = self.__maxy;
	        this.IDs[num].maxy = 0;
	        this.IDs[num].initx = 0;
        }  else if (self.__anim_type == 2 && (self.__maxx!=0 || self.__maxy != 0)) {
	        this.IDs[num].maxx = self.__maxx;
	        this.IDs[num].inity = self.__maxy;
	        this.IDs[num].maxy = 0;
	        this.IDs[num].initx = this.getwindowwidth();
        }  else if (self.__anim_type == 3 && (self.__maxx!=0 || self.__maxy != 0)) {
	        this.IDs[num].maxx = 0;
	        this.IDs[num].inity = 0;
	        this.IDs[num].maxy = self.__maxy;
	        this.IDs[num].initx = self.__maxx;
        }  else if (self.__anim_type == 4 && (self.__maxx!=0 || self.__maxy != 0)) {
	        this.IDs[num].maxx = 0;
	        this.IDs[num].inity = this.getwindowheight();
	        this.IDs[num].maxy = self.__maxy;
	        this.IDs[num].initx = self.__maxx;
        }


        if (self.__anim_type == 1 || self.__anim_type == 2) {
        this.IDs[num].Ydir=/*Math.floor(Math.random()*2)>0*/false;
        this.IDs[num].Xdir=/*Math.floor(Math.random()*2)>0*/true;
        this.IDs[num].Ystep=Math.ceil(Math.random()*Ymax);
        this.IDs[num].Xstep=/*Math.ceil(Math.random()*this.Xmax)*/this.Xmax;
        } else if (self.__anim_type == 3 || self.__anim_type == 4) {
        this.IDs[num].Ydir=/*Math.floor(Math.random()*2)>0*/true;
        this.IDs[num].Xdir=/*Math.floor(Math.random()*2)>0*/false;
        this.IDs[num].Ystep=/*Math.ceil(Math.random()*Ymax)*/this.Xmax;
        this.IDs[num].Xstep=Math.ceil(Math.random()*Ymax);
        }
        //var self = this;
        //setTimeout('getnewprops('+num+')', Math.floor(Math.random()*Tmax));
        //startfly = setInterval(function(){self.moveimage(0)}, 40);
        setTimeout(function()
        {
            self.getnewprops(0), Math.floor(Math.random()*Tmax)
        });
    },


    playIt: function(anim_type, maxx, maxy, sizeX, sizeY, speed, step)
    {

        this.speed = speed;
        this.step = step;
        this.Xmax = this.step;
        
        var n = 0;
        var self =this;
        switch(anim_type)
        {
         case 'fromLeft': n = 1; break;
         case 'fromRight': n = 2; break;
         case 'fromTop': n = 3; break;
         case 'fromBottom': n = 4; break;
         default: alert('Wrong value popup of animation type `'+anim_type+'`');
        }

//n = 4;

              
    this._anim_type = n;
    this._maxx = maxx;
    this._maxy = maxy;

    anim_type = this._anim_type;
    maxx = this._maxx;
    maxy = this._maxy;

    self.__anim_type = n;
    self.__maxx = maxx;
    self.__maxy = maxy;

        wind_w=this.getwindowwidth();
     
		wind_h=this.getwindowheight();
		
	
        //alert ("starting init " + wind_w);

        //alert (getwindowwidth()+" / "+getwindowheight());
        for(var i=0; i<this.floatimages.length; i++)
        {
            this.IDs[i]=this.getid('pic'+i);
            
            if(NS4)
            {
                this.IDs[i].document.embeds["p0"].width = sizeX;
                this.IDs[i].document.embeds["p0"].height = sizeY;
            }
            if(NS6 || IE4)
            {
                document.embeds["p0"].width = sizeX;
				document.embeds["p0"].height = sizeY;
            }
//                this.IDs[0].W=sizeX;
//                this.IDs[0].H=sizeY;
                
            if(NS4)
            {
                this.IDs[i].W=this.IDs[i].document.embeds["p"+i].width;
                this.IDs[i].H=this.IDs[i].document.embeds["p"+i].height;
            }
            if(NS6 || IE4)
            {
                this.IDs[i].W=document.embeds["p"+i].width;
                this.IDs[i].H=document.embeds["p"+i].height;
            }

            //alert (this.IDs[i].W+" / "+this.IDs[i].H);
            this.getnewprops(i);

            //getValues(i);
            //alert(Math.floor(Math.random()*2)>0);
            //alert(Math.floor(Math.random()*2));
            //moveidto(i , Math.floor(Math.random()*(wind_w-this.IDs[i].W)), Math.floor(Math.random()*(wind_h-this.IDs[i].H)));
            
            this.moveidto(i , this.IDs[i].initx, this.IDs[i].inity);
            
            if(NS4)this.IDs[i].visibility = "show";
            if(IE4 || NS6) this.IDs[i].style.visibility = "visible";

            //startfly=setInterval('moveimage('+i+')',/*Math.floor(Math.random()*100)+100*/40);

            var self = this;

            startfly = setInterval(function()
            {
                self.moveimage(0)
            }, this.speed);
        }
    },

    close: function()
    {
               for(var i=0; i<this.floatimages.length; i++)
        {
            if (IE4) eval("document.all.pic"+i+".style.visibility='hidden'")
            else if (NS6)
                document.getElementById("pic"+i).style.visibility='hidden'
            else if (NS4)
                eval("document.pic"+i+".visibility='hide'")
                clearInterval(startfly);
        }
    }
    
}



function printObj(obj, r)
{
    r = (r) ? true : false; 
    var s = "obj{";
    for (var i in obj){
            s += "\n" + i + "=" + obj[i] + "\n";
    }
    s += "}";
    if(r) return s;
    else alert(s);
}


window.PopUpBanner = new Anim();
//window.PopUpBanner.playIt();