var Tooltip = {};
Tooltip.Box = function(conf) {
	conf = conf == null ? {} : conf;
	Tooltip.id = Tooltip.id == null ? 1 : ++Tooltip.id;
	var _template = conf.template == null ? '<div class="tooltipshare">' +
              '<div class="linetop-left"></div>' +
              '<div class="linetop-right"></div>' +
              '<div class="boxtip">' +
              '<div class="headertip"><span id="{1}">{4}</span><a href="javascript:void(0)" class="tipclosebtn" id="{0}"></a></div>' +
              '<div class="bodytip" id="{2}">{5}</div>' +
              '<div class="footertip" id="{3}">{6}</div>' +
              '</div>' +
              '<div class="linebot-left"></div>' +
              '<div class="linebot-right"></div>' +
              '</div>' : conf.template;
	var _container = null;
	var	_header = null;
	var	_body = null;
	var	_footer = null;	
	
  function stringFormat(text){
		if (arguments.length <= 1)				
			return text;
		var tokenNum = arguments.length - 2;
		for(var i = 0; i <= tokenNum; i++) {
			text = text.replace(new RegExp("\\{" + i + "\\}", "gi"), arguments[i + 1]);
		}
		return text;
	}
	
	function hide() {
		_isShow = false;	
			
	}
	
	function init() {
		var idCloseBtn = 'mktooltipclosebtn' + Tooltip.id;
  	var idHeader = 'mktooltipheader' + Tooltip.id;
  	var idBody = 'mktooltipbody' + Tooltip.id;
  	var idFooter = 'mktooltipfooter' + Tooltip.id;
  	
		var txtHeader = conf.header == null ? '' : conf.header;
		var txtBody = conf.body == null ? '' : conf.body; 
		var txtFooter = conf.foooer == null ? '' : conf.foooer;
		_overlay = document.createElement('div');
		_overlay.id = 'tooltipOverlay';
		_container = document.createElement('div');
		_container.innerHTML = stringFormat(_template, idCloseBtn, idHeader, idBody, 
													idFooter, txtHeader, txtBody, txtFooter);
	
		
													
		_container.style.display = 'none';
		_overlay.style.display = 'none';
		_container.style.position = 'absolute';
		_container.style.zIndex = 100000;
		var body = document.getElementsByTagName('body')[0];
		body.appendChild(_overlay);
		body.appendChild(_container);
		var closeBtn = document.getElementById(idCloseBtn);
		closeBtn.onclick = function(){_container.style.display = 'none';}
		_overlay.onclick = function(){_container.style.display = 'none';_overlay.style.display='none' }
		_header = document.getElementById(idHeader);
		_body = document.getElementById(idBody);
		_footer = document.getElementById(idFooter);		
	}
	
	this.show = function(x, y) {
		_container.style.display = 'block';
		_overlay.style.display = 'block';
		if (x != null && y != null) {
			this.moveTo(x, y);
		}
	};
	this.hide = function() {
		_container.style.display = 'none';
	};
	this.moveTo = function(x, y) {
  	_container.style.top = y + "px";
  	_container.style.left = x + "px";
	};
	this.setHeader = function(text) {
		_header.innerHTML = text;
	};
	this.setBody = function(text) {
		_body.innerHTML = text;
	};
	this.setFooter = function(text) {
		_footer.innerHTML = text;
	};
	
	init();	
	return this;
}