// JavaScript Document
// class TtipData
// code by Azer Manafov (azerman[at]hotmail[dot]com)

// cursor position trailing
var GLB_CURSOR            =  {x:-1, y:-1};
var HELPER_EVENT_HANDLERS = new Array( );

window.onload = cursorposinit;
function cursorposinit()
{	if ( window.Event )
	{	document.captureEvents(Event.MOUSEMOVE |  Event.MOUSEDOWN | Event.MOUSEUP);
	}
	document.onmousemove = mouseEventHandler;
	document.onmousedown = mouseEventHandler;
	document.onmouseup   = mouseEventHandler;
//	document.onclick     = mouseEventHandler;
}
function mouseEventHandler(e)
{
	e = e || window.event;
	for( var hlp in HELPER_EVENT_HANDLERS )
	     GLB_CURSOR = HELPER_EVENT_HANDLERS[hlp].onMouseEvent(e);
}
// end cursor position trailing

function clsTtipData( id, pointW, pointH, imgW, imgH, nameImgOn, nameImgOff, nameImgSub )
{
	var m_id		 = id;
	var m_ptW        = pointW;
	var m_ptH        = pointH;
	var m_imgW       = imgW;
	var m_imgH       = imgH;
	var m_nameImgOn  = nameImgOn;
	var m_nameImgOff = nameImgOff;
	var m_nameImgSub = nameImgSub;
	var m_link       = "#";
	var m_alttxt     = '';
	var m_bblend     = false;//true;


	var m_movie	     = null;
	var m_ppos       = new Array(0,0);
	var m_ipos       = new Array(-pointW/2,-pointH/2);

	var m_imgState   = 0;
	var m_img        = new Image( );
	
	this.getId      = getId;
	this.getImgOn  	= getImgOn;
	this.getImgOff 	= getImgOff;
	this.getImgTtip	= getImgTtip;
	this.pheight 	= pheight;
	this.pwidth 	= pwidth;
	this.iheight 	= iheight;
	this.iwidth 	= iwidth;
	this.getLink	= getLink;
	this.setLink	= setLink;
	this.getAlttxt	= getAlttxt;
	this.setAlttxt	= setAlttxt;
	this.setMovie   = setMovie;
	this.getMovie   = getMovie;
	this.setpPos    = setpPos;
	this.getpPos    = getpPos;
	this.setiPos    = setiPos;
	this.getiPos    = getiPos;
	this.enableBlend= enableBlend;
	this.canBlend   = canBlend;
	this.correctTtipPos = correctTtipPos;

	this.isImgComplete = isImgComplete;


	if ( clsTtipData.IMGS_PATH  ==  undefined || !clsTtipData.IMGS_PATH )
	     clsTtipData.IMGS_PATH   =  "images";
	if ( clsTtipData.VIEW_RIGHT	==  undefined || !clsTtipData.VIEW_RIGHT )
		 clsTtipData.VIEW_RIGHT  = 800;
	if ( clsTtipData.VIEW_BOTTOM == undefined || !clsTtipData.VIEW_BOTTOM )
		 clsTtipData.VIEW_BOTTOM = 600;
	if ( clsTtipData.REF_LT_OBJ  == undefined || !clsTtipData.REF_LT_OBJ )
	     clsTtipData.REF_LT_OBJ = "mapRefPoint";

	m_img.onload  = onImgload;
	m_img.onabort = onImgAbort;
	m_img.onerror = onImgError;
	m_img.src     = getImgTtip( );

	function onImgload     ( ) { onComplete(1); }
	function onImgError    ( ) { onComplete(2); }
	function onImgAbort    ( ) { onComplete(2); }
	function onComplete    ( state ) 
	{   m_imgState = state; 
		if ( m_imgState == 1)
		{	if ( m_imgW == 0 ) m_imgW = m_img.width;
			if ( m_imgH == 0 ) m_imgH = m_img.height;
		}
	}
	
	function isImgComplete ( ) { return (m_imgState)?true:false; }

    function correctTtipPos( )
	{	var helper = new clsViewHelper( );
		var thisObj= helper.getElement( m_id );
		if ( !thisObj ) return;
		var thisPos= [parseInt(thisObj.style.left), parseInt(thisObj.style.top)];

		if ( thisPos[0] + iwidth() > clsTtipData.VIEW_RIGHT )
		     m_ipos[0] = -(thisPos[0] + iwidth() - clsTtipData.VIEW_RIGHT );
		if ( thisPos[1] + iheight() > clsTtipData.VIEW_BOTTOM )
		     m_ipos[1] = -(thisPos[1] + iheight() - clsTtipData.VIEW_BOTTOM );
	}
	
	function getId 		( )	{ return m_id; }
	function getImgOn 	( )	{ return clsTtipData.IMGS_PATH + '/' + m_nameImgOn; }
	function getImgOff	( ) { return clsTtipData.IMGS_PATH + '/' + m_nameImgOff; }
	function getImgTtip	( ) { return clsTtipData.IMGS_PATH + '/' + m_nameImgSub; }
	function pwidth		( ) { return m_ptW;  }
	function pheight	( ) { return m_ptH;  }
	function iwidth		( ) 
	{   if ( m_imgW == 0 ) m_imgW = m_img.width; 
		return m_imgW; 
	}
	function iheight	( )	
	{   if ( m_imgH == 0 ) m_imgH = m_img.height;
		return m_imgH; 
	}
	function getLink	( ) { return m_link; }
	function setLink	( linktxt ) { m_link = linktxt; }
	function getAlttxt	( ) { return m_alttxt; }
	function setAlttxt	( alttxt ) { m_alttxt = alttxt; }
	function setMovie	( obj ) { m_movie = obj;}
	function getMovie	( ) { return m_movie;}
	
	function enableBlend( blend ) { m_bblend = blend; }
	function canBlend	( ) { return m_bblend; }
	
	function setpPos	( x,y ) { m_ppos[0] = x; m_ppos[1] = y; }
	function getpPos	( ) { return m_ppos; }
	function setiPos	( x,y ) { m_ipos[0] = x; m_ipos[1] = y; }
	function getiPos	( ) { return m_ipos; }

};// end class clsTtipData

