/* ////////////////////////////////////////
  Semaphore, LLC Handy Global Functions
  
  Change Date: 2007/03/14
  
  Interface Design and Programming: Brian Sage, semaphorellc.com
//////////////////////////////// */




// Default Global Variables used by scripts below
if (!ss) var ss = new Array();
if (!ss.global) ss.global = new Array();
if (!ss.global.documentRoot) ss.global.documentRoot = '/';
if (!ss.global.cssRoot) ss.global.cssRoot = ss.global.documentRoot + 'stylesheets/';
if (!ss.global.graphicsRoot) ss.global.graphicsRoot = ss.global.documentRoot + 'graphics/';

// Browser detect for IE6 fixer code all over
ss.global.ver = navigator.appVersion.split('MSIE');     // This ridiculous bit of code must be...
ss.global.agentVerNo = parseFloat( ss.global.ver[1] );  // ...on 2 lines.
var isIe6 = false; if ( (ss.global.agentVerNo >= 5.5) && (ss.global.agentVerNo < 7) ) isIe6 = true; // OK, so it's actually IE 5.5-6, but no one uses 5.5. We may as well give it a chance. Maybe we'll crash it and they'll upgrade.




/* ////////////////////////////////////////
 addEvent()
 Version 1.0 - June 19, 2007 
 
 How it works:
 Creates a common method for adding event handlers to DOM objects.
 
 Use:
 ss.addEvent( domElementLocator, 'click|load|etc', runthisfunctionnamehere, true|false bubble event );
 
 Requires:
 nothing

 Returns: n/a
//////////////////////////////////////// */

ss.addEvent = function (obj, evt, func, capture) {
	if(obj.addEventListener) {
		obj.addEventListener(evt, func, capture);
	}
	else if(obj.attachEvent) {
		obj.attachEvent('on' + evt, func);
	}
	else {
		alert("Your web browser doesn't support modern websites.\n\nGet ready for a new view of the world.\n\nGet Firefox....");
		window.location = 'http://www.getfirefox.com/';
	}
}




/* ////////////////////////////////////////
 Create Debug Output Window
 
 How it works:
 Creates textarea#debugoutput, appended within <body>, if (ss.dbo == 1).
 Otherwise creates ss.dbo as an Array, to store output from dependant functions.
 
 Use:
 	ss.dbo = 1;
 	ss.dbo.value += 'This will append a line to the dbo box for all to see\n';

 Returns: n/a
//////////////////////////////// */

if( !ss.dbo ) ss.dbo = new Array();
if( ss.dbo == 1) {
	ss.dbo = new Array();
	ss.dbo.createDbo = true;
} else {
	ss.dbo = new Array();
}

if( ss.dbo.createDbo == true ) {
	// create textarea.dbo node for placement
	ss.dbo = document.createElement('textarea');
	ss.dbo.id = 'debugoutput';
	ss.dbo.setAttribute('wrap', 'off');
	ss.dbo.style.cssText = 'font-size: 11px; position: fixed; left: 10px; bottom: 10px; height: 250px; width: 98%; z-index: 100000; background: #eee; border: 1px solid #999; padding: 2px; overflow: auto;';
	ss.appendDbo = function () {
		document.getElementsByTagName('body')[0].appendChild(ss.dbo);
		document.getElementsByTagName('body')[0].style.paddingBottom = ss.dbo.style.height;
		ss.dbo = document.getElementById('debugoutput');
		ss.dbo.value += ("ss.dbo created successfully!\n");
	}
	ss.addEvent( window, "load", ss.appendDbo, false );
}

ss.dbo.showArray = function ( gimmeAnArray )
{
	ss.dbo.value += "dboArray() :\n";
	ss.dbo.value += "	0=[" + gimmeAnArray[0] + "]";
	for (var i = 1; i < gimmeAnArray.length; i++)
	{
		ss.dbo.value += "."+i+"=[" + gimmeAnArray[i] + "]";
	}
	ss.dbo.value += "\n";
}




/* ////////////////////////////////////////
 getParentNodesByTagName( Starting Element, 'query nodeName' )
 
 How it works:
 returns an Array of parent elements, of matching nodeName, starting
 from the Starting Element argument.
  
 Use:
 	getParentNodesByTagName ( document.getElementById('foo'), 'div' ) {

 Returns: Element Reference Array
//////////////////////////////// */

getParentNodesByTagName = function( targ, tag ) {
	var parentNodesByTagName = new Array();
	var loopPoint = targ;
	while( loopPoint.nodeName != 'BODY' ) {
		if( loopPoint.nodeName == tag ) parentNodesByTagName.push( loopPoint );
		loopPoint = loopPoint.parentNode;
	}
	return parentNodesByTagName;
}
getFirstParentNodeByTagName = function( targ, tag ) {
	var firstParentNodeByTagName = new Array();
	var loopPoint = targ;
	while( loopPoint.nodeName != 'BODY' ) {
		if( loopPoint.nodeName == tag ){
			firstParentNodeByTagName.push( loopPoint );
			return firstParentNodeByTagName;
		}
		loopPoint = loopPoint.parentNode;
	}
	return firstParentNodeByTagName;
}




/* ////////////////////////////////////////
 getParentNodesByClassName( Starting Element, 'query className' )
 
 How it works:
 returns an Array of parent elements, with matching classNames, starting
 from the Starting Element argument.
  
 Use:
 	getParentNodesByClassName ( document.getElementById('foo'), 'someClass_name' ) {

 Returns: Element Reference Array
//////////////////////////////// */

getParentNodesByClassName = function( targ, classNameQ ) {
	var parentNodesByClassName = new Array();
	var loopPoint = targ;
	while( loopPoint.nodeName != 'BODY' )
	{
		if( loopPoint.className == classNameQ ) parentNodesByClassName.push( loopPoint );
		loopPoint = loopPoint.parentNode;
	}
	return parentNodesByClassName;
}




/* ////////////////////////////////////////
 solveForE( e )
 
 How it works:
 e is the target of a mouse event, handled differently by nearly every browser.
 This function returns an normalized object element reference that can be used by
 all browsers.
  
 Use: 
 	<a href="#" id="theATag">foo</a>
	<script type=text/javascript>
		$(theATag).onclick = function(e) {
			var elementRef = solveForE( e );
			elementRef.style.backgroundColor = 'black'; //turns the link background black.
		}
	</script>

 Returns: Element Reference
//////////////////////////////// */

function solveForE(e)
{
	var targ;

	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()
 Version 1.1 - March 12, 2007 
 
 How it works:
 Fixes PNG transparencies in MSIE 5.5 and 6.
 Replaces <img src="x.png" /> with <img src="dot_clear.gif" style="adds MS transparency filter to x.png">
 
 Use:
 Place the following at the end of the document, just before the </body> tag or after the last <img src=*.png">
 <script type="text/javascript"></script>
 Just let it run.
 
 Requires:
  * ss.global.graphicsRoot be set. If it's not set, it will use /graphics/
  * graphicsRoot/dot_clear.gif

 Returns: n/a
//////////////////////////////////////// */

ss.fixPNG = new Array();

ss.fixPNG.fix = function ( theImg ) {
	if ( isIe6 && (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="'+ ss.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;
	}
}

ss.fixPNG.init = function() {
	for( i = document.getElementsByTagName('IMG').length; i > 0; i-- ) {
		ss.fixPNG.fix( document.getElementsByTagName('IMG').item( i -1 ) );
	}
}




// Load Announce
ss.dbo.value += ("ss.global.js loaded\n");