document.observe("dom:loaded", function(){
	if($$('body')[0].hasClassName('HomePage') == true) {SpotLight.init()}
	eHA.loadMeta();
/*
	if($$('body')[0].hasClassName('SearchPage')==true){
		pageToolBarFunctions = new PageToolBarFunctions({textDiv:'content_main'});
		SearchPageExpandCollapse.childrenContainerSelector='.category_result';
		SearchPageExpandCollapse.childrenSelector='.result';
		SearchPageExpandCollapse.init('resultsMain');
	}
	else {
		pageToolBarFunctions = new PageToolBarFunctions({textDiv:'content_body'});
	}
	
	pageToolBarFunctions.shareThisSelector=' .addthis_button';
	pageToolBarFunctions.registerToolBars('#page_toolbar');
*/	

page_toolbar(); 
if (check_text_size()){
change_link_text();
}

	NavigationSelect.setSelectedOpen("div#content_body_left div.page_list",eHA.assetid);
	NavigationSelect.setParents("#content_body_left .page_list ul li");
	NavigationSelect.setActive("div#content_body_left div.page_list",eHA.assetid);
	//if left navigation create navigation selectors
	if($$('div#content_body_left div.page_list')){	NavigationSelect.setFirst("div#content_body_left div.page_list ul li");}
	NavigationSelect.setSelected("div#primary_navigation",eHA.assetid);
	NavigationSelect.setSelected("div#action_toolbar",eHA.assetid);
	NavigationSelect.setSelected("div#global_navigation",eHA.assetid);
	NavigationSelect.setSelected("div#portal_navigation",eHA.assetid);

	if(eHA.assetid !== eHA.categoryid){
		NavigationSelect.setSelected("div#primary_navigation",eHA.categoryid);
		NavigationSelect.setSelected("div#action_toolbar",eHA.categoryid);
		NavigationSelect.setSelected("div#global_navigation",eHA.categoryid);
	}

	MoreButtons.divsToHideSelectors.push(".category_general_body");
	MoreButtons.divsToHideSelectors.push("#make_an_appointment");
	if($('content_right_rail')){MoreButtons.createMoreButtons();}
	mediaDirectory.usePanels = true;
	mediaDirectory.assignMediaEvents();
});

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;

/**
 * rewrites prototype's String#unescapeHTML so that it further decodes &apos; and &quot;
 * @function
 * @return {String} decoded string
 */
String.prototype.unescapeHTML = function(){
	return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&').replace(/&apos;/g,'\'').replace(/&quot;/g,"\"");
}
var TabRollOvers = {
	setRollovers: function(selector){
		this.hoverSelector = selector;
		$$(this.hoverSelector).each(function(element){
			element.observe('mouseover',function(event){
				element.className=element.className+' hover';
				element.addClassName(' hover');
			});
			element.observe('mouseout',function(event){
				element.removeClassName('hover');
				element.className=element.className.replace(' hover','');
			});
			element.observe('click',function(event){
				window.location=this.down('a').getAttribute('href')
			})
		});
	},
	focusIndex:0,
	setTabFocus: function(selector){
		$$(selector).each(function(element,i){
			this.focusIndex++;
			element.down('a').setAttribute('tabindex',-1);
			element.setAttribute('tabindex',this.focusIndex);
			element.observe('keydown',function(event){if(event.keyCode==Event.KEY_RETURN){window.location=Event.element(event).down('a').href;}})
		}.bind(this));
	}
};

