﻿var tip_offsetLeft = 5;
var tip_offsetTop = 15;
var tipDiv = false;
var MSIE = false;
var Opera = false;
var midBar = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
if(navigator.userAgent.indexOf('Opera')>=0)Opera=true;
var iframeObj2 = false;
var showed = false;

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null ) node = document;
	if ( tag == null ) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else
		elm['on' + evType] = fn;
}

function wr_bottomBar( )
{
	var bottomBar = document.createElement( 'DIV' );
	bottomBar.id = 'bottomBar';
	tipDiv.appendChild( bottomBar );	
}
//
function wr_topBar( )
{
	var topBar = document.createElement( 'DIV' );
	topBar.id = 'topBar';
	tipDiv.appendChild( topBar );
}
//
function wr_midBar( )
{
	midBar = document.createElement( 'DIV' );
	midBar.id = 'midBar';
	tipDiv.appendChild( midBar );
}
//
function hideTip( )
{
	tipDiv.style.display='none';
	if ( iframeObj2 ) iframeObj2.style.display='none';
	showed = false;
}

function moveTip( e )
{
	if ( !showed ) return;
	e = (e) ? e : ((window.event) ? window.event : "");
	if (MSIE)
	{
		var b = document.getElementsByTagName( 'body' )[0];

		var yScroll = 0;
	    if (self.pageYOffset) {
	        yScroll = self.pageYOffset;
	    } else if (document.documentElement && document.documentElement.scrollTop){     // Explorer 6 Strict
	        yScroll = document.documentElement.scrollTop;
	    } else if (document.body) {// all other Explorers
	        yScroll = document.body.scrollTop;
	    }
		
		tempX = event.clientX + b.scrollLeft;
		tempY = event.clientY + yScroll;
	}
	else
	{
    	tempX = e.pageX;
	    tempY = e.pageY;
	}
	if ( tempX < 0 ) { tempX = 0; }
	if ( tempY < 0 ) { tempY = 0; }  
	tipDiv.style.left = parseInt( tempX + tip_offsetLeft ) + 'px';
	tipDiv.style.top = parseInt( tempY + tip_offsetTop ) + 'px';
	if ( iframeObj2 )
	{
		iframeObj2.setAttribute( "left", tipDiv.style.left );
		iframeObj2.setAttribute( "top", tipDiv.style.top );
	}
}
//
function showTip( e )
{
	e = (e) ? e : ((window.event) ? window.event : "");
	tipDiv.style.visibility = 'visible';	
	tipDiv.style.display = 'block';
	if ( iframeObj2 )
	{
//		iframeObj2.style.display = '';
		iframeObj2.style.display = 'none';
		iframeObj2.style.height = tipDiv.offsetHeight + 'px';
		iframeObj2.style.width = tipDiv.offsetWidth + 'px';	
		title = e.srcElement.ttitle;
	}
	else
	title = this.getAttribute('ttitle');
	midBar.innerHTML = title;
	showed = true;
	moveTip( e );
}
//
function initTips ( )
{
	var b = document.getElementsByTagName( 'body' )[0];
	if(MSIE)
	{
		iframeObj2 = document.createElement('IFRAME');
		iframeObj2.setAttribute("position", "absolute" );
		iframeObj2.setAttribute("border", "0px");
		iframeObj2.setAttribute("backgroundColor", "#FF0000" );
		iframeObj2.setAttribute("frameBorder", "0"); 
		iframeObj2.setAttribute("scrolling", "no"); 
		b.appendChild( iframeObj2 );
	}
	tipDiv = document.createElement('DIV');	
	tipDiv.id = 'tipDiv';
	b.appendChild( tipDiv );
	wr_topBar( );
	wr_midBar( );
	wr_bottomBar( );
	hideTip( );
	var arr = getElementsByClass( "wzc" );
	for ( i in arr )
	{
		addEvent( arr[ i ], "mouseover", showTip, false );
		addEvent( arr[ i ], "mousemove", moveTip, false );
		addEvent( arr[ i ], "mouseout", hideTip, false );
	}
}
if (window.addEventListener) window.addEventListener("load",initTips,false);
	else if (window.attachEvent) window.attachEvent("onload",initTips);
