$(document).ready(function(){
	function init()
	{
	}
	var skipLinkCountControl;
	var skipLinkCount;
	var textAlignment;
	var textColor;
	var backgroundColor;
	var opacity;
	var skipLinkPanel;
	var cmdCreateSkipNavCode;
	var genJSandCSS;
	var genHTML;

	function setUpFormControls()
	{
	skipLinkCountControl = document.getElementById("skipLinkCount");
	textAlignment = document.getElementById("textAlignment");
	textColor = document.getElementById("textColor");
	backgroundColor = document.getElementById("backgroundColor");
	opacity = document.getElementById("opacity");
	skipLinkPanel = document.getElementById("skipLinkPanel");
	cmdCreateSkipNavCode = document.getElementById("cmdCreateSkipNavCode");
	genJSandCSS = document.getElementById("genJSandCSS");
	genHTML = document.getElementById("genHTML");
	cmdCreateSkipNavCode.onclick=generateCode;
	getSkipCount();
	skipLinkCountControl.onchange=getSkipCount;
	}
	function getSkipCount()
	{
	skipLinkCount = skipLinkCountControl.selectedIndex+2	;
	skipLinkPanel.innerHTML="";
	for (i=1;i<skipLinkCount;i++)
		{
		var row = document.createElement("div");
		row.setAttribute("className","row");
		row.setAttribute("class","row");
	//add label for link phrase
		var row_label = document.createElement("label");
		var row_label_text = document.createTextNode("Link text for skip link " + i);
		var controlId = "skipNav" + i + "_linkText";
		row_label.setAttribute("htmlFor",controlId);
		row_label.setAttribute("for",controlId);
		row_label.appendChild(row_label_text);
	//add input for link phrase
		var row_input = document.createElement("input");
		row_input.setAttribute("type","text");
		row_input.setAttribute("value","e.g. 'Skip to Main Content'");
		row_input.setAttribute("id",controlId);
		row_input.setAttribute("name",controlId);
		row_input.onfocus=function(){this.value="";};
		row.appendChild(row_label);
		row.appendChild(row_input);
		skipLinkPanel.appendChild(row);
		}
	}
	function generateCode()
	{
	writeGenJSandCSS();
	writeGenHTML();
	}
	function writeGenJSandCSS(){
	var strJSandCSS='';
	strJSandCSS+='<script type="text\/javascript">\n';
	strJSandCSS+='function showSkipLinks() {\n';
	strJSandCSS+='var skipBgColor= "' + backgroundColor.value + '";\n';
	strJSandCSS+='var skipTextColor = "' + textColor.value + '";\n';
	strJSandCSS+='\/\/ Amend\/tweak these to your satisfaction	\n';
	strJSandCSS+='var textIndent = "20px";\n';
	strJSandCSS+='var skipNavHeight = "auto";\n';
	strJSandCSS+='var skipFontSize = "medium";\n';
	strJSandCSS+='var viewportwidth="100%";\n';
	strJSandCSS+='var sk_a = document.getElementsByTagName("a");\n';
	strJSandCSS+='for (i=0; i<sk_a.length; i++)\n';
	strJSandCSS+=' {\n';
	strJSandCSS+='	bodyEl = document.getElementsByTagName("body")[0];\n';
	strJSandCSS+='	if (sk_a[i].className=="skip-link")\n';
	strJSandCSS+='		{\n';
	strJSandCSS+='		sk_a[i].onfocus=function(e){\n';
	strJSandCSS+='			this.style.width=viewportwidth;\n';
	strJSandCSS+='			this.style.padding="10px 0";\n';
	strJSandCSS+='			this.style.fontSize = skipFontSize;\n';
	strJSandCSS+='			this.style.height = skipNavHeight;\n';
	strJSandCSS+='			this.style.textIndent = textIndent;\n';
	strJSandCSS+='			this.style.backgroundColor = skipBgColor;\n';
	strJSandCSS+='			this.style.color = skipTextColor;\n';
	strJSandCSS+='			}\n';
	strJSandCSS+='		sk_a[i].onblur=function(e){\n';
	strJSandCSS+='			this.style.width="0";\n';
	strJSandCSS+='			this.style.padding="0";\n';
	strJSandCSS+='			this.style.fontSize="0px";\n';
	strJSandCSS+='			this.style.height="0";\n';
	strJSandCSS+='			this.style.textIndent="-30000px";\n';
	strJSandCSS+='			this.style.backgroundColor="transparent";\n';
	strJSandCSS+='			this.style.backgroundImage="none";\n';
	strJSandCSS+='			}\n';
	strJSandCSS+='		}\n';
	strJSandCSS+='	}\n';
	strJSandCSS+='}\n';
	strJSandCSS+='function init()\n';
	strJSandCSS+='{\n';
	strJSandCSS+='\/\/place calls to all functions that you want to run after page load here\n';
	strJSandCSS+='showSkipLinks();\n';
	strJSandCSS+='}\n';
	strJSandCSS+='window.onload=init;\n';
	strJSandCSS+='<\/script>\n\n';

	strJSandCSS+='<style type="text\/css">\n';
	strJSandCSS+='#skipLinkList li {\n';
	strJSandCSS+='list-style:none;\n';
	strJSandCSS+='}\n';
	strJSandCSS+='a.skip-link {\n';
	strJSandCSS+='position:absolute;\n';
	strJSandCSS+='top:0px;\n';
	strJSandCSS+='left:0px;\n';
	strJSandCSS+='z-index:1000 !important;\n';
	strJSandCSS+='font-size:0px;\n';
	//strJSandCSS+='height:0px;\n';
	strJSandCSS+='color:' + textColor.value + ' !important;\n';
	strJSandCSS+='display:block;\n';
	strJSandCSS+='margin:0;\n';
	strJSandCSS+='text-indent:-30000px;\n';
	strJSandCSS+='outline:none;\n';
	strJSandCSS+='text-align:' + textAlignment[textAlignment.selectedIndex].value + ';\n';
	var op = opacity[opacity.selectedIndex].value
	strJSandCSS+='filter:alpha(opacity=' + op + ');\n';
	if (op=="100") {
		op="1";
		}
		else
		{
		op="0." + op;
		}
	strJSandCSS+='opacity:' + op + ';\n';
	strJSandCSS+='}\n';
	strJSandCSS+='<\/style>\n';
	genJSandCSS.value=strJSandCSS;
	}
	function writeGenHTML(){
	var strHTML='';
	strHTML+='<!-- Place these at the top of the document (as close to opening <body> tag as possible) -->\n';
	strHTML+='<div id="skipLinkList">\n';
	strHTML+='	<ul>\n';
	for (i=1;i<skipLinkCount;i++)
	{
	var linkText = document.getElementById("skipNav" + i + "_linkText").value;
	strHTML+='		<li><a href="#skipdest' + i + '" class="skip-link" id="skipto-dest' + i + '">' + linkText + '<\/a><\/li>\n';
	}
	strHTML+='	<\/ul>\n';
	strHTML+='<\/div>\n';
	strHTML+='\n\n<!-- Place these wherever necessary in the document -->\n';
	for (i=1;i<skipLinkCount;i++)
	{
	strHTML+='<a href="#skipdest' + i + '" name="skipdest' + i + '" id="skipdest' + i + '"><\/a>\n';
	}
	genHTML.value=strHTML;
	}
	setUpFormControls();
});