var MoreButtons = {
	relatedDivSelectors:new Array(".smart_navigation","#clinical_trials_smart_navigation","#category_related_links","#category_related_documents"),
	divsToHideSelectors:new Array(".media_wrapper","#content_body_right .display_media",".category_general_body",".content_category_information",".page_title",".service_description",".contact_information",".release_date",".city_state","#media_contacts","#listed_item","#listed_location","#location_tab_navigation","#tabs_content",".page_general_body"),
	//divsToHideSelectors:new Array(".media_wrapper",".category_general_body",".content_category_information",".page_title",".service_description",".contact_information",".release_date",".city_state","#media_contacts","#make_an_appointment"),
	createMoreButtons: function(){
		this.relatedDivSelectors.each(function(selector){
			$$(selector).each(function(element){
			if(element.select('ul.sub li').length > 0){var liArray=element.select('ul.sub li');}
			else{var liArray=element.select('ul li');}
			liArray.each(function(element,i){if(i>2){element.hide()}});
			if(liArray.length>2){
				var moreLink=new Element('a',{href:'javascript:void(0)'}).addClassName('see_more_related').update('more >>');
				element.appendChild(moreLink);
				moreLink.observe('click',function(event){
					var divCounter=0;
					var afterFinishFunction=function(){return false}
					this.divsToHideSelectors.each(function(divSelect){$$('#content_body '+divSelect).each(function(element,i){
						if(divCounter==0){afterFinishFunction=function(){MoreButtons.showMore(moreLink.up('div'))}}
						Effect.Fade(element,{ duration: .3,afterFinish:afterFinishFunction});
						divCounter++;
					})});
					if(divCounter==0){MoreButtons.showMore(moreLink.up('div'))}
				}.bind(this));
			}
			else if(liArray.length==0){element.hide()}
			}.bind(this));
		}.bind(this))
	},
	showMore:function(element){
		var newElement=new Element('div').addClassName('more_related').insert(element.cloneNode(true)).setStyle({display:'none'});
		newElement.select('.see_more_related')[0].remove();
		newElement.insert(new Element('a',{href:"javascript:void(0)"}).addClassName('remove').update('<<<'));
		newElement.select('.remove')[0].observe('click',function(event){Effect.Fade(newElement,{afterFinish:MoreButtons.showOriginal,duration: .3})}.bind(this));
		newElement.select('li').invoke('show');
		if(newElement.down('ul').select('ul').length>0){
			newElement.down('ul').addClassName('no_list_style');
		}
		if($$('#content_body .more_related')[0]){$$('#content_body .more_related')[0].remove();}
		$('content_body').appendChild(newElement);
		Effect.Appear(newElement,{ duration: .3});
		//Effect.SlideDown(newElement);
	},
	showOriginal:function(){
		$$('#content_body .more_related').invoke('remove');
		MoreButtons.divsToHideSelectors.each(function(divSelect,i){$$('#content_body '+divSelect).each(function(element){
			Effect.Appear(element,{ duration: .3});
		})});
	}
};


/**
 * 
 * 
 * @namespace
 */
var NavigationSelect = {
	selectedClass: " sel",
	openClass: " open",
	parentClass:" parent",
	activeClass:" active",
	activeParentClass:" activeParent",
	firstClass:" first",
	/**
	 * selects the nav appropriately
	 * @function
	 * @param {String} selector CSS selector for DIV of nav
	 * @requires eHA.assetid
	 */
	setSelected: function(selector,assetid){
		if(typeof assetid !== "undefined"){
			if($$(selector)[0] && $$(selector)[0].select(".assetid-"+assetid)[0]){
				$$(selector)[0].select(".assetid-"+assetid).each(function(element){
					if($(element).up("li") && !$(element).up("li").hasClassName("sel")){
						$(element).up("li").className += this.selectedClass;
						$(element).up("li").addClassName(this.selectedClass);
					}else{
						if(!$(element).hasClassName("sel")){
							$(element).className += this.selectedClass;
							$(element).addClassName(this.selectedClass);
						}
					}
				}.bind(this));
			}
		}

	},
	setFirst: function(selector){
		if($$(selector)[0]) $$(selector)[0].addClassName(this.firstClass);
		if($$(selector)[0]) $$(selector)[0].down("span a").addClassName(this.firstClass);
	},

	setOpen: function(selector,assetid){
		if(typeof assetid !== "undefined"){
			if($$(selector)[0] && $$(selector)[0].select(".assetid-"+assetid)[0]){
				$$(selector)[0].select(".assetid-"+assetid).each(function(element){
					if($(element).up("ul"))
						$(element).up("ul").addClassName(this.openClass);
					if($(element).down("ul"))
						$(element).addClassName(this.parentClass);
					if($(element).up("li"))
						$(element).up("li").addClassName('test');
				}.bind(this)); 
			}
		}
	},
	setActive: function(selector,assetid){
			if(typeof assetid !== "undefined"){
			if($$(selector)[0] && $$(selector)[0].select(".assetid-"+assetid)[0]){
				$$(selector)[0].select(".assetid-"+assetid).each(function(element){
						$(element).className += this.activeClass;
						if($(element).up("li").up("ul").up("li")) $(element).up("li").up("ul").up("li").addClassName(this.activeParentClass);


				}.bind(this));
			}
		}
	},
	setParents: function(parentSelector){
			$$(parentSelector).each(function(element){
			if($(element).down("ul")) $(element).addClassName('parent');
		  })

	},
	setSelectedOpen: function(selector,assetid){
		if(typeof assetid !== "undefined"){
			if($$(selector)[0] && $$(selector)[0].select(".assetid-"+assetid)[0]){
				$$(selector)[0].select(".assetid-"+assetid).each(function(element){
					if($(element).up("ul"))
						$(element).up("ul").addClassName(this.openClass);
					if($(element).up("ul").up("li"))
						$(element).up("ul").up("li").addClassName(this.openClass);
					if($(element).up("li") && !$(element).up("li").hasClassName("sel")){
						$(element).up("li").className += this.selectedClass;
						$(element).up("li").addClassName(this.selectedClass);
					}else{
						if(!$(element).hasClassName("sel")){
							$(element).className += this.selectedClass;
							$(element).addClassName(this.selectedClass);
						}
					}
				}.bind(this));
			}
		}
	}
};