function clsFlashLayer( id, f_name, width, height, flashvars)
{
	var m_genericId  = id;
	var m_id         = 'movie'+id;
	var m_style      = new Object();
	var m_shtml      = '';
	var m_fname      = f_name;
	var m_width      = width;
	var m_height     = height;
	var m_sflashvars = flashvars;
	
	this.createFlashLayer	= createFlashLayer;
	this.getGenericId       = getGenericId;
	this.getId				= getId;
	this.preStyle			= preStyle;
	this.setStyle			= setStyle;
	this.resStyle			= resStyle;
	
	function getGenericId    ( ) { return m_genericId; }
	function getId    		 ( ) { return m_id; }
	function getDiv          ( ) { return getElement(m_id); }
	function createFlashLayer( )
	{	
		document.write(getFlashContent( m_width, m_height, m_fname, m_sflashvars));
		setStyle( );
	}
	function resStyle( ) { m_style = new Object( ); }
	function preStyle( )
	{	resStyle( );
		for ( var i=0; i < arguments.length; i=i+2)
		{	var currArg = arguments[i].toLowerCase();    
			m_style[currArg] = arguments[i+1];
	  	}
	}
	function setStyle( )
	{	var obj = getElement( m_id );
		if ( !obj ) return;
		for ( var i in m_style)
			  obj.style.setAttribute(i,m_style[i]);
	}
	function getFlashContent( width, height, movie, flashvars)
	{	
		var str='';		
		str+=' <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"';
		str+=' width="'+width+'" height="'+height+'">\n';

		str+=' <param name="movie"     value="'+movie+'" /> \n';
		str+=' <param name="quality"   value="high" /> \n';
		str+=' <param name="loop"      value="true" /> \n';
		str+=' <param name="wmode"     value="transparent" /> \n';
		
		if ( flashvars )
		     str+=' <param name="flashvars" value="'+flashvars+'" /> \n';
		
		var str2='<embed pluginpage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high"';
	
		str2+=' width="'+width+'" height="'+height+'"';
		str2+=' src="'+movie+'"';
		str2+=' wmode="transparent"';
		str2+=' flashvars="'+flashvars+'"';
		str2+=' > \n';
		
		str+=str2;
		str+='</OBJECT>\n';
		return str;
	}
	function getElement( id )
	{	if ( document.getElementById )
	         return document.getElementById( id );
		if ( document.all!=null )
      		 return document.all   [id];
    	else return document.layers[id];
	}
};

