function initContent() {
	initCorners();
	initTables();
	initExpandableLists();
	initStepByStepLists();
}

// execute initContent on DOM ready
YAHOO.util.Event.onDOMReady(initContent);

function initCorners() {
	var featureBoxes = YAHOO.util.Dom.getElementsByClassName("feature_box_1", "div", "content_container");
	var cornerClasses = ["top_left_corner", "top_right_corner", "bottom_left_corner", "bottom_right_corner"];
	
	var tempDiv;
	var borderTopWidth, borderRightWidth, borderBottomWidth, borderLeftWidth;
	var offsetTop, offsetRight, offsetBottom, offsetLeft;
		
	for(var i = 0; i < featureBoxes.length; i++) {
		for(var j = 0; j < cornerClasses.length; j++) {
			tempDiv = document.createElement("div");
			tempDiv.className = cornerClasses[j];								
			tempDiv.innerHTML = "&nbsp;";

			featureBoxes[i].appendChild(tempDiv);

			borderTopWidth = parseInt(YAHOO.util.Dom.getStyle(featureBoxes[i], "border-top-width"));
			borderRightWidth = parseInt(YAHOO.util.Dom.getStyle(featureBoxes[i], "border-right-width"));
			borderBottomWidth = parseInt(YAHOO.util.Dom.getStyle(featureBoxes[i], "border-bottom-width"));
			borderLeftWidth = parseInt(YAHOO.util.Dom.getStyle(featureBoxes[i], "border-left-width"));

			if( tempDiv.className.indexOf("right") != -1 ) {				
				offsetLeft = featureBoxes[i].offsetWidth - tempDiv.offsetWidth - borderLeftWidth;
				
				if( !(tempDiv.offsetLeft == offsetLeft || tempDiv.offsetLeft == offsetLeft + borderLeftWidth) ) {
					offsetRight = 0 - (offsetLeft - tempDiv.offsetLeft + borderRightWidth);

					tempDiv.style.right = offsetRight + "px";					
				} 
			}
			
			if( tempDiv.className.indexOf("bottom") != -1 ) {	
				offsetTop = featureBoxes[i].offsetHeight - tempDiv.offsetHeight - borderTopWidth;

				if( !(tempDiv.offsetTop == offsetTop || tempDiv.offsetTop == offsetTop + borderTopWidth) ) {
					offsetBottom = 0 - (offsetTop - tempDiv.offsetTop + borderBottomWidth);

					tempDiv.style.bottom = offsetBottom + "px";					
				} 				
								
			}
								
		}
	}
}

/*
 * add the class alternate to odd rows in the tbodies of tables
 * with specified classes if browser does not support nth-child
 * pseudo class
 */
function initTables() {
	// opera 9.5, safari 3.1, and konquerer support the nth-child pseudo-class,
	// so no need to add styles		
	if( YAHOO.env.ua.opera >= 9.5 || YAHOO.env.ua.webkit >= 525.13 || YAHOO.env.ua.webkit == 1 ) {
		return;
	}
	
	// run init on tables with these classes	
	var tableClasses = ["simple", "contacts"];
	
	var tables = [];
	for(var i = 0; i < tableClasses.length; i++) {
		tables = tables.concat(YAHOO.util.Dom.getElementsByClassName(tableClasses[i], "table"));
	}
		
	for(var i = 0; i < tables.length; i++) {
		for(var j = 0; j < tables[i].tBodies.length; j++) {
			for(var k = 0; k < tables[i].tBodies[j].rows.length; k += 2) {
				YAHOO.util.Dom.addClass(tables[i].tBodies[j].rows[k], "alternate");
			}
		}
	}	
}

function initExpandableLists() {
	var lists = YAHOO.util.Dom.getElementsByClassName("expandable", "dl");
	for(var i = 0; i < lists.length; i++) {
		new ExpandableList(lists[i]);
	}

}

function initStepByStepLists() {
	var lists = YAHOO.util.Dom.getElementsByClassName("step_by_step", "ol");
	for(var i = 0; i < lists.length; i++) {
		new StepByStepList(lists[i]);
	}
	
}

var ExpandableList = function(el) {
	this.init(el);
}