var SearchPageExpandCollapse={
	childrenContainerSelector:'',
	childrenSelector:'',
	init:function(selector){
		$$('#'+selector+' '+this.childrenContainerSelector).each(function(element){
			var elementChildren=element.select(this.childrenSelector);
			elementChildren.each(function(result,i){
				if(i>=3){result.hide();}
			});	
			if(elementChildren.length>3){
				element.setAttribute('aria-expanded','false');
				element.insert(new Element('a',{href:'javascript:void(0)'}).update('More Results from '+element.down('h2').innerHTML).addClassName('see_more').observe('click',this.handleClick.bindAsEventListener(this)))
			}
		}.bind(this));
	},
	handleClick:function(event){
		var parentDiv=Event.element(event).up(this.childrenContainerSelector);
		if(parentDiv.getAttribute('aria-expanded')=='false'){
			Event.element(event).update(Event.element(event).innerHTML.replace('More','Less'));
			Event.element(event).addClassName('open');
			parentDiv.setAttribute('aria-expanded','true');
			parentDiv.select(this.childrenSelector).invoke('show');
		}
		else{
			Event.element(event).update(Event.element(event).innerHTML.replace('Less','More'));
			Event.element(event).removeClassName('open');
			parentDiv.setAttribute('aria-expanded','false');
			parentDiv.select(this.childrenSelector).each(function(result,i){
				if(i>=3){result.hide();}
			});
		}
	}
}




// add remove text in search bar field
function clearField(theField, defaultText) {
	if (theField.value == defaultText) {
		theField.value = "";
	}
}

function revertField(theField, defaultText) {
	if (theField.value == "") {
		theField.value = defaultText;
	}
}

