﻿/* This is for the checkbox, radio button and select field dropdown styles */

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

/* End checkbox, radio button and select field dropdown styles */

$(function(){
	//Makes the wrapper the same height as the content div
	//contentHeight = $('div#content').height();
	//newHeight = contentHeight + 20 + "px"
	//$('div#wrapper').height(newHeight);
	
	//Gives the page subnav the show/hide functionality for the subsequent sections
	var divs = $('div.content-with-sub-nav').children('div');//Find and put into an array, all of the div sections within the container div
	var links = $('div#sub-menu').find('ul > li > a');//Find and put into an array, all the links within the sub nav ul list items
	var links2 = $('div#sub-menu2').find('ol > li > a');// For the 8 ways links in the Intro page. //Find and put into an array, all the links within the sub nav ul list items
	var currentdiv = 0;
	
	divs.hide().filter(':first').show().addClass('current');//Hide all the divs besides the default/first one
	links.filter(':first').addClass('selected');//set the correct link to 'selected'
	links2.filter(':first').addClass('selected');// For the 8 ways links in the Intro page. //set the correct link to 'selected'
	
	links.click(function(){//On click of a sub nav button, show/hide the appropriate div depending on its index
		links.removeClass('selected');
		$(this).addClass('selected');
		thisPos = links.index(this);
		divs.hide();
		divs.eq(thisPos).show();
		compplan(thisPos);//specifically for the comp plan page to reset the next/prev buttons to show/hide.
		return false;
	});
	// For the 8 ways links in the Intro page. 
	links2.click(function(){//On click of a sub nav button, show/hide the appropriate div depending on its index
		links2.removeClass('selected');
		$(this).addClass('selected');
		thisPos = links2.index(this) + 1;
		divs.hide();
		divs.eq(thisPos).show();
		compplan(thisPos);//specifically for the comp plan page to reset the next/prev buttons to show/hide.
		return false;
	});
	
	//Comp plan next/prev buttons hide/show
	function compplan(number){//specifically for the comp plan page to reset the next/prev buttons to show/hide.
		currentdiv = number;
		if (number == divs.length - 1){
			$('a.compplan-next').hide();
			$('a.compplan-prev').show();
		} else if (number == 0){
			$('a.compplan-next').show();
			$('a.compplan-prev').hide();
		} else {
			$('a.compplan-next').show();
			$('a.compplan-prev').show();
		}
		$('div.current').hide().removeClass('current');
		divs.eq(number).show().addClass('current');
		links.removeClass('selected');
		links2.removeClass('selected');// For the 8 ways links in the Intro page. 
		links.eq(number).addClass('selected');
		links2.eq(number).addClass('selected');// For the 8 ways links in the Intro page. 
	};
	compplan(0);//call it on page load
	
	//Comp plan next/prev buttons
	$('a.compplan-next').click(function(){
		compplan(currentdiv + 1);
		return false;
	});
	$('a.compplan-prev').click(function(){
		compplan(currentdiv - 1);
		return false;
	});
	
	//Main Nav
	$('li:has(ul)').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); });

	//Timeline Nav	
	var yeardiv = $('div#timeline').children('div');
	var timelinelinks = $('ul#timeline-nav').find('li > a');
	timelinelinks.click(function(){
		timelinelinks.removeClass('selected');
		$(this).addClass('selected');
		thisIndex = timelinelinks.index(this);
		years_top = (thisIndex * -361) + "px";
		$('div#timeline-years').animate( {top: years_top}, 500, "swing" );
		return false
	});
		
	//Contact Page
	contactDivs = $('div#info-box').children('div');
	contactDivs.hide();
	contactDivs.eq(0).show();
	
	//Contact Tooltips
	$('div#map area').each(function(){
		ref = $(this).attr('href');
		$(this).qtip({
			content: {
				prerender: true,
				text: "<a class='maplink' href='" + ref + "'>" + $(this).attr('alt') + "</a>"
			},
			hide: {
				fixed: true // Make it fixed so it can be hovered over
			},
			style: {
				name: 'red', // Give it the preset dark style
				border: {
				   width: 0, 
				   radius: 4 
				}, 
				tip: false // Apply a tip at the default tooltip corner
			},
			position: {
				corner: {
					target: 'topMiddle',
					tooltip: 'bottomMiddle'
				}
			}
		})
	});

	//Contact info show/hide
	$('a.maplink').click(function(){
		target = $(this).attr('href').match(/#\w*/);
		contactDivs.hide();
		$('div' + target).show();
		return false
	});
});

// POP-UP Function
var newWin = null;

function popURL(strURL,strType,strHeight,strWidth) 
	{
		var strOptions="";

		if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
		if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
		if (strType=="elastic") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;

		newWin = window.open(strURL, 'newWin', strOptions);

		newWin.focus();
}
