$(document).ready( function(){
	//**********  START PAGE INITIALIZATION CODE **********
	//
	//  INITIALIZE DEFAULT LIST ITEM
	//
	//  THIS FOR LOOP POPULATES THE HIDDEN TEXT FIELD
	//  id = "default". THIS FIELD USED TO MAINTAIN STATE.
	//  LOOK AT EACH ATTRIBUTE IN ALL <li>'s FOR ROLLOVER
	//  ELEMENTS CONTAININ THE WORD "roll_" IN ID

	//  READ VALUE IN HIDDEN DEFAULT TEXT FIELD
	var defaulto = document.getElementById("default").value;

	if((defaulto == 'contact') || (defaulto == 'confirmation')){
		//  ALREADY A DEFAULT VALUE FILLED IN BY PHP 
		//  HIDDEN TEXT FIELD IS NOT EMPTY), SO DO NOTHING
	} else {
		//  FIRST TIME TO PAGE - NO DEFAULT VALUE SET IN HIDDEN FIELD.
		//  USE ID OF FIRST ROLLOVER LIST ELEMENT AS DEFAULT TEXT
		for(i=0; (a = document.getElementsByTagName("li")[i]); i++) {
			if(a.getAttribute("id")==null){
				// TRAP FOR NULL . . . EMPTY STMT

			//  IF WILL BE TRUE ON FIRST li ITEM WITH id = "roll_xxxnamexx"
			}else if(a.getAttribute("id").indexOf("roll_") != -1) {

				id = a.getAttribute("id");
				startPos = id.indexOf('_') + 1;
				idSfx = id.substr(startPos);

				if(document.getElementById('default').value == 'confirmation'){
					break;	// TRAP, DO NOTHING
				} else {
					document.getElementById('default').value = idSfx;
				}	//  if(document.getElementById('defa

				break;

			}	//  if(a.getAttribute("id")==null){
		}	//  for(i=0; (a = document.getE . . . 


		//  TURN OFF ALL DIV BLOCKS EXCEPT FOR FIRST ONE
		for(i=0; (a = document.getElementsByTagName("div")[i]); i++) {
			//  LOOK AT EACH ATTRIBUTE IN A "div" AND GET THE STRING 
			//  POSITION OF THE WORD "pblock"
			if(a.getAttribute("id")==null){
				//  TRAP FOR NULL . . . EMPTY STMT
			}else if(a.getAttribute("id").indexOf("pblock") != -1) {
				//  IF YOU FOUND A "pblock" ELEMENT, TURN IT OFF
				a.style.display = 'none';

				//  CHECK IF CURRENT DIV ELEMENT HAS THE SAME id
				//  AS THE ONE PASSED IN, TURN IT ON
				if(a.getAttribute("id").indexOf(idSfx) != -1) {
					//  WHEN INITIAL CONTACT PAGE, NEED TO 
					//  CHECK STATUS OF CONTACT FOR EACH TIME
					//  idSfx SHOULD HOLD STRING 'contact' AS
					//  THIS IS THE FIRST IN THE ROLLOVER LIST
					a.style.display = 'block';
				}	//  if(a.getAttribute("id").indexOf(idSfx) != -1) {
			}	//  if(a.getAttribute("id")==null){
		}	//  for(i=0 . . . 
	}	//  if((defaulto == 'cont



	//  MAKE ROLLOVER NAV <li> ELEMENT WITH ID MATCHING defaulto TURN
	//  GREEN. OTHER <li> ELEMENTS GET BLACK
	defaulto = document.getElementById('default').value;
	for(i=0; (a = document.getElementsByTagName("li")[i]); i++) {
		//  LOOK AT EACH ATTRIBUTE IN A "li" AND GET THE STRING 
		//  POSITION OF THE WORD "roll_"
		if(a.getAttribute("id")==null){
			// TRAP FOR NULL . . . EMPTY STMT
		}else if(a.getAttribute("id").indexOf("roll_") != -1) {
			//  CHECK IF CURRENT HTML ELEMENT HAS THE SAME id
			//  AS THE DEFAULT, TURN IT ON
	 		if(a.getAttribute("id").indexOf(defaulto) != -1){
	 			a.style.color = 'green';
			}else{
	 			a.style.color = 'black';
			}
		}
	}

	//  LOOK FOR IE BROWSERS
	//  IF FOUND, APPEND IE STYLESHEET
	var browser=navigator.appName;

	if (browser=="Microsoft Internet Explorer") {

		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');

		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = "shared/css/ieStyle.css";
		cssNode.media = 'screen';
		headID.appendChild(cssNode);
	}
	//*************  END PAGE INITIALIZATION CODE **************



	//************* START UPPER-RIGHT NAVIGATION BAR ***********
/*	$('ul.nav>li').hover(
		function(){ $('ul', this).css('display', 'block'); },
		function(){ $('ul', this).css('display', 'none');}
	);
*/
	$("a.bounce").hover(
		function () {
			$(this).stop(true).animate(
				{paddingLeft: '50px'}, 
				{speed: 2000, easing: 'easeOutBack'}
			);
		}, 

		function () {
			$(this).stop(true).animate(
				/* MUST MATCH: 				   */
				/* #nav a {                    */
				/* 		padding-left: 20px;    */
				/* IN root/shared/header.inc   */
				{paddingLeft: '25px'}, 

				{speed: 100, easing: 'easeOutBounce'}
			);
		}
	);


	//  NEED TO DUPLICATED CODE ABOVE FOR DROP DOWN MENU
	//  FIRST ROW OF SUBMENU TO ALLOW FOR TOP PADDING
	$('a.first').hover(
		function () {
			$(this).stop(true).animate(
				{paddingLeft: '50px'}, 
				{speed: 2000, easing: 'easeOutBack'}
			);
		}, 

		function () {
			$(this).stop(true).animate(
				/* MUST MATCH: 				   */
				/* ul.nav>li>ul>li>a {         */
				/* 		padding-left: 20px;    */
				/* IN root/shared/header.inc   */
				{paddingLeft: '25px'}, 
				{speed: 100, easing: 'easeOutBounce'}
			);
		}
	);
	//************* END UPPER-RIGHT NAVIGATION BAR *************




	// *********** START MID-PAGE ROLLOVER NAVIATION *********
	$('ul.roll_over li').click(
		function () {
			//  GET ID OF LIST ITEM TO CHANGE
			id = this.getAttribute("id");
			startPos = id.indexOf('_')+1;
			idSfx = id.substr(startPos);

			document.getElementById('default').value = idSfx;

			$(this).css({'color' : 'green', 'font-style': 'normal'});

			defaultText = document.getElementById('default').value;

			//  LOOP THROUGH EACH <li> ELEMENT
			//  AND CHANGE COLOR OF LIST ELEMENT
			//  IF NEEDED
			for(i=0; (a = document.getElementsByTagName("li")[i]); i++) {
				//  LOOK AT EACH ATTRIBUTE IN A "li" AND GET THE STRING 
				//  POSITION OF THE WORD "roll_"
				if(a.getAttribute("id")==null){
					// TRAP FOR NULL . . . EMPTY STMT
				}else if(a.getAttribute("id").indexOf("roll_") != -1) {
					//  IF YOU FOUND THE HTML ELEMENT, MAKE FONT BLACK
					a.style.color = 'black';

					//  CHECK IF CURRENT HTML ELEMENT HAS THE SAME id
					//  AS THE ONE PASSED IN, TURN IT ON
			 		if(a.getAttribute("id").indexOf(defaultText) != -1){
			 			a.style.color = 'green';
			 		}
				}
			}

			//  LOOP THROUGH EACH <div> ELEMENT
			//  FIND AND DISPLAY APPROP. TEXT
			for(i=0; (a = document.getElementsByTagName("div")[i]); i++) {
				//  LOOK AT EACH ATTRIBUTE IN A "div" AND GET THE STRING 
				//  POSITION OF THE WORD "pblock"
				if(a.getAttribute("id")==null){
					//  EMPTY STMT . . . TRAP FOR NULL
				}else if(a.getAttribute("id").indexOf("pblock") != -1) {
					//  IF YOU FOUND THE HTML ELEMENT, TURN IT OFF
					a.style.display = 'none';

					//  CHECK IF CURRENT HTML ELEMENT HAS THE SAME id
					//  AS THE ONE PASSED IN, TURN IT ON
			 		if(a.getAttribute("id").indexOf(defaultText) != -1) {
						$(a).fadeIn(2000);
			 		}
				}
			}
		}
	);


	$('ul.roll_over li#roll_offices ul#office_submenu li' ).click(
		function () {
			id = this.getAttribute("id");
			startPos = id.indexOf('_')+1;
			idSfx = id.substr(startPos);
			document.getElementById('default').value = idSfx;
		}
	);

	$('ul.roll_over li').hover(
		function () {
			$(this).css({'color' : 'blue', 'font-style' : 'italic'});
		},

		function () {
			defText = document.getElementById('default').value;


			if(this.getAttribute("id").indexOf(defText) != -1){
				$(this).css({'color': 'green', 'font-style' : 'normal'});
			} else {
				$(this).css({'color': 'black', 'font-style' : 'normal'});
			}

		}
	);
	// *********** END MID-PAGE ROLLOVER NAVIATION *********



//*******************************************
//*******************************************
//*** CODE USED JUST FOR contact.php PAGE ***
//*******************************************


	// ******************************
	// ** CHECK USER INPUT WHEN *****
	// ** SUBMIT BUTTON CLICKED *****
	// ******************************
	function contact_input_ok() {
		//  ITERATE AND IDENTIFY ALL 'optional' FORM FIELDS
		var tmp = document.getElementsByTagName('input');
		bool = true;

		for (var i=0;i < tmp.length;i++){
			//  BACKGROUND MAY HAVE BEEN COLORED FROM PREV.
			//  SUBMISSIONS. RESET COLOR
			tmp[i].style.backgroundColor = "white";

			//  LOOK FOR EMPTY STRINGS IN REQUIRED FIELDS.
			//  COLOR YELLOW IF FOUND
			if(tmp[i].className == 'req_inp') {
				if (tmp[i].value == ""){
					tmp[i].style.backgroundColor = "yellow";
					bool = false;
				}
			}	//  if
		}	//  for (var i=0;i < tmp.length;i++){

		return bool;

	}	//  function contact_input_ok() {





	// ******************************
	// ****** SUBMIT BUTTON *********
	// ******************************
	$('input#js_submit' ).click(
		function () {
			if (contact_input_ok()){
				document.getElementById('form_contact').submit();
			} else {
				alert("A name, email address, and anti-spam math answer MUST be entered in order to submit your request.");
			}
		}
	);




	// ******************************
	// ****** INPUT BUTTON *********
	// ******************************
	$('input#js_clear' ).click(
		function () {
			//  IDENTIFY ALL INPUT FIELDS & CLEAR VALUES
			var inp_bx = document.getElementsByTagName('input');

			for (var i=0; i < inp_bx.length; i++){
				cond1 = (inp_bx[i].className == "req_inp");
				cond2 = (inp_bx[i].className == "opt_inp");
				if ( cond1 || cond2 ) {
					inp_bx[i].value = "";
				}	// if
			}	//  for

			//  UNCHECK CHECKBOXES
			cb = document.getElementsByTagName('input');
			for (k=0; k < cb.length; k++) {
				if (cb[k].type == 'checkbox') {
					cb[k].checked = false;
				}	// if
			}	//  for


			//  SET SELECT BOX TO DEFAULT
			select_box = document.getElementById('state');
			select_box.options[0].selected = true;

			ta = document.getElementsByTagName('textarea');
			ta[0].value = '';

			//  IF USER FORMERLY SUBMITTED, THERE MAY 
			//  BE ERROR MESSAGES. CLEAR THESES TOO
			p = document.getElementsByTagName('p');
			for (j=0; j < p.length; j++) {
				if (p[j].className == 'error_message') {
					p[j].style.display = 'none';
				}	//  if
			}	//  for
		}	//  function () {
	);	//  $('input.js_clear' ).click(





	// *******************************
	// ** LISTENS FOR CLICK ON      **
	// ** ANCHOR THAT HIDES/REVEALS **
	// ** OPTIONAL INPUT FIELDS     **
	// *******************************
	// ** SOME CODE TAKEN FROM:     **
	// ** http://www.stuffandnonsense.co.uk/archives/trimming_form_fields.html
	// *******************************
	if(window.location.pathname == '/v1/contact.php') {
		//  CHECK FOR NULL IN getElementById
		if(document.getElementById){

			//  FIND ELEMENT TO LATCH ONTO BELOW WHICH DYNAMIC LINK WILL APPEAR
			var linkContainer = document.getElementById('form_contact');

			//  APPEND A LINE BREAK AND THE HYPERLINK
			var linebreak = linkContainer.appendChild(document.createElement('br'));
			var toggle = linkContainer.appendChild(document.createElement('a'));
			toggle.href = '#';
			toggle.appendChild(document.createTextNode(' Hide optional fields?'));

			toggle.onclick = function()
			{
				//  GIVE VALUES TO DIFF. STATES OF HYPERLINK
				var linkText = this.firstChild.nodeValue;
				this.firstChild.nodeValue = (linkText == ' Hide optional fields?') ? ' Display optional fields?' : ' Hide optional fields?';
			
				//  ITERATE AND IDENTIFY ALL 'optional' FORM FIELDS
				var tmp = document.getElementsByTagName('div');
				for (var i=0;i < tmp.length;i++){

					if(tmp[i].className == 'optional'){
						tmp[i].style.display = (tmp[i].style.display == 'none') ? 'block' : 'none';
					}
				}
				return false;
			}
		}else{
			alert('This website requires use of a modern browser. It appears you are using an older browser. Please call ASEB for further assistance.');
		}	//  	if(document.getElementById){



		// *******************************
		// ** CHECK TO SEE IF USER HAS  **
		// ** SUCCESSFULLY SUBMITTED    **
		// ** THE FORM AND HIDE/DISPLAY **
		// ** PROPER BLOCK              **
		// *******************************
		// *******************************
		defaultBox = document.getElementById('default');

		condition1 = (defaultBox.getAttribute('value')=='confirmation');
		condition2 = (defaultBox.getAttribute('value')=='contact');

		if (condition1 || condition2){
			// TURN OFF ALL pblocks
			for(i=0; (a = document.getElementsByTagName("div")[i]); i++) {
				//  LOOK AT EACH ATTRIBUTE IN A "div" AND GET THE STRING 
				//  POSITION OF THE WORD "pblock"
				if(a.getAttribute("id")==null){
					//  TRAP FOR NULL . . . EMPTY STMT
				}else if(a.getAttribute("id").indexOf("pblock") != -1) {
					//  IF YOU FOUND A "pblock" ELEMENT, TURN IT OFF
					a.style.display = 'none';
				}	//  if
			}	//  for(i=0; (a = document.getElementsByTagName("di . . . 

			if(condition1){
				//  TURN ON pblock_confirmation
				document.getElementById('pblock_confirmation').style.display = 'block';
				document.getElementById('js_submit').disabled =true;
				document.getElementById('js_clear').disabled =true;
				document.getElementById('after_submit_msg').style.display = 'block';
			} else {	//  if(condition1){
				//  TURN ON pblock_contact
				document.getElementById('pblock_contact').style.display = 'block';
			}	//  if(condition1){

		}else{	//  if (defaultBox.getAttribute('value')=='confirmation'){
			document.getElementById('pblock_'+defaultBox).style.display = 'block';
			document.getElementById('pblock_confirmation').style.display = 'none';
		}	//  if (defaultBox.getAttribute('value')=='confirmation'){
	}	// if(window.location.pathname == '/contact.php') {
//*******************************************
//***      END contact.php PAGE CODE       **
//*******************************************
//*******************************************

//*******************************************
//*******************************************
//**   CODE USED JUST FOR title.php PAGE   **
//*******************************************
	$('div#clickable_splash' ).click(
		function () {
			window.location.href = "auction.php";
		}
	);

//*******************************************
//***        END title.php PAGE CODE       **
//*******************************************
//*******************************************
});

function nav2PgSect(page, block) {
	window.location.href = page+"?visible="+block;
}