var eHA = {
	Version: '3.3.5',
	Site: 'demo',
	requiredFlashVersion: '9.0.0',
	includeScripts: "media,panels,swfobject,qtobject", // possible scripts to include
	loadMeta: function(){
		if(this.meta("Asset_Id")){
			this.assetid = this.meta("Asset_Id");
		}
		if(this.meta("eHA_Category_Id")){
			this.categoryid = this.meta("eHA_Category_Id");
		}
	},
	require: function(libraryName) {
		// inserting via DOM fails in Safari 2.0, so brute force approach
		document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
	},
	REQUIRED_PROTOTYPE: '1.6.1',
	load: function() {
		function convertVersionString(versionString){
			var r = versionString.split('.');
			return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
		}
	
		if((typeof Prototype=='undefined') || 
				(typeof Element == 'undefined') || 
				(typeof Element.Methods=='undefined') ||
				(convertVersionString(Prototype.Version) < 
						convertVersionString(eHA.REQUIRED_PROTOTYPE)))
			throw("eHA requires the Prototype JavaScript framework >= " +
					eHA.REQUIRED_PROTOTYPE);
	
		$A(document.getElementsByTagName("script")).findAll( function(s) {
			return (s.src && s.src.match(/eHA\.js(\?.*)?$/))
		}).each( function(s) {
			var path = s.src.replace(/eHA\.js(\?.*)?$/,'');
			var includes = s.src.match(/\?.*load=([a-z,]*)/);
			(includes ? includes[1] : eHA.includeScripts).split(',').each(
					function(include) { eHA.require(path+include+'.js') });
		});
	},
	/**
	 * returns "content" attribute of requested meta tag
	 * @function
	 * @param {String} metaName
	 * @example alert(eHA.meta("Asset_Id")); // will output "1264128919400" (or something)
	 * @returns {String} value of meta's "content" or false if metaName can't be found
	 */
	meta: function(metaName){
		if($$("meta[name="+metaName+"]")[0]){
			return $$("meta[name="+metaName+"]")[0].readAttribute("content");
		}else{
			return false;
		}
	},
	log: {
		// there are 4 log levels, 0 = off, 1 = error, 2 = warning, 3 = debug
		verbosity_level: 0,
		messages_total: 0, // number of total messages
		messages_1: 0, // number of error messages
		messages_2: 0, // number of warning messages
		messages_3: 0, // number of debug messages
		create: function(log_string,log_level_int){
			if(log_level_int<4 && log_level_int>0){
				this.messages_total++;
				eval("this.messages_"+log_level_int+"++;");
				if(this.verbosity_level>=log_level_int){
					// this message should be displayed, prepare outputString
					eval("var message_number = this.messages_"+log_level_int);
					var message_name = "ERROR MESSAGE";
					if(log_level_int==2) message_name = "WARNING MESSAGE";
					if(log_level_int==3) message_name = "DEBUG MESSAGE";
					var outputString = message_name+" "+new Date()+" "+message_number+": "+log_string;
					this.output(outputString);
				}
			}
		},
		output: function(outputString){
			// placeholder function.  redefine this function in order to see output
		}
	},
	loadValuefromClass: function(el, requestedName){
		var requestedValue = false;
		var classNames = el.className.split(" ");
		for(var cni=0;cni<classNames.length;cni++){
			if(classNames[cni].indexOf('-')!=-1){
				classNameSplit = classNames[cni].split('-');
				if(classNameSplit[0]==requestedName){
					requestedValue = classNameSplit[1];
				}
			}
		}
		return requestedValue;
	},
	elementAttributeArray: ["class","id","title","style","dir","lang","cite","classid","type","href","src","alt","name","value","for","action","method","target","enctype","accept","accepty-charset","longdesc","height","width","disabled","selected","checked","profile","size","multiple","label","xmlns","maxlength","cols","rows"],
	
	/**
	 * turns an HTML element into a javascript object
	 * uses all attributes of HTML element (from above array)
	 * as well as any name-value pairs in "className" to set properties
	 * NOTE: className property will also continue to contain all
	 * classes
	 * 
	 * @function
	 * @param {Element} el
	 * @returns {Object}
	 */
	elementToObjectLiteral: function(el){
		var objectLiteral = {};
		for (var i=0; i<eHA.elementAttributeArray.length; i++){
			var thisAttrName = eHA.elementAttributeArray[i];
			if(thisAttrName.indexOf("class")!=-1) thisAttrName = "className"; // this is necessary for IE
			var thisAttrValue = $(el).readAttribute(thisAttrName);
			if(thisAttrValue!==null){
				try{
					eval("objectLiteral."+thisAttrName+"='"+thisAttrValue+"'");
				}catch(err){
					eHA.log.create(err.name+": "+err.message+" -- objectLiteral."+thisAttrName+"='"+thisAttrValue+"'", 1);
				}
			}
		}
		if(el.className){
			var classNames = el.className.split(" ");
			for(var cni=0;cni<classNames.length;cni++){
				if(classNames[cni].indexOf('-')!=-1){
					classNameSplit = classNames[cni].split('-');
					eval("objectLiteral."+classNameSplit[0]+"='"+classNameSplit[1]+"'");
				}
			}
		}
		return objectLiteral;
	},
	addChild: function(ob, childName, childOb){
	   ob[childName] = childOb;
	   childOb.parent = ob;
	}
}

function check_text_size() {
	var cookie = get_cookie("text_size");
	var current_text_size = cookie ? cookie : get_default_text_size();
	return set_current_text_size(current_text_size);
}

function change_link_text() {
			if($('page_toolbar')){
			var text_link = document.getElementById("page_toolbar_text").getElementsByTagName("a")[0];
			var text_node = document.createTextNode("Increase/Decrease Text Size");
			text_link.className = "decrease";
			text_link.setAttribute("title", "Decrease Text Size");
			text_link.removeChild(text_link.firstChild);
			text_link.appendChild(text_node);
			}

}

function returnPageURL() {
	// alert(document.location.href);
	return document.location.href
}

