﻿initOnload();

function initOnload(){		
    addEvent(window, 'load',initRollovers);
    addEvent(window, 'load',initPrint);
}

var browser = navigator.appName;
var IE = "Microsoft Internet Explorer";
var vendor = navigator.vendor;
var safari = "Apple Computer, Inc.";
var imagePath = "/_layouts/images/cctb/";
var classAttribute = classAttr();   //Get the appropriate class attribute to set. IE and Firefox use different attributes for class in the DOM.

/**** Begin image rollover funtion ****/
/* Function to initalize rollover */
function initRollovers(){	
	var rollovers = getElementsByClass("rollover",null,null);	//Get elements with a class of "rollover"
	
	if (rollovers.length > 0){		//If there is at least one element with a class "rollover"
		for(var i=0;i<rollovers.length;i++){	//Loop through all elements with class "rollover"
			addEvent(rollovers[i],"mouseover",rollover);	//Attach mouseover event
			addEvent(rollovers[i],"mouseout",rollover);	//Attach mouseout event
		}		
	}
}

// This can be used for rollovers that are NOT transparent PNGs. In IE, transparent PNGs are replaced in the DOM with clearpixel.gif, so grabbing the src attribute
// in IE will only return clearpixel.gif, not the actual image src that we want to swap with its on/off state.
// This function grabs the src attribute and replaces "off" with "on" (for mouseover) or "on" with "off (for mouseout) in the attribute string. KM
function rollover(event) {
	var etype = event.type;
	var imgSrc = getImgSrc(this);
	var newImgSrc;
	
	if (etype == "mouseover"){
	    newImgSrc = imgSrc.replace("off.","on.","gi");
		this.setAttribute("src",newImgSrc);
	}
	
	else if (etype == "mouseout") {
	    newImgSrc = imgSrc.replace("on.","off.","gi");
		this.setAttribute("src",newImgSrc);
	}
}

function rolloverInline(imgId,type) {
	var imgObj = $(imgId);
	var imgSrc = getImgSrc(imgObj);
	var newImgSrc;	

	if (type == 'over'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}

	

	else if (type == 'out') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}
}
/***** End image rollover funtion *****/

/***** Begin tab change functions *****/
function initTabbing(){	
	var tabs = getElementsByClass("tab",null,null);	//Get elements with a class of "tab"
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
	
	if (tabs.length > 0){		//If there is at least one element with a class "tab"
		for(var i=0;i<tabs.length;i++){	//Loop through all elements with class "tab"
			addEvent(tabs[i],"click",tabClick);	//Attach click event
			addEvent(tabs[i],"mouseover",tabHover);	//Attach over event
			addEvent(tabs[i],"mouseout",tabHover);	//Attach out event
		}		
	}
	
	if (tabSections.length > 0){		//If there is at least one element with a class "tab-section"
		
		for(var i=0;i<tabSections.length;i++){	//Loop through all elements with class "tab-section"
			if(tabSections[i].getAttribute(classAttribute).indexOf("selected") == -1){
			    tabSections[i].style.visibility = "hidden";
//			    if (browser != IE){
//			        tabSections[i].style.visibility = "hidden";
//			    }
//			    else {
//			        tabSections[i].style.display = "none";
//			    }
			}
			if(tabSections[i].getAttribute(classAttribute).indexOf("selected") > -1){
			    if (browser != IE){
			        tabSections[i].style.height = "auto";
			        tabSections[i].style.width = "auto";
			    }
			    else {
				    tabSections[i].style.height = "100%";
				    tabSections[i].style.width = "100%";
                }
			    tabSections[i].style.overflow = "visible";
			}
		}				
	}
}

function tabClick(event){    
    var tabs = getElementsByClass("tab",null,null);	//Get tabs
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
    	
	for(var t=0;t<tabs.length;t++){ //Loop through all tabs
	    var tabObj = tabs[t];
	    var tabSectionObj = tabSections[t];
	    	    
	    if(tabObj == this){ //Change clicked tab on
            tabObj.setAttribute(classAttribute, "tab selected");
			tabSectionObj.style.visibility = "visible";
			if (browser != IE){
				tabSectionObj.style.height = "auto";
				tabSectionObj.style.width = "auto";
            }
            else {
				tabSectionObj.style.height = "100%";
				tabSectionObj.style.width = "100%";
            }
			tabSectionObj.style.overflow = "visible";
	    }
	    else {	//Turn other tabs off	        
            tabObj.setAttribute(classAttribute, "tab");
			tabSectionObj.style.visibility = "hidden";
			tabSectionObj.style.height = "0px";
			tabSectionObj.style.width = "0px";
			tabSectionObj.style.overflow = "hidden";
	    }
	    // Browser detection is a temporary fix for making FreeTextBox work in Firefox when it is placed in a div that is not shown.
		// Firefox needs to start by using visibility hidden, otherwise FreeTextBox will not register properly.
		// A better solution needs to be found. KM
	}
}

