/* Begin: TragicMedia.com - Tragic Library
/* created 8/08 by Rich Rudzinski
/*------------------------------------------*/
(function() {
	//The Tragic namespace
	if(!window.TM) { window['TM'] = {} }

	/*------------- BEGIN: isCompatible  ----------------*/
	function isCompatible(other) {
		// Use capability detection to check requirements
		if(other == false || !Array.prototype.push || !Object.hasOwnProperty || !document.createElement || !document.getElementsByTagName) {
			return false;
		} 
		return true;
	}
	window['TM']['isCompatible'] = isCompatible;
	/*------------- END: isCompatible  ----------------*/
	
	/*------------- BEGIN: $  ----------------*/
	function $() {
		var elements = new Array();
		// Find all elements supplied as arguments
		for(var i=0; i<arguments.length; i++) {
			var element = arguments[i];
			//If the argument is a string assume it's an id
			if(typeof element == 'string') {
				element = document.getElementById(element);
			}
			// If only one argument was supplied, return the element immediately
			if(arguments.length == 1) {
				return element;
			}
			// Otherwise add it to the array
			elements.push(element);
		}
		// Return the array of multiple requested elements
		return elements;
	}
	window['TM']['$'] = $;
	/*------------- END: $  ----------------*/
	
	/*------------- BEGIN: addEvent  ----------------*/
	function addEvent(node, type, listener) {
		// Check compatibility using the earlier method to ensure graceful degradation
		if(!isCompatible()) {return false;}
		if(!(node=$(node))) {return false;}
		if(node.addEventListener) {
			// W3C method
			node.addEventListener(type, listener, false);
			return true;
		} else if(node.attachEvent) {
			//MSIE method
			node['e' + type + listener] = listener;
			node[type + listener] = function() {
				node['e' + type + listener](window.event);
			}
			node.attachEvent('on' + type, node[type + listener]);
			return true;
		}
		//Didn't have either so return false
		return false;
	}
	window['TM']['addEvent'] = addEvent;
	/*------------- END: addEvent  ----------------*/
	
	/*------------- BEGIN: removeEvent  ----------------*/
	function removeEvent(node, type, listener) {
		if(!(node=$(node))) {return false;}
		if(node.removeEventListener) {
			// W3C method
			node.removeEventListener(type, listener, false);
			return true;
		} else if(node.detachEvent) {
			//MSIE method
			node.detachEvent('on' + type, node[type + listener]);
			node[type + listener] = null;
			return true;
		}
		//Didn't have either so return false
		return false;
	}
	window['TM']['removeEvent'] = removeEvent;
	/*------------- END: removeEvent  ----------------*/
	
	/*------------- BEGIN: addLoadEvent  ----------------*/
	function addLoadEvent(loadEvent, waitForImages) {
		if(!isCompatible()) return false;
		//If the wait flag is true use the regular add event method
		if(waitForImages) return addEvent(window, 'load', loadEvent);
		//Otherwise use a number of different methods
		//Wrap the loadEvent mehtod to assign the correct content for the this keyword and ansure that the event doesn't execute twice
		var init = function() {
			if(arguments.callee.done) return; // Return if this function has already been called
			arguments.callee.done = true; // Mark this function so you can verify if it was already run
			loadEvent.apply(document, arguments); // Run the load event in the context of the document
		};
		if(document.addEventListener) document.addEventListener('DOMContentLoaded', init, false);
		if(/WebkKit/i.test(navigator.userAgent)) { // For Safari, use a setInterval() to see if the document has loaded
			var _timer = setInterval(function() {
				if(/loaded|complete/.test(document.readyState)) {
					clearInterval(_timer);
					init();
				}
			}, 10);
		}
		// For IE (using conditional comments) attach a script that is deferred to the end of the load process and then check to see if it has loaded
		/*@cc_on @*/
		/*@if(@_win32)
			document.write('<script id=_ie_onload defer src=javascript:void(0)><\/script>');
			var script = document.getElementById('_id_onload');
			script.onreadystatechange = function() {
				if(this.readState == 'complete') init();
			};
		/*@end @*/
		return true;
	}
	window['TM']['addLoadEvent'] = addLoadEvent;
	/*------------- END: addLoadEvent  ----------------*/
	
	/*------------- BEGIN: getEventObject  ----------------*/
	function getEventObject(W3CEvent) {
		return w3CEvent || window.event;
	}
	window['TM']['getEventObject'] = getEventObject;
	/*------------- END: getEventObject  ----------------*/
	
	/*------------- BEGIN: stopPropagation  ----------------*/
	function stopPropagation(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		if(eventObject.stopPropagation) 
			eventObject.stopPropagation();
		else
			eventObject.cancelBubble = true;
	}
	window['TM']['stopPropagation'] = stopPropagation;
	/*------------- END: stopPropagation  ----------------*/
	
	/*------------- BEGIN: preventDefault  ----------------*/
	function preventDefault(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		if(eventObject.preventDefault) 
			eventObject.preventDefault();
		else
			eventObject.returnValue = false;
	}
	window['TM']['preventDefault'] = preventDefault;
	/*------------- END: preventDefault  ----------------*/
	
	/*------------- BEGIN: getTarget  ----------------*/
	function getTarget(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		var target = eventObject.target || eventObject.scrElement; // Check if the target is W3C or MSIE
		if(target.nodeType == TM.node.TEXT_NODE) target = node.parentNode; // Reassign the target to the parent if it is a text node like in Safari
		return target;
	}
	window['TM']['getTarget'] = getTarget;
	/*------------- END: getTarget  ----------------*/
	
	/*------------- BEGIN: getMouseButton  ----------------*/
	function getMouseButton(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		var buttons = {'left':false, 'middle':false, 'right':false}; // Initialize an object with the appropriate properties
		if(eventObject.toString && eventObject.toStinr().indexOf('MouseEvent') != -1) { // Check the toString value of the eventObject, W3C DOM objects have a toString method and in this case it should be MouseEvent
			switch(eventObject.button) { // W3C Method
				case 0: buttons.left = true;
					break;
				case 1: buttons.middle = true;
					break;
				case 2: buttons.right = true;
					break;
				default: break;
			}
		} else if(eventObject.button) {
			switch(eventObject.button) { // MSIE method
				case 0: buttons.left = true;
					break;
				case 1: buttons.right = true;
					break;
				case 3: buttons.left = true;
					buttons.right = true;
					break;
				case 4: buttons.middle = true;
					break;
				case 5: buttons.left = true;
					buttons.middle = true;
					break;
				case 6: buttons.middle = true;
					buttons.right = true;
				case 7: buttons.left = true;
					buttons.middle = true;
					buttons.right = true;
					break;
				default: break;
			}
		} else {
			return false;
		}
		return buttons;
	}
	window['TM']['getMouseButton'] = getMouseButton;
	/*------------- END: getMouseButton  ----------------*/
	
	/*------------- BEGIN: getPointerPosition  ----------------*/
	function getPointerPosition(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		var x = eventObject.pageX || (eventObject.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
		var y = eventObject.pageY || (eventObject.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
		return {'x':x, 'y':y}; // x and y now contain the coordinates of the mouse relative to the document origin.
	}
	window['TM']['getPointerPosition'] = getPointerPosition;
	/*------------- END: getPointerPosition  ----------------*/
	
	/*------------- BEGIN: getKeyPressed  ----------------*/
	function getKeyPressed(eventObject) {
		eventObject = eventObject || getEventObject(eventObject);
		var code = eventObject.keyCode;
		var value = String.fromCharCode(code);
		return {'code':code, 'value':value};
	}
	window['TM']['getKeyPressed'] = getKeyPressed;
	/*------------- END: getKeyPressed  ----------------*/
	
	/*------------- BEGIN: getElementsByClassName  ----------------*/
	function getElementsByClassName(className, tag, parent) {
		parent = parent || document;
		if(!(parent = $(parent))) {return false;}
		// Locate all the matching tags
		var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);
		var matchingElements = new Array();
		// Create a regular expression to determine if the className is correct
		className = className.replace(/\-/g, "\\-");
		var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var element;
		// Check each element
		for(var i=0; i<allTags.length; i++) {
			element = allTags[i];
			if(regex.test(element.className)) {
				matchingElements.push(element);
			}
		}
		// Return any matching elements
		return matchingElements;
	}
	window['TM']['getElementsByClassName'] = getElementsByClassName;
	/*------------- END: getElementsByClassName ----------------*/
	
	/*------------- BEGIN: toggleDisplay ----------------*/
	function toggleDisplay(node, value) {
		if(!(node = $(node))) return false;
		if(node.style.display != 'none') {
			node.style.display = 'none';
		} else {
			node.style.display = value || '';
		}
		return true;
	}
	window['TM']['toggleDisplay'] = toggleDisplay;
	/*------------- END: toggleDisplay ----------------*/

		/*------------- BEGIN: toggleClass ----------------*/
	function toggleClass(node, newClass) {
		if(!(node = $(node))) return false;
		if(node.className.match(newClass)) {
			node.className = node.className.replace(newClass, '');
			return newClass;
		} else {
			node.className += ' ' + newClass;
			return;
		}
	}
	window['TM']['toggleClass'] = toggleClass;
	/*------------- END: toggleClass ----------------*/
	
	/*------------- BEGIN: insertAfter ----------------*/
	function insertAfter(node, referenceNode) {
		if(!(node = $(node))) return false;
		if(!(referenceNode = $(referenceNode))) return false;
		return referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
	}
	window['TM']['insertAfter'] = insertAfter;
	/*------------- END: insertAfter ----------------*/
	
	/*------------- BEGIN: removeChildren ----------------*/
	function removeChildren(parent) {
		if(!(parent = $(parent))) return false;
		while(parent.firstChild) { //while there is a child remove it
			parent.firstChild.parentNode.removeChild(parent.firstChild);
		}
		return parent; //return the parent again so you can chain methods
	}
	window['TM']['removeChildren'] = removeChildren;
	/*------------- END: removeChildren ----------------*/
	
	/*------------- BEGIN: prependChild ----------------*/
	function prependChild(parent, newChild) {
		if(!(parent = $(parent))) return false;
		if(!(newChild = $(newChild))) return false;
		if(parent.firstChild) {
			parent.insertBefore(newChild, parent.firstChild); //there is already a first child so insert before the first one
		} else {
			parent.appendChild(newChild); //no children so just append
		}
		return parent; //Return the parent again so you can chain the methods
	}
	window['TM']['prependChild'] = prependChild;
	/*------------- END: prependChild ----------------*/
	
	/*------------- BEGIN: bindFunction ----------------*/
	function bindFunction(obj, func) {
		return function() {
			func.apply(obj, arguments);
			return false;
		}
	}
	window['TM']['bindFunction'] = bindFunction;
	/*------------- END: bindFunction ----------------*/
	
	/*------------- BEGIN: getBrowserWindowSize ----------------*/
	function getBrowserWindowSize() {
		var de = document.documentElement;
		return {
			'width':(window.innerWidth || (de && de.clientWidth) || document.body.clientWidth),
			'height':(window.innerHeight || (de && de.clientHeight) || document.body.clientHeight)
		}
	}
	window['TM']['getBrowserWindowSize'] = getBrowserWindowSize;
	/*------------- END: getBrowserWindowSize ----------------*/
	
	/*------------- BEGIN: nodeConstants ----------------*/
	window['TM']['node'] = {
		ELEMENT_NODE:1,
		ATTRIBUTE_NODE:2,
		TEXT_NODE:3,
		CDATA_SELECTION_NODE:4,
		ENTITY_REFERENCE_NODE:5,
		ENTITY_NODE:6,
		PROCESSING_INSTRUCTION_NODE:7,
		COMMENT_NODE:8,
		DOCUMENT_NODE:9,
		DOCUMENT_TYPE_NODE:10,
		DOCUMENT_FRAGMENT_NODE:11,
		NOTATION_NODE:12
	};
	/*------------- END: nodeConstants ----------------*/
	
	/*------------- BEGIN: walkElementsLinear ----------------*/
	function walkElsLinear(func, node)	{
		var root = node || window.document;
		var nodes = root.getElementsByTagName('*');
		for(var i=0; i<nodes.length; i++) {
			func.call(nodes[i]);
		}
	}
	window['TM']['walkElsLinear'] = walkElsLinear;
	/*------------- END: walkElementsLinear ----------------*/
	
	/*------------- BEGIN: walkDOM ----------------*/
	function walkDOM(func, node, depth, returned) {
		var root = node || window.document;
		var returned = func.call(root, depth++, returned);
		var node = root.firstChild;
		while(node) {
			walkDOM(func, node, depth, returned);
			node = node.nextSibling;
		}
	}
	window['TM']['walkDOM'] = walkDOM;
	/*------------- END: walkDOMRecursive ----------------*/
	
	/*------------- BEGIN: walkDOMAttributes ----------------*/
	function walkDOMAttributes(func, node, depth, returned) {
		var root = node || window.document;
		var returned = func.call(root, depth++, prefix);
		if(root.attributes) {
			for(var i=0; i<root.attributes.length; i++) {
				walkDOMAttributes(func, root.attributes[i], depth-1, returned);
			}
		}
		if(root.nodeType != Node.ATTRIBUTE_NODE) {
			var node = root.firstChild;
			while(node) {
				walkDOMAttributes(func, node, depth, returned);
				node = node.nextSibling;
			}
		}
	}
	window['TM']['walkDOMAttributes'] = walkDOMAttributes;
	/*------------- END: walkDOMAttributes ----------------*/
	/*------------- BEGIN: modify string object ----------------*/
	/* repeat a string */
	if(!String.repeat) {
		String.prototype.repeat = function(l) {
			return new Array(l+1).join(this);
		}
	}
	/* Remove trailing and leading whitespace */
	if(!String.trim) {
		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,'');
		}
	}
	/* camel case */
	function camelCase(s) {
		return s.replace(/-(\w)/g, function(strMatch, p1) {
			return p1.toUpperCase();
		});
	}
	window['TM']['camelCase'] = camelCase;
	/*------------- END: modify string object ----------------*/

/*------------- BEGIN: Appended Functions ----------------*/
	/*------------- BEGIN: opacityEffect ----------------*/
	/*initialize opacity variables 
	make sure to set the elements style/filter property before making the function call. Also endOpacity must be a property of "content" ie: content.endOpacity
	opacityCont.style.opacitySpeed = 60;
	opacityCont.style.opacity = 0;
	opacityCont.style.filter = 'alpha(opacity='+0*100+')'; 
	opacityCont.endOpacity = 1;
	TM.animateOpacity(this.content);
	*/
	function setOpacity() {
		clearTimeout(this.timer);
		if(this.endOpacity == 1 && this.style.opacity < this.endOpacity) {
			this.style.opacity = this.style.opacity*1 + .1; // multiply by 1 to typecast
			this.style.filter = 'alpha(opacity='+this.style.opacity*100+')';
			this.timer = setTimeout(TM.bindFunction(this, TM.setOpacity), this.opacitySpeed);
		} else if (this.endOpacity == 0 && this.style.opacity > this.endOpacity) {
			this.style.opacity = this.style.opacity - .1;
			this.style.filter = 'alpha(opacity='+this.style.opacity*100+')';
			this.timer = setTimeout(TM.bindFunction(this, TM.setOpacity), this.opacitySpeed);
		} else {
			clearTimeout(this.timer);
			this.style.opacity = this.endOpacity; 
			this.style.filter = 'alpha(opacity='+this.endOpacity*100+')';
		}
	}
	window['TM']['setOpacity'] = setOpacity;
	function animateOpacity(content) {
		content.timer = setTimeout(TM.bindFunction(content, TM.setOpacity), content.opacitySpeed);
	}
	window['TM']['animateOpacity'] = animateOpacity;
	/*------------- END: opacityEffect ----------------*/
	/*------------- BEGIN: resetFields ----------------*/
	function resetFields() {
		var inputArray = document.getElementsByTagName('input');
		for(j=0;j<inputArray.length;j++){
			if(inputArray[j].type == 'text') {
				inputArray[j].onfocus = function() {
					if (this.value == this.defaultValue) this.value = '';
				}
				inputArray[j].onblur = function() {
					if(this.value == '') this.value = this.defaultValue;
				}
			}
		}
	}
	window['TM']['resetFields'] = resetFields;
	/*------------- END: resetFields ----------------*/
	/*------------- BEGIN: getStyle ----------------*/
	function getStyle(el, styleProp) {
		if (el.currentStyle)
			var y = el.currentStyle[styleProp];
		else if(window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
		return parseInt(y);
	}
	window['TM']['getStyle'] = getStyle;
	/*------------- END: getStyle ----------------*/
	/*------------- BEGIN: randomizer ----------------*/
	function randomizer() { return Math.random(); }
	window['TM']['randomizer'] = getStyle;
	/*------------- END: getStyle ----------------*/
	/*------------- BEGIN: custom select ----------------*/
	function customSelect() {
		var selectArr = TM.getElementsByClassName('customSelect', 'a');
		for(i=0; i<selectArr.length; i++) {
			var selectTarget = TM.getElementsByClassName('customSelectInput', 'input', selectArr[i].parentNode)[0]; 
			var selectLinks = $(selectArr[i].rel).getElementsByTagName('a');
			for(n=0; n<selectLinks.length; n++) {
				selectLinks[n].onclick = function() {return updateParent(this);} 
			}
		}
		var updateParent = function(self) {
			for(k=0; k<selectArr.length; k++) {
				if(selectArr[k].getAttribute('rel') == self.parentNode.parentNode.id) {
					selectArr[k].innerHTML = self.innerHTML;
					var target = TM.getElementsByClassName('customSelectInput', 'input', selectArr[k].parentNode)[0];
					target.value = self.innerHTML;
				}
			}
			return false;
		}
	}
	/*------------- END: custom select ----------------*/
	/*------------- BEGIN: debug ----------------*/
	function debug(err) {
		if(console.log)
			console.log(err);
		else if(window.console)
			window.console.log(err);
		else
			alert(err);
	}
 /*------------- END: debug ----------------*/
 /*----------------------------*/
/*------------- END: Appended Functions ----------------*/
/*------------- END: TragicNamespace ----------------*/
})();
/* BEGIN: onload events */
/*--------------------------------*/
TM.addEvent(window, 'load', function() {

});