ExpandableList.prototype = {
	
	addLinks: function() {
		var div, a;		
		var clickHandler = function(e) { 			
			var element = e.target || e.srcElement;					
			if (element.nodeName == "DT") {
				var dt = element;
				var dd = YAHOO.util.Dom.getNextSibling(dt);
			}
			else {
				var parent = element.parentNode;
				if( parent.nodeName == "DIV" ) {			
					var dd = parent.parentNode;
					var dt = YAHOO.util.Dom.getPreviousSibling(dd);			
				}
				else {			
					var dt = parent;
					var dd = YAHOO.util.Dom.getNextSibling(dt);
				}
			}

			var a = dt.getElementsByTagName("a")[0];
			if (dt.className.indexOf("closed") != -1) {
				a.className = "hide";
				a.innerHTML = "Hide";
				if (dt.className.indexOf("alternate") != -1) {
					YAHOO.util.Dom.removeClass(dt, "alternate_closed");
				}
				else {
					YAHOO.util.Dom.removeClass(dt, "closed");	
				}
				YAHOO.util.Dom.removeClass(dd, "closed");
			}
			else {
				a.className = "show";
				a.innerHTML = "Show";
				if (dt.className.indexOf("alternate") != -1) {
					YAHOO.util.Dom.addClass(dt, "alternate_closed");
				}
				else {
					YAHOO.util.Dom.addClass(dt, "closed");
				}					
				YAHOO.util.Dom.addClass(dd, "closed");
			}

		};

		for(var i = 0; i < this.el.childNodes.length; i++) {
			if (this.el.childNodes[i].nodeName == "DT") {
				if( this.count % 2 != 0 ) {
					YAHOO.util.Dom.addClass(this.el.childNodes[i], "alternate");
					YAHOO.util.Dom.addClass(this.el.childNodes[i], "alternate_closed");
				}				
				else {
					YAHOO.util.Dom.addClass(this.el.childNodes[i], "closed");
				}
				
				a = document.createElement("a");
				a.href = "javascript:void(0);";
				a.className = "show";
				a.innerHTML = "Show";	
				
				YAHOO.util.Event.on(this.el.childNodes[i], "click", clickHandler, this.count);
				this.el.childNodes[i].insertBefore(a, this.el.childNodes[i].childNodes[0]);
				
				this.count++;
			}
			else if (this.el.childNodes[i].nodeName == "DD") {
				YAHOO.util.Dom.addClass(this.el.childNodes[i], "closed");
			
				div = document.createElement("div");
				div.className = "hide";
				this.el.childNodes[i].appendChild(div);
				
				a = document.createElement("a");
				a.href = "javascript:void();";
				a.innerHTML = "Hide";
				YAHOO.util.Event.on(a, "click", clickHandler);
				div.appendChild(a);				
			}
			
		}
		
	},
	
	init: function(el) {
		this.el = YAHOO.util.Dom.get(el);
		this.count = 0;
		
		this.addLinks();
		
	}
	
}

var StepByStepList = function(el) {
	this.init(el);
}

StepByStepList.prototype = {
		
	init: function(el) {
		this.el = YAHOO.util.Dom.get(el);
		if( YAHOO.util.Dom.hasClass(this.el, "js") ) {
			return;
		}
		
		YAHOO.util.Dom.addClass(this.el, "js");	

		var clickHandler = function(e) { 			
			var element = e.target || e.srcElement;					
			if(YAHOO.util.Dom.hasClass(element, "hd")) {
				var hd = element;
			}
			else {
				var hd = element.parentNode;
			}
			
			var item = hd.parentNode;
			var link = hd.getElementsByTagName("a")[0];
			if( YAHOO.util.Dom.hasClass(item, "closed") ) {
				YAHOO.util.Dom.removeClass(item, "closed");
				link.className = "hide";
				link.innerHTML = "Hide";
			}
			else {
				YAHOO.util.Dom.addClass(item, "closed");
				link.className = "show";
				link.innerHTML = "Show";
			}

		};
				
		var count = 1;
		var item, bd, hd, ordinal, link;		
		for(var i = 0; i < this.el.childNodes.length; i++) {
			if( this.el.childNodes[i].nodeName == "LI" ) {
				item = this.el.childNodes[i];
				YAHOO.util.Dom.addClass(item, "closed");
				if( count % 2 == 0 ) {
					YAHOO.util.Dom.addClass(item, "alternate");
				}
				
				bd = YAHOO.util.Dom.getElementsByClassName("bd", "div", item)[0];
							
				hd = document.createElement("div");
				hd.className = "hd";
				YAHOO.util.Event.on(hd, "click", clickHandler, this, true);
				
				ordinal = document.createElement("span");
				ordinal.className = "ordinal";
				ordinal.innerHTML = count;
				hd.appendChild(ordinal);
				
				link = document.createElement("a");
				link.href = "javascript:void();";
				link.className = "show";
				link.innerHTML = "Show";
				hd.appendChild(link);
				
				for(var j = 0; j < item.childNodes.length; j++) {
					if( item.childNodes[j].nodeName == "H3" ) {
						hd.appendChild(item.childNodes[j]);
					}
				}
				
				item.insertBefore(hd, bd);
				
				count++;
			}
		}
		
	}
	
}
