// Global JavaScripts
$(document).ready(function() { 
    //$('ul#nav').superfish(); 
	sfHover();
		
	initrollovers();	
		
	// Accordion Functions
	if ($(".accordion").length > 0) {
		$(".accordion").accordion({animated: 'slide', autoHeight: false, collapsible: true, header: "h3"});
	}
	
	// Home Page Accordion Functions
	if ($(".accordion-home").length > 0) {
		$(".accordion-home").accordion({active: false, animated: 'slide', autoHeight: false, collapsible: true, header: "h3"});
	}
	
	//Case Study Promo Rollovers
	if ($(".case-study-promo").length > 0) {
		$(".case-study-promo").mouseover(function() {
			$(this).addClass("over");
			var src = $(this).find("img").attr("src");
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			$(this).find("img").attr("src", src.replace(ftype, '-over'+ftype));
		}).mouseout(function() {
			$(this).removeClass("over");
			var src = $(this).find("img").attr("src");
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			$(this).find("img").attr("src", src.replace('-over'+ftype, ftype));
		});
	}
	
	// Year Selector
	if($("#year-selector").length > 0) {
		$("#year-selector").click(function() {
			$(this).toggleClass("year-selector-over");
			$("#year-selector-panel").toggle();
		});
	}
			
			
	//Twirldown
	if($(".twirldown").length > 0) {
		$(".twirldown").click(function() {
			$(this).prev().toggle("fast");
			if ($(this).find("a").html()=="Close X")
				{
				$(this).find("a").html("Read More") 
				}
				else
				{
				$(this).find("a").html("Close X")
				}
				return false;
		});
		}

});

/* Just add class="rollover" to the img tag and make sure your images are named whatever.gif and whatever-over.gif */
/* You can use any kind of images and name them what you like.  The "-over" is the part that matters */
function initrollovers() {
	if (!document.getElementById) return;
	var aPreLoad = new Array();
	var sTempsrc;
	var aImages = $("img,input");
	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className == 'rollover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '-over'+ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aImages[i].onmouseover = function() {
				sTempsrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			aImages[i].onmouseout = function() {
				if (!sTempsrc) sTempsrc = this.getAttribute('src').replace('-over'+ftype, ftype);
				this.setAttribute('src', sTempsrc);
			}
		}
	}
};


// To make dropdown menus work in IE6
function sfHover() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.setAttribute('hclassname', this.className);
			this.className+=" selected sfHover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.getAttribute('hclassname');
		}
	}
}