function eHA_escapeSingleQuote(strVal) {
	sRetVal = new String(strVal);
	sRetVal = sRetVal.replace(/'/g,"\\'");
	return sRetVal;
}

function eHA_escapeDoubleQuote(strVal) {
	sRetVal = new String(strVal);
	sRetVal = sRetVal.replace(/\"/g,/\\"/);
	return sRetVal;
}

function popupEmailWindow(pagename, pageurl, sitename) {
	top.thisWin= window.open("/EmailPage/email_this_page.jsp?siteName=" + escape(sitename) + "&pageDisplayName=" + pagename + "&pageURL=" + escape(pageurl),"thisPage","scrollbars=1,resizable=1,menubar=0,toolbar=0,width=640,height=500");
	if(!top.thisWin.closed) top.thisWin.focus();
}
					
function page_toolbar() {
		if($('page_toolbar')){
			var text_link = document.getElementById("page_toolbar_text").getElementsByTagName("a")[0];
			var print_link = document.getElementById("page_toolbar_print").getElementsByTagName("a")[0];
			var bookmark_link = $$("#page_toolbar_bookmark a")[0];
		
			bookmark_link.onclick = function(){
				var thisURL = document.location.href;
				var thisTitle = document.title;
				bookmarkPage(thisURL,thisTitle);
				return false;
			}
		
			text_link.onclick = function () {
				toggle_text_size(this);
				return false;
			}
		
			print_link.onclick = function () {
				window.print();
				return false;
			}
	}
}

					// ########### change text size javascript ###########
					var DEFAULT_SIZE = "100%";
					var LARGER_SIZE = "110%";
					
					function toggle_text_size(text_link) {
						if (document.documentElement.style.fontSize == LARGER_SIZE) decrease_text(text_link);
						else increase_text(text_link);
						
					}
					
					function increase_text(text_link) {
					
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							document.documentElement.style.fontSize = LARGER_SIZE;
							text_link.className = "decrease";
							text_link.setAttribute("title", "Decrease Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
					
					}
					
					function change_link_text() {
					
							var text_link = document.getElementById("page_toolbar_text").getElementsByTagName("a")[0];
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							text_link.className = "decrease";
							text_link.setAttribute("title", "Decrease Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
							
					
					}
					
					function decrease_text(text_link) {
					
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							document.documentElement.style.fontSize = DEFAULT_SIZE;
							text_link.className = "increase";
							text_link.setAttribute("title", "Increase Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
					
						
					}
					function check_text_size() {
						var cookie = get_cookie("text_size");
						var current_text_size = cookie ? cookie : get_default_text_size();
						return set_current_text_size(current_text_size);
					}
					
					
					function text_size_unload() {
						var current_text_size = get_current_text_size();
						make_cookie("text_size", current_text_size);
					}

					addUnloadEvent(text_size_unload);
					
					function set_current_text_size(current_text_size) {
						if (current_text_size == LARGER_SIZE) {
							document.documentElement.style.fontSize = LARGER_SIZE;
							return true;
						}
						return false;
					}
					
					function get_default_text_size() { return DEFAULT_SIZE; }
					
					function get_current_text_size() {
					
						if (document.documentElement.style.fontSize == LARGER_SIZE) return LARGER_SIZE;
						else return DEFAULT_SIZE;
						
					}
					
					function make_cookie(name, val) {
  						var expires = "";
  						document.cookie = name+"="+val+expires+"; path=/";
					}
					
					function get_cookie(name) {
					
						var n = name + "=";
						var cookieArray = document.cookie.split(';');
					
						for( var h = 0; h < cookieArray.length; h++ ) {
					
							var c = cookieArray[h];
					
							while (c.charAt(0)==' ') c = c.substring(1,c.length);
					
							if (c.indexOf(n) == 0) return c.substring(n.length,c.length);
					
						}
					
						return null;

					}


					// ##### END CHANGE TEXT SIZE JAVASCRIPT ##########################

					// ##### FUNCTION: addUnloadEvent
					// #####  PURPOSE: appends a function to the window.unonload event handler 
					function addUnloadEvent(func) {
						var oldonunload = window.onunload;
						if (typeof window.onunload != 'function') {
							window.onunload = func;
						} else {
							window.onunload = function() {
								if (oldonunload) {
									oldonunload();
								}
								func();
							}
						}
					}

					// ##### FUNCTION: addLoadEvent
					// #####  PURPOSE: appends a function to the window.onload event handler 
					function addLoadEvent(func) {
						var oldonload = window.onload;
						if (typeof window.onload != 'function') {
							window.onload = func;
						} else {
							window.onload = function() {
								if (oldonload) {
									oldonload();
								}
								func();
							}
						}
					}


					function bookmarkPage(bookmarkURL,bookmarkTitle){
						try{
							window.external.AddFavorite(bookmarkURL, bookmarkTitle);
						}catch(e){
							alert("To bookmark this page please type Ctrl+D on your keyboard.");
						}
					}