function tabHover(event){ 
    var etype = event.type;
	
	if (this.getAttribute(classAttribute) != "tab selected"){
	    if (etype == "mouseover"){
		    this.setAttribute(classAttribute,"tab hover");
	    }
    	
	    else if (etype == "mouseout") {
		    this.setAttribute(classAttribute,"tab");
	    }
	}
}
function tabHoverInline(id,state){ 
    var tab = $(id);
	
	if (tab.getAttribute(classAttribute) != "tab selected"){
	    if (state == "over"){
		    tab.setAttribute(classAttribute,"tab hover");
	    }
    	
	    else if (state == "out") {
		    tab.setAttribute(classAttribute,"tab");
	    }
	}
}
/***** End tab change functions *****/

/***** Begin showInputWidget function *****/
function showInputWidget(id){
    var inputBar = $(id);
    
    if(inputBar.style.display == "block"){
        inputBar.style.display="none";
    }
    else {
        inputBar.style.display="block";
    }
}
/***** End showInputWidget function *****/

/***** Begin pop up functions *****/
function popWindow(href,title,sb,width,height) {
	window.open(href,title,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+ sb +",resizable=0,width="+ width +",height="+ height +",top=150,left=100");
}
/***** End pop up functions *****/

/***** Begin print functions *****/
function initPrint(){	
	var printBtns = getElementsByClass("print",null,null);	//Get elements with a class of "print"
	
	if (printBtns.length > 0){		//If there is at least one element with a class "print"
		for(var i=0;i<printBtns.length;i++){	//Loop through all elements with class "print"
			addEvent(printBtns[i],"click",printPage);	//Attach click event
		}		
	}
}

function printPage() {
	window.print();
}
/***** End print functions *****/

/***** Begin member details photo module *****/
function initMemberPhotos(){	
	var thumbImages = getElementsByClass("thumbnail",null,null);	//Get elements with a class of "thumbnail"
	
	if (thumbImages.length > 0){		//If there is at least one element with a class "thumbnail"
		for(var i=0;i<thumbImages.length;i++){	//Loop through all elements with class "thumbnail"
			addEvent(thumbImages[i],"click",swapMemberPhotos);	//Attach click event
		}		
	}
}

function swapMemberPhotos() {
    var mainImageObj = getElementsByClass("main",null,null)[0];
    var clickedImage = getImgSrc(this).split(memberThumbPath)[1];
    var mainImage = getImgSrc(mainImageObj).split(memberImagePath)[1];
    
    for(var i=0;i<memberThumbnails.length;i++){        
        if(clickedImage == memberThumbnails[i]){
            mainImageObj.setAttribute('src',memberImagePath + memberImages[i]);              
        }
        if(mainImage == memberImages[i]){
            this.setAttribute('src',memberThumbPath + memberThumbnails[i]);
        }
    }	
}
/***** End member details photo module *****/

/***** Begin info bubbles *****/
function infoBubble(id){

    var parentEl = $(id).parentNode;
    var info = getElementsByClass("info-bubble",parentEl,null)[0];
    
    var selectFilter = $('gridview-filters');
    
    if(info.style.display == "block"){
        info.style.display="none";
        if ((browser == IE) && (id == "RegionImage0")){//Show select filters on member list page when IE and only the first area icon
            selectFilter.style.visibility = "visible";
        }
        if ((browser == IE) && (parentEl.getAttribute("id") == "read-about-it")){//Show select filters on member list page when IE and only the first area icon
            $("content-site").style.zIndex = "0";
        }
    }
    else {
        info.style.display="block";
        if ((browser == IE) && (id == "RegionImage0")){//Hide select filters on member list page when IE and only the first area icon
            selectFilter.style.visibility = "hidden";
        }
        if ((browser == IE) && (parentEl.getAttribute("id") == "read-about-it")){//Show select filters on member list page when IE and only the first area icon
            $("content-site").style.zIndex = "2000";
        }
    }
}
/***** End info bubbles *****/

/***** Begin google tracking outgoing links *****/
function initGoogleOutgoing(){	
	var outgoingLinks = getElementsByClass("google-outgoing",null,null);	//Get elements with a class of "print"
	
	if (outgoingLinks.length > 0){		//If there is at least one element with a class "google-outgoing"
		for(var i=0;i<outgoingLinks.length;i++){	//Loop through all elements with class "google-outgoing"
			addEvent(outgoingLinks[i],"click",googleOutgoing);	//Attach click event
		}		
	}
}

function googleOutgoing(){
    var linkObj = $(this);
    var linkHREF = linkObj.getAttribute("href");
    var googleLink = "/outgoing/" + linkHREF.split("http://")[1];
    
    urchinTracker(googleLink);
}
/***** End google tracking outgoing links *****/

/***** Begin random home page image *****/
var hpImages = new Array("homepage_image4.jpg");
var p = hpImages.length;

var whichImage = Math.round(Math.random()*(p-1));
function randomHPImage(){
    var hpimgObj = $("homepage-image");
    hpimgObj.setAttribute('src',imagePath + hpImages[whichImage]);
}
/***** End random home page image *****/