// JavaScript Document
function msgBox(init)
{
   var _i = init;  
   this.container = _i.container==undefined ? "ads_14" :_i.container;
   this.dragArea = _i.dragArea==undefined ? "drag" : _i.dragArea;
   this.imgPath = _i.imgPath==undefined ? "." : _i.imgPath;
   this.width =  _i.width==undefined ? 282 : _i.width;
   this.height = _i.height==undefined ?235 : _i.height;
   this.smallHeight = _i.smallHeight==undefined? 27: _i.smallHeight;
   this.smallId = _i.smallId==undefined ? "small" : _i.smallId;
   this.closeId = _i.closeId==undefined ? "close" : _i.closeId;
   this.area = ( document.compatMode.toLowerCase()=="css1compat" ) ? document.documentElement : document.body;
   this.space = _i.space==undefined ?15:_i.space;
   this.position = _i.position == undefined ?'right': _i.position;
   this.timer;
   this.zIndex = _i.zIndex==undefined ? 10000 : _i.zIndex;
   this.timeOut = 150;
   this.smalled = false;
   var msgBoxListener = this;
   this.$(this.smallId).onclick= function(){msgBoxListener.toSmall()};
   this.$(this.closeId).onclick = function(){msgBoxListener.close()};
}
msgBox.prototype.flow = function()
{
   if(this.$(this.container)==undefined) return;		
   this.$(this.container).style.position = "absolute";
   this.$(this.container).style.zIndex = this.zIndex;
   if(this.smalled)
   {
    this.$(this.container).style.top = this.area.scrollTop + this.area.clientHeight - this.smallHeight - this.space + "px";
   }else{
    this.$(this.container).style.top = this.area.scrollTop + this.area.clientHeight - this.height - this.space + "px";
   }
   if(this.position=='right')
	    this.$(this.container).style.left = this.area.scrollLeft + this.area.clientWidth - this.width - this.space + "px";
   else
   		this.$(this.container).style.left = 0 + "px";
}
msgBox.prototype.toSmall = function()
{
   if(this.smalled)
   {
    this.$(this.smallId).src = this.imgPath+"/small.gif";
    this.$(this.container).style.marginTop = -this.height + "px";
    this.$(this.container).style.height = this.height + "px";
    this.$(this.container).style.overflow = "hidden";
    this.smalled = false;
    this.flow();
    this.$(this.container).style.marginTop = "0px";
   }else{
    this.$(this.smallId).src = this.imgPath+"/big.gif";
    this.$(this.container).style.height = this.smallHeight + "px";
    this.$(this.container).style.overflow = "hidden";
    this.smalled = true;
    this.flow();
   }
}
msgBox.prototype.close = function()
{
   document.body.removeChild(this.$(this.container));
}
msgBox.prototype.auto = function()
{
   this.flow();var msgBoxListener =this;
  // window["onresize"]=function(){msgBoxListener.flow();};
  //   window["onscroll"]=function(){msgBoxListener.flow();};
  var func = function(){msgBoxListener.flow();};
  var old1 = window.onresize ;
	if (typeof window.onresize != 'function') {
		window.onresize = func;
	} else {
		window.onresize = function() {
			old1();
			func();
		}
	}
	var old = window.onscroll ;
	if (typeof window.onscroll != 'function') {
		window.onscroll = func;
	} else {
		window.onscroll = function() {
			old();
			func();
		}
	}
	
/*   this.addfuncEvent(function(){msgBoxListener.flow()},window.onresize);
   this.addfuncEvent(function(){msgBoxListener.flow()},window.onscroll);*/
   document.onmousedown = function(){clearInterval(msgBoxListener.timer);msgBoxListener.drag(msgBoxListener.container, msgBoxListener.dragArea);};
}
msgBox.prototype.drag = function(container, drag)
{
   var IMOUSEDOWN = true;
   var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
   container = document.getElementById(container);
   drag = document.getElementById(drag);
   if(drag)
   {
    try{
      if(IMOUSEDOWN){
       drag.onmousedown=function(a){
        var d=document;
        if(!a)a=window.event;
        drag.style.cursor="move";
        var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
        if(drag.setCapture)
        drag.setCapture();
        else if(window.captureEvents)
        window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
        d.onmousemove=function(a){
         if(!a)a=window.event;
         if(!a.pageX)a.pageX = (a.clientX<0 ?0:a.clientX);
         if(!a.pageY)a.pageY = (a.clientY <0 ?0:a.clientY);
         var tx = a.pageX-x, ty = a.pageY-y;
         if(isIE){
          ty = ty + document.documentElement.scrollTop - document.documentElement.clientTop;
         }
         container.style.position = "absolute";
          container.style.left = tx+"px";
          container.style.top = ty+"px";
        };
        d.onmouseup=function(){
         if(drag.releaseCapture)
         drag.releaseCapture();
         else if(window.captureEvents)
         window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
         d.onmousemove=null;
         d.onmouseup=null;
        };
       };
      }else{
       container.style.cursor="pointer";
       drag.style.cursor="move";
      }
    }catch(e){
     	// alert(e);
		return;
    }
   }
}
msgBox.prototype.$ = function(ele)
{
   return document.getElementById(ele);
}

msgBox.prototype.addfuncEvent = function (func,eve) {	
	var old = eve ;
	if (typeof eve != 'function') {
		eve = func;
	} else {
		eve = function() {
			old();
			func();
		}
	}
}