// class clsViewHelper
function clsViewHelper()
{
	var tipBkgColor         = "#f6e9cf";
	var m_fnMouseListener   = null;
	this.setOpacity 		= setOpacity;
	this.setVisible 		= setVisible;
	this.swapImages 		= swapImages;
	this.getElement			= getElement;
	this.findPos2           = findPos2;
	this.findPos			= findPos;
	this.showTtip   		= showTtip;
	this.goToUrl            = goToUrl;
	this.onMouseEvent		= onMouseEvent;
	this.pointInObject		= pointInObject;
	this.setTipBkg			= setTipBkg;
	this.setMouseListener   = setMouseListener;
	this.setDivPos			= setDivPos;
	this.getCursorPos       = getCursorPos;
	this.getInstanceId      = getInstanceId;
	this.allsetMouseListener= allsetMouseListener;
	
	this.ltrim				= ltrim;
	this.rtrim				= rtrim;
	this.trim				= trim;

	var bAllSupport         = document.all!=null;
	var m_cursor_pos		= { x:-1, y:-1 };
	var m_instanceid        = 0;
	
	if ( clsViewHelper.INSTANCE == undefined )
	     clsViewHelper.INSTANCE = 0;
	else clsViewHelper.INSTANCE++;
	clsViewHelper.TTIP_DIV_ID = 'tipView';
	clsViewHelper.TTIP_ZINDEX = 40;
	
	m_instanceid = clsViewHelper.INSTANCE;
	
	registerHelper( this );

	function allsetMouseListener( listener )
	{   for( var hlp in HELPER_EVENT_HANDLERS )
			 HELPER_EVENT_HANDLERS[hlp].setMouseListener(listener);
	}

	function registerHelper( helper )
	{   for( var hlp in HELPER_EVENT_HANDLERS )
		{   if ( HELPER_EVENT_HANDLERS[hlp].getInstanceId() == helper.getInstanceId())
	        	return;
		}
		HELPER_EVENT_HANDLERS.push(helper);
	}
	function getInstanceId( ) { return "helper"+m_instanceid;}
	function setTipBkg    ( bkgColor )
	{
		tipBkgColor = bkgColor;
	}
	function getElement   ( id )
	{	if ( document.getElementById )
	         return document.getElementById( id );
		if ( bAllSupport )
      		 return document.all   [id];
    	else return document.layers[id];
	}
	
	function setVisible( id, enable )
	{	
		if ( id <=0 ) return;
	    var NNtype  ='show'; 
	    var IEtype  ='visible'; 
		var WC3type ='visible';
		
		if ( enable != 'visible' )
		{   NNtype  = 'hidden';
			IEtype  = 'hidden';
			WC3type = 'hidden';
		}
		try
		{   if ( document.getElementById )
				eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
			else
				if (document.layers)
					document.layers[id].visibility = NNtype;
			else
				if (document.all)
					eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
		}
		catch(err) { window.status = err.description+"; Id: "+id; }
	}
	function setOpacity( id, value )
	{	var obj = getElement(id);
		if ( obj == undefined ) return;
		obj.style.opacity      = value/10;
//		obj.style.background   = "transparent";
		
		if ( browser.isIE55 || browser.isIE6x )
			 obj.style.filter       = 'progid:DXImageTransform.Microsoft.Alpha(opacity=\''+value*10 +'\')';
		else obj.style.filter       = 'alpha(opacity=' + value*10 + ')';
	}
	
	function swapImages( id,img)
	{	var obj = getElement(id);//document.getElementById(id);
		if ( obj == undefined ) return;
		obj.src = img;
		
	}
//http://blog.firetree.net/2005/07/04/javascript-find-position/	
	function getXpos(elem)
	{	while (elem != null && !elem.offsetParent) elem = elem.parentNode;
		if (elem == null) return 0;
		return (elem.offsetLeft + getXpos(elem.parentNode))
	}
	function getYpos(elem)
	{	while (elem != null && !elem.offsetParent) elem = elem.parentNode;
		if (elem == null) return 0;
		return (elem.offsetTop + getYpos(elem.parentNode))
	}
	function cumulativeOffset( element )
	{   var valueT = 0, valueL = 0;
    	do
		{   valueT += element.offsetTop  || 0;
      		valueL += element.offsetLeft || 0;
      		element = element.offsetParent;
    	} while (element);
    	return [valueL, valueT];
    }
	function cumulativeScrollOffset( element )
	{   var valueT = 0, valueL = 0;
        do 
		{   valueT += element.scrollTop  || 0;
            valueL += element.scrollLeft || 0;
            element = element.parentNode;
        } while (element);
        return [valueL, valueT];
   }
   function findPos2( id )
	{  	var obj     = ( typeof id == 'object')?id:getElement( id );
		if ( obj == undefined ) return [-1,-1];
		var pos1 = cumulativeOffset      ( obj );
		var pos2 = cumulativeScrollOffset( obj );
		return [pos1[0] - pos2[0],pos1[1]-pos2[1]];
		

   }
// from http://www.quirksmode.org/js/findpos.html#
	function findPos( id )
	{  	
		var obj     = ( typeof id == 'object')?id:getElement( id );
	  	if ( obj == undefined ) return [-1,-1];
		var curleft = 0;
		var curtop  = 0;
		if ( obj.offsetParent )
		{	curleft = obj.offsetLeft;
			curtop  = obj.offsetTop;
			while ( (obj = obj.offsetParent))
			{	//if (obj.scrollLeft) { curleft -= obj.scrollLeft; }// ?
				//if (obj.scrollTop ) { curtop  -= obj.scrollTop;  }// ?
			    curleft += obj.offsetLeft;
				curtop  += obj.offsetTop;
			}
		}
		return [curleft,curtop];
	}
	function setDivPos      ( id, aPos )
	{	var obj     = getElement( id );
		if ( !obj ) return;
		if ( obj.style )
		{	obj.style.left = aPos[0];
			obj.style.top  = aPos[1];
		}
	}
	function createTtipLayer( idName )
	{
		if ( !document.createElement ) return null;
		var ttipNode = document.createElement("div");
		document.body.appendChild(ttipNode);
		ttipNode.setAttribute("id", idName );
		ttipNode.style.position   = "absolute";
		ttipNode.style.background = tipBkgColor;
		ttipNode.style.border     = "1pt black solid";
		ttipNode.style.visibility = "hidden";
		ttipNode.style.left       = "0px";
		ttipNode.style.top        = "0px";
		ttipNode.style.zIndex     = clsViewHelper.TTIP_ZINDEX;
		 return ttipNode;
	}
	function showTtip( name, enable, tipTxt,xoffset, yoffset )
	{
		var ttipNode = getElement( clsViewHelper.TTIP_DIV_ID );
		if ( ttipNode == null )
		{	ttipNode = createTtipLayer( clsViewHelper.TTIP_DIV_ID );
			if ( ttipNode == null ) return;
		}
		var parent = getElement(name);
		var zindex = clsViewHelper.TTIP_ZINDEX;
		
		if ( parent )
		     zindex = parent.style.zIndex + 1;

		ttipNode.style.zIndex = (zindex >= clsViewHelper.TTIP_ZINDEX)?zindex:clsViewHelper.TTIP_ZINDEX;

		var ptob = findPos   ( name );
		if ( !xoffset ) xoffset=0;
		if ( !yoffset ) yoffset=40;
		if ( enable )
		{   if ( !tipTxt ) return;
			var str ='';
			str+='<B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tipTxt+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>';
		
			ttipNode.style.pixelLeft = ptob[0]+xoffset;
			ttipNode.style.pixelTop  = ptob[1]+yoffset;
			ttipNode.innerHTML = str;
			setVisible( clsViewHelper.TTIP_DIV_ID, 'visible');
		}
		else
		{
			setVisible( clsViewHelper.TTIP_DIV_ID, 'hidden');
		}
	
	}
	//http://www.hscripts.com/scripts/JavaScript/cursor-position.php
	function onMouseEvent( e )
	{
		e = e || window.event;
		var cursor = {x:-1, y:-1};
		
		if ( !e ) return cursor;
	
		if (e.pageX || e.pageY)
		{
			cursor.x = e.pageX;
			cursor.y = e.pageY;
		} 
		else
		{
			var de = document.documentElement;
			var b  = document.body;
			cursor.x = e.clientX + 
				(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
			cursor.y = e.clientY + 
				(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
		}
		if ( m_fnMouseListener )
		     m_fnMouseListener(e);
			 
		m_cursor_pos = cursor;	 
		
		return cursor;
	}
	function getCursorPos    ( ) { return m_cursor_pos; }
	function setMouseListener( fnUserMouseListener )
	{
		m_fnMouseListener = fnUserMouseListener;
	}
	function pointInObject( id, w, h )
	{	var apos = findPos(id);
		var w    = (w == null )?60:w;
		var h    = (h == null )?60:h;
		if ( !apos ) return false;
		if ( (apos[0] <= m_cursor_pos.x && m_cursor_pos.x <= apos[0]+w) &&  (apos[1] <= m_cursor_pos.y && m_cursor_pos.y <= apos[1]+h))
			  return true;
		return false;	  
	}

	function goToUrl( strUrl)
	{	
		window.location=strUrl;
	//	window.location.href = strUrl;
		return true;
	}
	function ltrim( src )
	{   if ( !src.length ) return "";
		var posL = 0;
		while( isWhitespace(src.charAt(posL)) && posL < src.length ) posL++;
		return src.substring( posL );
	}
	function rtrim( src )
	{   if ( !src.length ) return "";
		var posR = src.length - 1;
		while( isWhitespace(src.charAt(posR)) && posR > 0 ) posR--;
		return src.substring( 0,posR+1);
	}
	function trim( str )
	{   str = dcdSpaces( str ); 
		return ltrim(rtrim(str));
	}
	function isWhitespace( charToCheck )
	{   var whitespaceChars = " \t\n\r\f";
		return (whitespaceChars.indexOf( charToCheck ) != -1);
    }
	function dcdSpaces( src )
	{	var i;
		while( ( i = src.indexOf( "&nbsp;")) != -1 )
		{   src = src.substring( 0, i ) + ' ' + src.substring( i+6 );
		}
		return src;
	}
};// end class clsViewHelper

//default helper object
visi = new clsViewHelper( );