//----------------------------------------------------------------
var xshowAlt_event = {
  offX: 8,
  offY: 12,
  ready: false,

  v_div_id: "alt_html",
  v_div: null,
  
//----------------------------------------------------------------
  init: function() {
    if ( document.createElement && document.body && typeof document.body.appendChild != "undefined" ) {
      var el = document.createElement("DIV");
      el.className = "divalt";
      el.id = this.v_div_id;
      document.body.appendChild(el);
      this.ready = true;
    }
  },
  
//----------------------------------------------------------------
  show: function(e, msg) {

    this.v_div = document.getElementById( this.v_div_id );

    xGetAll();

    if ( this.v_div && typeof this.v_div.innerHTML != "undefined" ) this.v_div.innerHTML = msg;

    this.positionTip(e);

    //setTimeout("document.getElementById('" + xshowAlt_event.v_div_id + "').style.visibility = 'visible'",500);	
    document.getElementById(xshowAlt_event.v_div_id).style.visibility = 'visible';

    },
    
    positionTip: function(e) {
      var x = e.pageX? e.pageX: e.clientX + v_scrollX;
      var y = e.pageY? e.pageY: e.clientY + v_scrollY;

      //  設定位置判定
      //--------------------------------
      if ( x + this.v_div.offsetWidth + this.offX > v_width + v_scrollX ){
        x = x - this.v_div.offsetWidth - this.offX;
      }else{
        x = x + this.offX;
      }
      if ( y + this.v_div.offsetHeight + this.offY > v_height + v_scrollY ){
        y = ( y - this.v_div.offsetHeight - this.offY > v_scrollY )? y - this.v_div.offsetHeight - this.offY : v_height + v_scrollY - this.v_div.offsetHeight;
      }else{
        y = y + this.offY;
      }
      //--------------------------------

      this.v_div.style.left = x + "px"; this.v_div.style.top = y + "px";

    },
    
//----------------------------------------------------------------
    hide: function() {

      document.getElementById(this.v_div_id).style.visibility = 'hidden'
      this.v_div = null;

    }

}
//----------------------------------------------------------------
xshowAlt_event.init();



//----------------------------------------------------------------
var v_width = 0;
var v_height = 0;
var v_scrollX = 0;
var v_scrollY = 0;
//----------------------------------------------------------------
function xGetAll(){
    xGetWinWidth();
    xGetWinHeight();
    xGetScrollX();
    xGetScrollY();
}

function xGetWinWidth(){
    v_width = 0;
    if (window.innerWidth) v_width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		v_width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		v_width = document.body.clientWidth;
}

function xGetWinHeight(){
    v_height = 0;
    if (window.innerHeight) v_height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		v_height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		v_height = document.body.clientHeight;
}

function xGetScrollX(){
    v_scrollX = 0;
  	if (typeof window.pageXOffset == "number") v_scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		v_scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		v_scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) v_scrollX = window.scrollX;
}

function xGetScrollY(){
    v_scrollY = 0;    
    if (typeof window.pageYOffset == "number") v_scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		v_scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		v_scrollY = document.body.scrollTop; 
  	else if (window.scrollY) v_scrollY = window.scrollY;
}

//----------------------------------------------------------------

sflag=0;
function xshowAlt(e, msg) {
  if ( typeof xshowAlt_event == "undefined" || !xshowAlt_event.ready ) return;
  xshowAlt_event.show(e, msg);
sflag=1;
}

function h_Alt(){
  if ( typeof xshowAlt_event == "undefined" || !xshowAlt_event.ready ) return;
  xshowAlt_event.hide();
}
function xhideAlt() {
 	h_Alt();
}
