// 	infolib.js
//
//	overlib replacement package
//	Requires infoDiv <DIV> in document
//	Dunc
//	07-01-04

idiv_cap = "";
infolibTimerId = 0;
ltisOnlineOpacity = '95';
ltisCurrId = 0;

function infolib (
	title, titleBgColour, titleClass, htmlContent, htmlContentBgColour, htmlContentClass, timerMSecs, type, siteRef )
	{
		
	var tableWidth = 350;
	var tableHeight = 100;
	var imgnam = null;
	var x;
	var y;
	var isVMS = false;
	var infotitle = 'INFO';

				
	iDiv = document.getElementById ( "infoDiv" );
	if ( !iDiv ) {
		//	Probable programmer error
		alert ( "<DIV> infoDiv not found in document!" );
		return;
		}

	// iDiv.style.filter='alpha(opacity=100)';
	// filter:DXImageTransform.Microsoft.Alpha(opacity=50)
	iDiv.style.filter='DXImageTransform.Microsoft.Alpha(opacity=100)';
	iDiv.style.opacity=1.0;

	ltisCurrId = 0;
		
	if ( infolib.arguments.length > 7 ) {
		imgnam = infolib.arguments[7];
		if ( imgnam == 'ltis-online' || imgnam == 'vms' ) {
			// iDiv.style.filter='alpha(opacity=' + ltisOnlineOpacity + ')';	//	For IE 5.5 up
			iDiv.style.filter='DXImageTransform.Microsoft.Alpha(opacity=' + ltisOnlineOpacity + ')';	//	For IE 5.5 up
			iDiv.style.opacity=ltisOnlineOpacity/100.0;						//	For CSS 3, eg Firefox
			}
			
		if ( imgnam == 'vms' ) {
			tableWidth = 177;
			isVMS = true;
			}

		if ( infolib.arguments.length == 10 ) {
			//	ltis event id
			ltisCurrId = infolib.arguments[9];
			}
			
		}
				
	idiv_cap = title;
		
	//	Table style - CSS3 doesn't have borderColor so use inline style...
	tabstyle = "style='border: 1px solid " + titleBgColour + "'";

	//txt = "<table id='infoTab' cellpadding=0 cellspacing=0 border=1 borderColor=" + titleBgColour + " width=" + tableWidth + ">";
	txt = "<table " + tabstyle + " id='infoTab' cellpadding=0px cellspacing=0px width=" + tableWidth + "px >";

	//	Start TABLE ROW for TITLE BAR
	//	==============================

	
	txt += "<tr>";
	/*
	txt += "<td bgcolor=" + titleBgColour + " class=" + titleClass + " align=left>" + title + "</td>";
	
	//	Close anchor on same row as title (like overlib)...
	txt += "<td bgcolor=" + titleBgColour + " class=" + titleClass + " align=right>";
	txt += "<a href='javascript:infolibHide();'>Close</a>";
	txt += "</td>";
	*/
	txt += "<td width=" + tableWidth + "px height=\"16px\">";
	txt += "<table cellpadding=0px cellspacing=0px width=" + tableWidth + "px height=16px border=0px>";	// HW <table height=16px is not XHTML
	txt += "<tr>";
	if ( imgnam == 'vms' )
		infotitle = title;
	// if ( mode == 'vcs' )
		// infotitle = title;


	txt += "<td background='./images/infolibstrip-left.gif' width=330px height=16px class=standard>" + infotitle + "</td>";

	if ( imgnam == 'vms' )
		txt += "<td background='./images/infolibstrip-left.gif'width=30px height=16px class=standard>" + siteRef + "</td>";
		
	//alert(siteRef);

	//LKL Accessibility - added access key - replaced images/cctvstrip-right.gif with images/cctvstrip-right2.gif
	//Put an underline in the image to indicate the short cut key
	txt += "<td width=20px height=16px>";
	txt += "<a accesskey='x' href='javascript:infolibHide();'><img  alt='Close' title='Close' src='./images/cctvstrip-right2.gif' border='0px' /></a>";
	txt += "</td>";
	txt += "</tr></table>";


	txt += "</td>";
	txt += "</tr>";

	//	===========================
	//	End TABLE ROW for TITLE BAR

		
	//	html content...
	txt += "<tr><td colspan=2 bgcolor=" + htmlContentBgColour + " class=" + htmlContentClass + " align=left>" + htmlContent + "</td></tr>";
	

	if ( imgnam != null ) {
		if ( imgnam != 'ltis-online' && imgnam != 'vms' )
			txt += "<tr><td colspan=2 bgcolor=" + htmlContentBgColour + "><img src=" + imgnam + " /></td></tr>";
		//x = 40;
		//y = 40;
		}
	else {
		var iTab = document.getElementById("infoTab");
		x = event.x;
		y = event.y;
		iDiv.style.left = infolibCalcLeftPos ( x, iTab.width ) + "px";
		iDiv.style.top = infolibCalcTopPos ( y, 85 ) + "px";
		}
		
	//	end of table...
	txt += "</table>";
	
	//	Insert into div...
	iDiv.innerHTML = txt;
		
	//	Position the div and make it visible...
	
		
		
	if ( infolibDisplay == true ) {
		if ( timerMSecs > 0 )
			infolibTimerId = setTimeout ( 'infolibTimerFunc()', timerMSecs );
		else {
			iDiv.style.visibility = "visible";
			if (wchExists)
				WCH.Apply(iDiv,'',true);
			}
		}
	else {
		iDiv.style.visibility = "hidden";
		}
	
	}

function infolibIsVisible () {

	var iDiv = document.getElementById ( "infoDiv" );
	if ( !iDiv ) return false;

	if ( iDiv.style.visibility == "visible" )
		return true;

	return false;

	}

	
function infolibTimerFunc () {

	if (typeof(wchExists) == 'undefined')
		return;

	var iDiv = document.getElementById ( "infoDiv" );
	if ( !iDiv ) return;
	
	iDiv.style.visibility = "visible";
	infolibTimerId = 0;
	if (wchExists)
		WCH.Apply(iDiv,'',true);
	
	}
	
function infolibClearTimeout () {

	if ( infolibTimerId == 0 )
		return;
		
	clearTimeout ( infolibTimerId );
	infolibTimerId = 0;
	
	} 
	
function infolibCalcLeftPos ( mousex, tablewid ) {
	var maxx = 600-10;
	var x = mousex;
	while ( x > (maxx-tablewid) )
		x--;
	return x;
	}
	
function infolibCalcTopPos ( mousey, tablehgt ) {
	var maxy = 400-10;
	var y = mousey;
	while ( y > (maxy-tablehgt) )
		y--;
	return y;
	}


function infolibMouseOut () {
	if ( infolibDisplay == true )
		return;
	infolibHide ();
	}
	
function infolibHide () {
	var elem = document.getElementById("infoDiv");
	if ( !elem ) return;
	if (wchExists) 
		WCH.Discard('infoDiv');

	elem.style.visibility = "hidden";
	}
	
function infolibOn () {
	infolibDisplay = true;
	}
	
function infolibOff () {
	infolibDisplay = false;
	infolibHide ();
	}
	
function infolibContextMenu () {
	if ( infolibDisplay == true )
		return;
	iDiv.style.visibility = "visible";
	}
	
function infolibIsOn () {
	return infolibDisplay;
	}
	
function infolibGetCurrLTISId () {
	return ltisCurrId;
	}
	
