/* 	use <li class="sub_nav"> to remove sub ul's or ol's from the script effects
	modified 18/02/2009 - Jeremy Livsey
	drops the border from the first question of an faq
	unless its preceeded by an image with the id 'headimage'
	*/

function styleQA() {
       // get all the li elements in the faq div
	   var ELEMENTS = document.getElementById('faq').getElementsByTagName('li');
       // flag to indicate a question or answer for formatting
	   var faqcount='q';
	   // flag to indicate we are processing the first question
	   var firstq = 'y';
	   // initialise the height store
	   var h = 0;

		// see if there is a header image in the page 
		try
		{
			var pic = document.getElementById('headimage');
			// see if it has height, if it doesnt exist it errors in IE!
			h = pic.offsetHeight;
			// no error so draw line
			
			//***********************************
			// need this for firefox which returns a 0 height for
			// a missing image, not an error!!
			if(h===0) {
				firstq='y';
			}
			else {
				firstq='n';
			}
			//***********************************
		}
		catch(err)
		{
		  	// means no image so dont draw top line
			firstq='y';
		}

	   // loop through all found elements
	   for (var i=0;i<ELEMENTS.length;i++) 
	   {
			// move the found element to a local var for manipulation
			var el = ELEMENTS[i];
			// checking to see that the element is called 'sub_nav'
			// if it is
			if (el.className.length == 7){
				
				//set the flag to processing a question for next element
				// that may be processed
				faqcount='q';
				// no class to apply formatting
				el.className = '';
			}
			
			// process the element
			else
			{	
				   // if its an answer
				   if (faqcount=='a') {	   
						   // set formatting class to answer
						   el.className = 'ans';
						   // switch flag for next process
						   faqcount='q';
				   }
				   // its a question
				   else{
						//set the class
						el.className = 'que';
						
						//if its the first question
						// adjust the class style to kill borders
						// and fix padding
						if (firstq=='y') {
							el.style.border='none';
							el.style.padding='8 0 10 20';
						
							// processed first question so switch 
							firstq='n';
						}
						// switch flag for next process
						faqcount='a';
				} //end not 7

			} //end if element class name is 7 chars long

		} //end for loop
	 
} // end function

// run on load
window.onload = styleQA;

