/* Begin: skinIt.com - skinIt 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: 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: 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 = '';
					//document.getElementById(selectArr[i].rel).getElementsByTagName('a');
					if ((this.id == 'keyword') || (this.id=='birth') || (this.id=='searchInput') || (this.name=='pin') || (this.name=='enterpincode')) {
						if (this.value == this.defaultValue) this.value = '';
					} //else {
					//	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 ----------------*/
	/*------------- BEGIN: randomizer ----------------*/
	function randomizer() { return Math.random(); }
	window['TM']['randomizer'] = getStyle;
	/*------------- END: getStyle ----------------*/
/*------------- END: Appended Functions ----------------*/
/*------------- END: TragicNamespace ----------------*/
})();

/* BEGIN: skinIt onload events */
/*--------------------------------*/
TM.addEvent(window, 'load', function() {
	TM.resetFields();
	customSelect();
	if(navigator.appVersion.match('MSIE 6.0')) ie6Rollovers();
});

/* BEGIN: skinIt custom functions */
/*------------------------------------*/
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 = document.getElementById(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;
	}
}
function ie6Rollovers() {
	var quickViewCont = TM.getElementsByClassName('quickViewCont', 'li');
	for(i=0; i<quickViewCont.length; i++) {
		var el = quickViewCont[i];
		TM.addEvent(quickViewCont[i],'mouseover', function() {
			var links = this.getElementsByTagName('a');
			for(n=0; n<links.length; n++) {
				if(links[n].className.match('quickView')) links[n].style.backgroundPosition = 'bottom left';
				else this.style.color = '#99cc66';
			}
		});
		TM.addEvent(quickViewCont[i],'mouseout', function() {
			var links = this.getElementsByTagName('a');
			for(n=0; n<links.length; n++) {
				if(links[n].className.match('quickView')) links[n].style.backgroundPosition = 'top left';	
				else this.style.color = '#373737';
			}
		});
	}
}
