/****************************

 Global JavaScript functions and conditions for IFWORLD web site projects
 Version:
 	1.0, Beta 1.3, 26 Jan 2007

 Usage:
 	This file must be included within <body>
	<script type="text/javascript" src="IFscript.global.js"></script>

****************************/




/****************************
 Global variables for IFWORLD web site projects.
****************************/
if (!IFs) var IFs = new Array();
if (!IFs.global) IFs.global = new Array();

if (!IFs.global.documentRoot) IFs.global.documentRoot = '/';
if (!documentRoot) var documentRoot = IFs.global.documentRoot;
if (!IFs.global.graphicsRoot) IFs.global.graphicsRoot = IFs.global.documentRoot + '_graphics/';
if (!IFs.global.flashRoot) IFs.global.flashRoot = IFs.global.documentRoot + '_flash/';

// Optional DeBugging Output, set to 1 or true for output window
if (!IFs.global.dbo) IFs.global.dbo = 0;




/****************************
 documentOnloadQ()
 
 How it works:
 Create a queue of functions to run once the window has loaded all
 HTML-specified content
 
 Use:
 	function documentOnloadQ()
	{
		functionToExecute();
		anotherFunctionToExecute();
		anotherFunctionTo... and so on...
	}
 	window.onload = documentOnloadQ; 

 Returns: n/a
****************************/
IFs.global.documentOnloadQ = function ()
{
}
window.onload = IFs.global.documentOnloadQ; 





/****************************
 Create Debug Output Window
 
 How it works:
 Creates textarea#debugoutput, appended within <body>, if (dbo == 1).
 
 Use:
 	IFs.global.dbo = 1;
 	IFs.global.dbo.value += 'This will append a line to the dbo box for all to see\n';

 Returns: n/a
****************************/
if (IFs && IFs.global && IFs.global.dbo)
{
	if (IFs.global.dbo == 1)
	{
		// create textarea.dbo node for placement
		IFs.global.dbo = document.createElement('textarea');
		IFs.global.dbo.id = 'debugoutput';
		IFs.global.dbo.wrap = 'off';
		IFs.global.dbo.style.position = 'fixed';
		IFs.global.dbo.style.left = '10px';
		IFs.global.dbo.style.bottom = '10px';
		IFs.global.dbo.style.height = '250px';
		IFs.global.dbo.style.width = '98%';
		IFs.global.dbo.style.zIndex = '50000';
		IFs.global.dbo.style.backgroundColor = '#eeeeee';
		IFs.global.dbo.style.borderWidth = '1px';
		IFs.global.dbo.style.borderStyle = 'solid';
		IFs.global.dbo.style.borderColor = '#999999';
		IFs.global.dbo.style.padding = '2px';
		IFs.global.dbo.style.overflow = 'auto';
		document.getElementsByTagName('body').item(0).appendChild(IFs.global.dbo);
		document.getElementsByTagName('body').item(0).style.paddingBottom = IFs.global.dbo.style.height;
		IFs.global.dbo = document.getElementById('debugoutput');
		IFs.global.dbo.value += ("IFs.global.dbo created successfully!\n");
	}
	else
	{
		IFs.global.dbo = new Array();
	}
}




/****************************
 solveForE()
 
 How it works:
  Helpful handy dandy script that handles clicks for different browser DOMs
 
 Use & Returns:
  You'll know when you need it.
****************************/
IFs.global.solveForE = function (e)
{
	// ...make var targ out of different browser event handling models
	if (!e) var e = window.event;                  // for IE's event model
	if (e.target) targ = e.target;                 // for W3C/Moz Event model
	else if (e.srcElement) targ = e.srcElement;    // also for IE's event model
	if (targ.nodeType == 3)                        // defeat Safari bug (thanks, quirksmode.org)
	targ = targ.parentNode;                        // realize the target node, itself
	
	return targ;
}




/****************************
 fixPNG()
 
 How it works:
 Fixes PNG transparencies in MSIE 5.5 and 6.
Replaces <img src="x.png" /> with dot_clear.gif
 
 Use:
 Just let it run.
 
 Requires:
 IFs.global.graphicsRoot is set.

 Returns: n/a
****************************/
IFs.global.fixPNG = new Array();
IFs.global.ver = navigator.appVersion.split('MSIE');      // This ridiculous bit of code must be...
IFs.global.agentVerNo = parseFloat( IFs.global.ver[1] );  // ...on 2 lines.

IFs.global.fixPNG.fix = function ( theImg ) {
	if ( (IFs.global.agentVerNo >= 5.5) && (IFs.global.agentVerNo < 7) && (document.body.filters) && (theImg.src.indexOf('.png') > 0) ) {
		// Make new HTML to swap with the target <img>. Yeah it's sloppy, and not filled with DOM-goodness, but it's a hack for IE 6, whaddayagonnado?
		var strOldStyle = '';
		var strOldClassName = (theImg.className!='')?(' class="'+theImg.className+'"'):('');
		if ( theImg.outerHTML.indexOf('style="')>0 ) {
			var subStr1 = theImg.outerHTML.slice( theImg.outerHTML.indexOf('style="') + 7 );
			strOldStyle = subStr1.slice( 0, subStr1.indexOf('"') ) + ';';
		}
		var strNewHTML = '<img'+ strOldClassName +' src="'+ IFs.global.graphicsRoot +'dot_clear.gif" alt="'+ theImg.alt +'" style="'+ strOldStyle +'width: '+ theImg.width +'px; height: '+ theImg.height +"px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +theImg.src+ "', sizingMethod='scale'" +');">';
		theImg.outerHTML = strNewHTML;
	}
}

for( i = document.getElementsByTagName('IMG').length; i > 0; i-- ) {
	IFs.global.fixPNG.fix( document.getElementsByTagName('IMG').item( i -1 ) );
}




/****************************
 Loaded Announce
****************************/
IFs.global.dbo.value += ("IFs.global.js loaded!\n");