/* Version 0.4 - Simon Willison, March 25th 2003 - http://simonwillison.net/2003/Mar/25/getElementsBySelector/ */
function getAllChildren(e){return e.all?e.all:e.getElementsByTagName('*')}document.getElementsBySelector=function(selector){if(!document.getElementsByTagName){return new Array()}var tokens=selector.split(' ');var currentContext=new Array(document);for(var i=0;i<tokens.length;i++){token=tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');if(token.indexOf('#')>-1){var bits=token.split('#');var tagName=bits[0];var id=bits[1];var element=document.getElementById(id);if(tagName&&element.nodeName.toLowerCase()!=tagName){return new Array()}currentContext=new Array(element);continue}if(token.indexOf('.')>-1){var bits=token.split('.');var tagName=bits[0];var className=bits[1];if(!tagName){tagName='*'}var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){var elements;if(tagName=='*'){elements=getAllChildren(currentContext[h])}else{elements=currentContext[h].getElementsByTagName(tagName)}for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j]}}currentContext=new Array;var currentContextIndex=0;for(var k=0;k<found.length;k++){if(found[k].className&&found[k].className.match(new RegExp('\\b'+className+'\\b'))){currentContext[currentContextIndex++]=found[k]}}continue}if(token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)){var tagName=RegExp.$1;var attrName=RegExp.$2;var attrOperator=RegExp.$3;var attrValue=RegExp.$4;if(!tagName){tagName='*'}var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){var elements;if(tagName=='*'){elements=getAllChildren(currentContext[h])}else{elements=currentContext[h].getElementsByTagName(tagName)}for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j]}}currentContext=new Array;var currentContextIndex=0;var checkFunction;switch(attrOperator){case'=':checkFunction=function(e){return(e.getAttribute(attrName)==attrValue)};break;case'~':checkFunction=function(e){return(e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b')))};break;case'|':checkFunction=function(e){return(e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?')))};break;case'^':checkFunction=function(e){return(e.getAttribute(attrName).indexOf(attrValue)==0)};break;case'$':checkFunction=function(e){return(e.getAttribute(attrName).lastIndexOf(attrValue)==e.getAttribute(attrName).length-attrValue.length)};break;case'*':checkFunction=function(e){return(e.getAttribute(attrName).indexOf(attrValue)>-1)};break;default:checkFunction=function(e){return e.getAttribute(attrName)}}currentContext=new Array;var currentContextIndex=0;for(var k=0;k<found.length;k++){if(checkFunction(found[k])){currentContext[currentContextIndex++]=found[k]}}continue}tagName=token;var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){var elements=currentContext[h].getElementsByTagName(tagName);for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j]}}currentContext=found}return currentContext}

/* Copyright MyspaceGens.com 2008 - New Myspace Navigation Bar Generator JS */
function $X(element)
{
	element = document.getElementById(element);
	return element;
}

function $$X(element)
{
	element = document.getElementsBySelector(element);
	return element;
}

$(document).ready(function(){
	$('#linkBackgroundColor, #linkTextColor, #hoverBackgroundColor, #hoverTextColor, #railColor, #arrowColor').ColorPicker({
		targetID : '',
		newTimeout : '',
		
		eventName: 'focus',
		
		onSubmit: function(hsb, hex, rgb, el) {
			$(el).val("#" + hex);
			$(el).ColorPickerHide();
			update();
		},
		onChange: function(cal, hex, el) {
			$("#" + targetID).val('#' + hex);
			
			newTimeout = setTimeout("update();", 2500); //IE gets slow
		},
		onBeforeShow: function () {
			$(this).ColorPickerSetColor(this.value);
			targetID = this.id;
		}
	});
	
	init();
});


function update()
{
	var background = $$X("div#sectionWrap").concat($$X("div#navWrap"));
	var i = 0;
	while (current = background[i++])
	{
		current.style.backgroundColor = $X('linkBackgroundColor').value;
	}
	
	var links = $$X("ul#navLinks li a.skipDrop");
	var i = 0;
	while (current = links[i++])
	{
		current.style.color = $X('linkTextColor').value;
		current.style.fontSize = $X('linkTextSize').value + 'px';
		current.style.fontFamily = $X('linkTextStyle').value;
		current.style.textDecoration = $X('linkTextDecoration').value;
		current.style.backgroundColor = $X('linkBackgroundColor').value;
	}
	
	var i = 0;
	while (current = links[i++])
	{
		current.onmouseover = function()
		{
			this.style.background = 'none';
			this.style.color = ($X('hoverTextColor').value == '') ? $X('linkTextColor').value : $X('hoverTextColor').value; //this.style.color = $X('hoverTextColor').value;
			this.style.fontSize = ($X('hoverTextSize').value == '') ? $X('linkTextSize').value + 'px' : $X('hoverTextSize').value + 'px'; //this.style.fontSize = $X('hoverTextSize').value + 'px';
			this.style.fontFamily = ($X('hoverTextStyle').value == '') ? $X('linkTextStyle').value : $X('hoverTextStyle').value; //this.style.fontFamily = $X('hoverTextStyle').value;
			this.style.textDecoration = ($X('hoverTextDecoration').value == '') ? $X('linkTextDecoration').value : $X('hoverTextDecoration').value; //this.style.textDecoration = $X('hoverTextDecoration').value;
			this.style.backgroundColor = $X('hoverBackgroundColor').value; //this.style.backgroundColor = ($X('hoverBackgroundColor').value == '') ? $X('linkBackgroundColor').value : $X('hoverBackgroundColor').value;
		};
		current.onmouseout = function()
		{ 
			if (this.style.backgroundColor != '')
			{
				this.style.backgroundColor = $X('linkBackgroundColor').value;
			}
			else {
				this.style.backgroundColor = '#2358b8';
			}
			
			this.style.background = 'url(/files/navigation_bar/menu_bg.png) repeat-x top';
			update();
		};
	}
	
	var drop = $$X("ul#navLinks li.trigger ul li a");
	var i = 0;
	while (current = drop[i++])
	{
		
		current.style.fontSize = $X('linkTextSize').value + 'px';
		current.style.fontFamily = $X('linkTextStyle').value;
		current.style.textDecoration = $X('linkTextDecoration').value;
		
		current.onmouseover = function()
		{
			var target = this.parentNode.parentNode.parentNode;
			
			if (target.childNodes[0].tagName == 'A')
			{
				var object = target.childNodes[0];
			}
			else {
				var object = target.childNodes[1];
			}
			
			object.style.background = 'none';
			object.style.color = ($X('hoverTextColor').value == '') ? $X('linkTextColor').value : $X('hoverTextColor').value; //this.style.color = $X('hoverTextColor').value;
			object.style.fontSize = ($X('hoverTextSize').value == '') ? $X('linkTextSize').value + 'px' : $X('hoverTextSize').value + 'px'; //object.style.fontSize = $X('hoverTextSize').value + 'px';
			object.style.fontFamily = ($X('hoverTextStyle').value == '') ? $X('linkTextStyle').value : $X('hoverTextStyle').value; //object.style.fontFamily = $X('hoverTextStyle').value;
			object.style.textDecoration = ($X('hoverTextDecoration').value == '') ? $X('linkTextDecoration').value : $X('hoverTextDecoration').value; //object.style.textDecoration = $X('hoverTextDecoration').value;
			object.style.backgroundColor = ($X('hoverBackgroundColor').value == '') ? '#FFFFFF' : $X('hoverBackgroundColor').value;
			
			this.style.fontSize = ($X('hoverTextSize').value == '') ? $X('linkTextSize').value + 'px' : $X('hoverTextSize').value + 'px'; //object.style.fontSize = $X('hoverTextSize').value + 'px';
			this.style.fontFamily = ($X('hoverTextStyle').value == '') ? $X('linkTextStyle').value : $X('hoverTextStyle').value; //object.style.fontFamily = $X('hoverTextStyle').value;
			this.style.textDecoration = ($X('hoverTextDecoration').value == '') ? $X('linkTextDecoration').value : $X('hoverTextDecoration').value; //object.style.textDecoration = $X('hoverTextDecoration').value;
			this.style.backgroundColor = $X('hoverBackgroundColor').value;
			
		};
		current.onmouseout = function()
		{
			var target = this.parentNode.parentNode.parentNode;
			
			if (target.childNodes[0].tagName == 'A')
			{
				var object = target.childNodes[0];
			}
			else {
				var object = target.childNodes[1];
			}
			
			object.style.background = 'url(/files/navigation_bar/menu_bg.png) repeat-x top';
			
			this.style.backgroundColor = '#FFFFFF';
			update();
		};
	}
	
	var rail = $$X("ul#navLinks li.spacer");
	var i = 0;
	while (current = rail[i++])
	{
		current.style.backgroundColor = $X('railColor').value;
	}
	
	var arrow = $$X("ul#navLinks li.trigger a small");
	var i = 0;
	while (current = arrow[i++])
	{
		current.style.color = $X('arrowColor').value;
		current.style.fontSize = $X('arrowSize').value + 'px';
	}
	
	var shadowHead = $$X("div#sectionWrap");
	var i = 0;
	while (current = shadowHead[i++])
	{
		current.style.backgroundImage = 'url(\'/files/navigation_bar/top_bg.png\')';
	}

	if ($X('linkProperty').value == 'transparent')
	{
		var transparent = $$X("div#sectionWrap").concat($$X("div#navWrap").concat($$X("ul#navLinks li a.skipDrop")));
		var i = 0;
		while (current = transparent[i++])
		{
			current.style.backgroundColor = 'transparent';
		}
	}
	
	if ($X('linkProperty').value == 'shadow' || $X('type').value == 'multiple')
	{
		var shadow = $$X("div#sectionWrap");
		var i = 0;
		while (current = shadow[i++])
		{
			current.style.backgroundImage = 'none';
		}
	}
}

function init()
{
	var elements = new Array("linkBackgroundColor", "linkProperty", "linkTextColor", "linkTextSize", "linkTextStyle", "linkTextDecoration", "railColor", "arrowColor", "arrowSize");
	
	for (var element = 0; element < elements.length; ++element)
	{
		$X(''+ elements[element] +'').onchange = update;
		$X(''+ elements[element] +'').onkeyup = update;
	}
	
	update();
	Rows.Toggle($X('type'));
}

Rows = {
	Toggle: function(pTarget) {
		//if (pTarget.value == "single") {
		//	$X('single').style.display = "";
		//	$X('multiple').style.display = "none";
		//}
		//if (pTarget.value == "multiple") {
		//	$X('single').style.display = "none";
		//	$X('multiple').style.display = "";
		//}
		//update();
	}
}

sfHover = function() {
	var sfEls = document.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);