/* THESE FUNCTIONS ARE USED FOR THE TITANIC EVENTS AREA */
var ost_MAXDEPTHR = 1000;

function ost_isAnchorNode(node) {
	return ostNodeNameFilter(node, 'a');
}
	
/* returns an array (actual array) of children - only useful if you filter */
function ostGetChildren(node, filter /* [, filterargs...] */) {
	var newargs = [node, 1].concat(Array.prototype.slice.call(arguments, 1));	/* probably not the most effecient way of doing this */
	return ostGetDescendents.apply(this, newargs);
}
/* compares the node.nodeName to the namespec insensitively */
function ostNodeNameFilter(node, tagName) {
	return !!node.nodeName && node.nodeName.toUpperCase() == tagName.toUpperCase();
}
function __getDescendentsCallback(node, gdobj) {
	gdobj.filterargs[0] = node;
	if (gdobj.filter.apply(this, gdobj.filterargs)) {
		gdobj.results.push(node);
	}
	return false /* don't stop the iterator */
}
/* dummy function that returns true
 * combine with similar functions in this file
 *  */
function __ostReturnTrue() { return true; }
function __ostReturnFalse() { return false; }
/* should also have unwind capability */
/* create an EX version with the extended caps */
/* returns an array containing the descendents matched by filterfunc */
function ostGetDescendents(parent, depth, filter /*, filterargs */) {
	var filterargs = Array.prototype.slice.call(arguments, 3);
	filterargs.unshift(null);
	 
	var gdObj = {
		results: new Array(),
		filter: filter || __ostReturnTrue,
		filterargs: filterargs
	 };
	ostIterateDescendents(parent, depth, __getDescendentsCallback, gdObj);
	return gdObj.results;	
}


/* the business end of iteratedescendents */
function __doIterateDescendents(parent, curdepth, maxdepth, func, args) {
	var retval = false;
	var children = parent.childNodes;
	if (!!children && !!children.length) {
		for (var n=0, l=children.length; n<l; ++n) {
			if (!!children[n]) { /* it is possible for children to have a null */
				args[0] = children[n];
				retval = func.apply(null, args);
				if (!retval && maxdepth > curdepth) __doIterateDescendents(args[0], curdepth+1, maxdepth, func, args); 
			}
		}
	}
	return retval;
}

/* general function to iterate the descendents of a node and perform an operation on them */
/* parent is the parent node (with .childNodes) */
/* any args past func will be passed to the callback function */
/* func is called in the global context (this==window) so be sure to bind if you need it
	to act on an object
	if func returns true (or something that evaluates as true, this stops)
	
	todo: need to be able to short circuit the unwind (check type)
	
	 */
	 
function ostIterateDescendents(parent, depth, func /*, args... */) {
	depth = depth || ost_MAXDEPTHR;
	/* ourargs is an array with arguments to send to callback function
		the first slot is reserved for the node we're looking at
	 */
	var ourargs = Array.prototype.slice.call(arguments, 3 /* ostIterateDescendents.length */);
	ourargs.unshift(null);
	return __doIterateDescendents(parent, 1, depth, func, ourargs);
}

function ostIsBoolean(v) {
	return typeof(v) == "boolean";
}

var iseventclassRE = /\bevent\b/;
var isactiveclassRE = /(\s*\bactive_event\b\s*)/;

function clearActiveEventCallback(node, true_active_node) {
		if (!!!node.className) return true;	// probably a text node
		if (node == true_active_node) {
			node.className = node.className + ' active_event';
		} else {
			node.className = node.className.replace(isactiveclassRE, ' ');//leaves a space	
		}
}

/* mouse over event handler */
function eventOnMouseOver() {
	if (this.className.search(isactiveclassRE) > -1) return false;
	ostIterateDescendents(this.parentNode, 1, clearActiveEventCallback, this);
}
var evcnt = 0;
function setEventOnMouseOverCallback(node) {
	if (node.nodeName == 'DIV' && !!node.className && node.className.search(iseventclassRE) > -1) {
		node.onmouseover = eventOnMouseOver;
		if (evcnt == 0) {
			eventOnMouseOver.apply(node);
		}
		evcnt++;
	}
	return false;
}
/* END OF FUNCTIONS FOR TITANIC EVENTS AREA */
