// A JavaScript object for fixing some broken CSS support (mostly in Internet Explorer)

fixer={
	
	olIds: [ 'statementOfFaith', 'god' ],
	olHeadingType: [ 'h3', 'h4'],
	olStyles: [ 'upper-roman', 'upper-alpha' ],
	olUpperRoman: [ 'I. ', 'II. ', 'III. ', 'IV. ', 'V. ', 'VI. ', 'VII. ', 'VIII. ', 'IX. ', 'X. ', 'XI. ', 'XII. ', 'XIII. ', 'XIV. ', 'XV. ', 'XVI. ', 'XVII. ', 'XVIII. ' ],
	olUpperAlpha: [ 'A. ', 'B. ', 'C. ', 'D. ', 'E. ' ],
	
	floatBrokenElemId:'footer',
	

	init:function() {
		
		fixer.fixQuotes();
		fixer.fixCites();
		fixer.fixOrderedLists();
		fixer.fixJubileeFooter();
		fixer.fixFloatParent();
		
	},
	
	/**
	* This method fixes MSIE browsers that do not support the :before and :after
	* pseudo-elements in CSS. It adds quotation marks before and after all <q>
	* elements.
	*/
	
	fixQuotes:function() {
		
		if( document.getElementsByTagName('q').length == 0 ) return;
		
		var quotes = document.getElementsByTagName( 'q' );
		
		for( var i=0; i<quotes.length; i++ ) {
			
			if( !quotes[i].currentStyle ) return;
			if( window.getComputedStyle ) return;
			
			var text = quotes[i].lastChild.nodeValue;
			
			quotes[i].lastChild.nodeValue = '"' + text + '"';
			
		}
		
	},
	
	/**
	* This method fixes MSIE browsers that do not support the :before and :after
	* pseudo-elements in CSS. It adds a dash at the beginning of all <cite>
	* elements.
	*/
	
	fixCites:function() {
		
		if( document.getElementsByTagName('cite').length == 0 ) return;
		
		var cites = document.getElementsByTagName( 'cite' );
		
		for( var i=0; i<cites.length; i++ ) {
			
//			alert( 'looping' );
			
			if( !cites[i].currentStyle ) return;
			
			var text = cites[i].lastChild.nodeValue;
			
			cites[i].lastChild.nodeValue = '- ' + text;
			
		}
		
	},
	
	/**
	* This method fixes all browsers that do not support styling of list item
	* bullet types (as of December 2007, it is believed that this refers to all
	* browsers). It also fixes improper implementation of 
	* 'list-style-position: inside' in certain browsers. It takes specific lists
	* (as specified by the olIds property of this object) and applies the
	* necessary styles with the help of two parallel arrays and an array of
	* bullets (chosen by a switch statement).
	*/
	
	fixOrderedLists:function() {
		
		if( document.getElementsByTagName( 'ol' ).length == 0 ) return;
		
		var lists = new Array();
		
		for( var i=0; i<fixer.olIds.length; i++ ) {

			if( !document.getElementById( fixer.olIds[i] ) ) continue;
			
			lists[ lists.length ] = document.getElementById( fixer.olIds[i] );
			
		}
		
		if( lists.length == 0 ) return;
		
		for( var i=0; i<lists.length; i++ ) {

			var listItems = new Array();

			// The splice() method does not seem to work when using an array reference
			// for an array called by the getElementsById() method.
			for( var j = 0; j<lists[i].getElementsByTagName('li').length; j++ ) {
				
				listItems[listItems.length] = lists[i].getElementsByTagName('li')[j];
					
				
			}
			
			for( var j=0; j<listItems.length; j++ ) {
								
				if( listItems[j].parentNode.getAttribute( 'id' ) != fixer.olIds[i] ) {
					
					listItems.splice(j, 1);
					j--;
					
				}
				
			}
			
			for( var j=0; j<listItems.length; j++ ) {
				
				listItems[j].style.listStylePosition = 'outside';
				listItems[j].style.listStyleType = 'none';
				listItems[j].style.paddingLeft = '0';
				
				if( listItems[j].getElementsByTagName( fixer.olHeadingType[i] ) == 0 )  {
					
					continue;
					
				} else {
					
//					alert( j + ': ' + fixer.olHeadingType[i] );
				
					var heading = listItems[j].getElementsByTagName( fixer.olHeadingType[i] )[0];
					
					switch( fixer.olStyles[i] ) {
						
						case 'upper-roman' :
						heading.innerHTML = fixer.olUpperRoman[j] + heading.innerHTML;
						break;
						
						case 'upper-alpha' :
						heading.innerHTML = fixer.olUpperAlpha[j] + heading.innerHTML;
						
					}
					
				}
				
			}
			
		}
		
	},
	
	fixFloatParent:function()
	{

		var parents = fixer.getElementsByClassName( 'articleLinkList', 'ul' );
		if( !parents || parents == '' ) return;
		
		for( var i=0; i<parents.length; i++ )
		{
			
			var lis = parents[i].getElementsByTagName( 'li' );
			var theHeight = 0;
			
			for( var j=0; j<lis.length; j++ )
			{
				
				if( lis[j].offsetHeight > theHeight )
				{
					
					theHeight = lis[j].offsetHeight;
					
				}
				
			}
			
			parents[i].style.height = theHeight + 'px';
			
		}
	
	},
	
	/**
	* Simple function for fixing a positioning bug in IE 5.5 and 6. Jubilee-
	* specific
	*/
	
	fixJubileeFooter:function() {
		
		if( !document.getElementById( 'scanAlert' ) || !document.getElementById( 'scanAlert' ).currentStyle ) return;
		
		var scanAlert = document.getElementById( 'scanAlert' );
		
		if( scanAlert.offsetLeft > 0 ) {
			
			scanAlert.style.marginLeft = ( 20 - scanAlert.offsetLeft ) + 'px';
			
			
		}
		
		
	},
	
	/**
	* Utility method that returns all elements with a particular class. The optional
	* type parameter defaults to any type in the first conditional, and can be
	* ommitted or passed an argument of null to achieve that default. Otherwise,
	* an element tag name should be passed just as it would be to the getElementsByTagName
	* method.
	*/
	
	getElementsByClassName:function( theClass, theType )
	{
		
		if( !theType || theType == undefined ) {
			
			theType = '*';
			
		}
		
		var byClass = new Array();
		
		var all = document.getElementsByTagName( theType );
		
		for( var i=0; i<all.length; i++ ) {
			
			if( all[i].className == theClass ) {
				
				byClass[ byClass.length ] = all[i];
				
			}
			
		}
		
		if( byClass.length == 1 )
		{
			
			byClass = byClass[0];
			
		}
		
		return byClass;
		
	},
	
	/**
	* Simple utility method for allowing the use of multiple window.onload functions.
	* Written by Simon Willison
	*/
	
	addLoadEvent:function( func ) {
		
		var oldonload = window.onload;
		
		if( typeof window.onload != 'function' ) {
			
			window.onload = func;
			
		} else {
			
			window.onload = function() {
				
				oldonload();
				func();
				
			}
			
		}
		
	}
	
}

fixer.addLoadEvent( fixer.init );