// the entirety of global.js is wrapped in a "modern browser check"
// none of this code should run in browsers which fail the check.
if(detectBrowser.modernBrowser()){

/*
	Section nav blinds 
	
	Note: the string 'test123' can be replaced with a variable that is set in another 
	      dynamically-generated javascript file so that the blinds can highlight and open
	      the correct item or sub-item as "current"
	
*/
Event.observe(window, 'load', function() {
	if($$('.section_nav_blinds .content').length > 0){
		var s3 = new Blinds($$('.section_nav_blinds .content'),$$('.section_nav_blinds')[0],null,{'current_id':$('menu_item_id').value});
	}
	if($$('.section_nav_blinds .no_content_section').length > 0){
			if($('menu_item_id') != null && $('menu_item_id').value != '')
			{
				var idVal = $('menu_item_id').value;
				if(document.getElementById(idVal) != null){
					document.getElementById(idVal).style.color  = "#99CCFF";
				}
			}
	}
}, false);


/*This is for On Demand Video. Calls function in plgindemandtv.js*/
Event.observe(window, 'load', function() {
	var nasatv = document.getElementById("NASATV");
	if (nasatv)
	{
		getSelectedVideoChannel();
	}
},false);


/*This is for NASA TV */
Event.observe(window, 'load', function() {
	var nasa_tv_rd = document.getElementById("nasa_tv_rd");
	if (nasa_tv_rd)
	{
		GetSelectedChannelNASATV();
	}
},false);


/*clear text input fields*/
Event.observe(window, 'load', function() {
	if($$('.input_clear')){
		$$('.input_clear').each(function(element){
			
			element.oldValue = element.value;
			
			Event.observe(element, "focus", function(e) {
				if(element.value == element.oldValue) {
					element.value = "";
				}
				Event.stop(e);
			});
			
		});
	}
}, false);

/* popular content blinds bootstrap */

Event.observe(window, 'load', function() {
	var allBlinds = $$('.narrow_blue_blinds').map(function(narrow_blue_blinds){
		var contents = narrow_blue_blinds.getElementsBySelector('.content');
		var cap = narrow_blue_blinds.getElementsBySelector('.cap')[0];
		return new Blinds(contents,narrow_blue_blinds,cap);
	});
}, false);

Event.observe(window, 'load', function() {
	var allBlinds = $$('.narrow_blue_blinds_img').map(function(narrow_blue_blinds_img){
		var contents = narrow_blue_blinds_img.getElementsBySelector('.content');
		var cap = narrow_blue_blinds_img.getElementsBySelector('.cap')[0];
		return new Blinds(contents,narrow_blue_blinds_img,cap);
	});
}, false);

/* Modules_Widgets-style grey accordions */
Event.observe(window, 'load', function() {
	$$('.grip_accordion').each(function(item){
		var s3 = new Blinds(item.getElementsBySelector('.content'),item, item.getElementsBySelector('.cap')[0]);
	});
}, false);

/* main news accordion bootstrap */
Event.observe(window, 'load', function() {
	if ($$('.main_news_accordion .content').length > 0) {
		$$('.main_news_accordion').each(function(item){
			var content = item.getElementsBySelector('.content');
			var cap = item.getElementsBySelector('.cap')[0];
			var s3 = new Blinds(content,item,cap);
		});
	}
}, false);	
/* top middle blinds bootstrap */
Event.observe(window, 'load', function() {
	if($$('.top_middle_blinds .content').length > 0){
		$$('.top_middle_blinds').each(function(item){
			var content = item.getElementsBySelector('.content');
			var cap = item.getElementsBySelector('.cap')[0];
			
			var s3 = new Blinds(content,item,cap);		
		});

	}
}, false);

/* main video accordion bootstrap */
Event.observe(window, 'load', function() {
	if ($$('.main_video_accordion .content').length > 0) {
		$$('.main_video_accordion').each(function(item){
			var content = item.getElementsBySelector('.content');
			var cap = item.getElementsBySelector('.cap')[0];
			var s4 = new Blinds(content,item,cap);
		});
	}
}, false);

/*For Video Landing Page */
Event.observe(window, 'load', function() {
	if ($$('.main_video_accordion_landing .content').length > 0) {
		$$('.main_video_accordion_landing').each(function(item){
			var content = item.getElementsBySelector('.content');
			var cap = item.getElementsBySelector('.cap')[0];
			var s4 = new Blinds(content,item,cap);
		});
	}
}, false);

/*For Video Pop-up Page */
Event.observe(window, 'load', function() {
	if ($$('.main_video_accordion_popup .content').length > 0) {
		$$('.main_video_accordion_popup').each(function(item){
			var content = item.getElementsBySelector('.content');
			var cap = item.getElementsBySelector('.cap')[0];
			var s4 = new Blinds(content,item,cap);
		});
	}
}, false);


/* SEARCH BUTTON SUBMIT */
Event.observe(window, 'load', function() {
	$$('.searchbtn').each(function(item){
		Event.observe(item, 'click', function() {
			window.location.href="search_results.html";
		}, false);
	});
}, false);

/* Overlays RSS bootstrap */
Event.observe(window, 'load', function() {
	if($$('.myOverlayRSS')){
		var allOverlays = $$('.myOverlayRSS').map(function(myOverlay){
			
			var theHref = myOverlay.href;

			function renderOverlayRss(contentElement, theHref){
				contentElement.innerHTML = "";
				
				function addRssPop(w, h, url){
					window.open(url, '', 'width='+ w +', height='+ h +', toolbar=no, resizable=yes, scrollbars=yes');
				}
				
				if(!Prototype.Browser.WebKit){
					var fieldFocus = "javascript: $$('.copy_bookmark')[0].select();";
				}
			
				var rssTitle = document.title;
				
				var title = new Element('h5',{});
				title.update("Add RSS");
				
				var description = new Element("p",{});
				description.update('Select a web-based rss site:');


				function makeListLink(title,classname,hideText){
					var link = new Element('a',{'className':classname,'href':'#'});
					if(hideText){
						var span = new Element('span',{'className':'hide'});
						span.update(title);
						link.insert(span);
					} else {
						link.update(title);
					}
					var li = new Element('li',{});
					li.insert(link);
					return li;
				}

				var links1 = [
					{className:'bookmark_msn',title:'My MSN'},
					{className:'bookmark_technorati',title:'Technorati'},
					{className:'bookmark_aol',title:'My Aol'}
				];
				var list1 = new Element('ul',{'className':'rss_left_ul'});
				for(var i=0;i<links1.length;i++){
					list1.insert(makeListLink(links1[i]['title'],links1[i]['className'],links1[i]['hideText']));
				}
							
				var links2 = [
					{className:'rss_google',title:'Google',hideText:true},
					{className:'bookmark_yahoo',title:'Yahoo!'}
				];
				var list2 = new Element('ul',{'className':'rss_right_ul'});
				for(var i=0;i<links2.length;i++){
					list2.insert(makeListLink(links2[i]['title'],links2[i]['className'],links2[i]['hideText']));
				}
	

				var br = new Element('br',{'className':'clear'});

				var footer = new Element('p',{});
				footer.update('Or copy the link below:');

				var textArea = new Element('textarea',{'className':'copy_bookmark','onfocus':fieldFocus});
				textArea.update(theHref);
				
				list1 = $(list1);
				list2 = $(list2);
				
				var rssTechnorati = list1.getElementsBySelector('.bookmark_technorati')[0];
				var rssTechnoratiURL = '../technorati.com/faves@add='+ theHref;
				
				Event.observe(rssTechnorati, "click", function(e) {
					addRssPop(980, 460, rssTechnoratiURL);
					Event.stop(e);
				});
				
				
				var rssAol = list1.getElementsBySelector('.bookmark_aol')[0];
				var rssAolURL = '../feeds.my.aol.com/add.jsp@url='+ theHref;
				
				Event.observe(rssAol, "click", function(e) {
					addRssPop(980, 460, rssAolURL);
					Event.stop(e);
				});
				
				var rssGoogle = list2.getElementsBySelector('.rss_google')[0];
				var rssGoogleURL = '../fusion.google.com/add@feedurl='+ theHref;
				
				Event.observe(rssGoogle, "click", function(e) {
					addRssPop(920, 460, rssGoogleURL);
					Event.stop(e);
				});
				
				var rssYahoo = list2.getElementsBySelector('.bookmark_yahoo')[0];
				var rssYahooURL = '../add.my.yahoo.com/rss@url='+ theHref;
				
				Event.observe(rssYahoo, "click", function(e) {
					addRssPop(920, 460, rssYahooURL);
					Event.stop(e);
				});
				
				var rssMsn = list1.getElementsBySelector('.bookmark_msn')[0];
				var rssMsnURL = '../my.msn.com/addtomymsn.armx@id=rss&ut='+ theHref;
				
				Event.observe(rssMsn, "click", function(e) {
					addRssPop(980, 460, rssMsnURL);
					Event.stop(e);
				});
	
				contentElement.appendChild(title);
				contentElement.appendChild(description);
				contentElement.appendChild(list1);
				contentElement.appendChild(list2);
				contentElement.appendChild(br);
				contentElement.appendChild(footer);
				contentElement.appendChild(textArea);
			
			}
			
			var classSplit = myOverlay.classNames().toString();
			var floatType = new Array();
			floatType = classSplit.split(" ");
	
			Event.observe(myOverlay, "mouseover", function(cellElement, floatDirection, cellContent) {
				return function (event) {
					new safariHover('over',cellElement, event, function(){
						new FloatingInfo(cellElement, {
							'float':'auto',
							'padding': 2,
							'floatDirection': floatDirection,
							'arrowClass':'float_arrow',
							'overlayClasses':
								{
								'top':'floatType_rss_top',
								'inner':'floatType_rss',
								'bottom':'floatType_rss_bottom'
								},
							'contentRender':  function(contentElement_){
											// this render function is called by the overlay
											renderOverlayRss(contentElement_, theHref);
										 }.bind(this)
						});
				
					});
				};
			}(myOverlay, floatType[2], theHref));

			Event.observe(myOverlay, "focus", function(cellElement, floatDirection, cellContent) {
				return function (event) {
					new safariHover('over',cellElement, event, function(){
						new FloatingInfo(cellElement, {
							'float':'auto',
							'padding': 2,
							'floatDirection': floatDirection,
							'arrowClass':'float_arrow',
							'overlayClasses':
								{
								'top':'floatType_rss_top',
								'inner':'floatType_rss',
								'bottom':'floatType_rss_bottom'
								},
							'contentRender':  function(contentElement_){
											// this render function is called by the overlay
											renderOverlayRss(contentElement_, theHref);
										 }.bind(this)
						});
				
					});
				};
			}(myOverlay, floatType[2], theHref));	
		});
	}

}, false);
	
/* Overlays bootstrap */
Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myOverlayVideo').map(function(myOverlay){

		var infoBody = myOverlay.getElementsBySelector("div")[0].innerHTML;
		var selectorCell = myOverlay.getElementsBySelector("a")[0];
		
		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");

		Event.observe(myOverlay, "mouseover", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': -7,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
				});
			};
		}(selectorCell, floatType[2], infoBody, floatType[3]));
         
		Event.observe(myOverlay, "focus", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': -7,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
				});
			};
		}(selectorCell, floatType[2], infoBody, floatType[3]));
	});
}, false);

Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myMyNASAAdd').map(function(myOverlay){

		var infoBody = $(myOverlay.parentNode).getElementsBySelector("div")[0].innerHTML;
		var selectorCell = myOverlay.getElementsBySelector("a")[0];
		
		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");

		Event.observe(selectorCell, "mouseover", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 4,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
			
				});
			};
		}(selectorCell, floatType[2], infoBody, floatType[3]));
        Event.observe(selectorCell, "focus", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 4,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
			
				});
			};
		}(selectorCell, floatType[2], infoBody, floatType[3])); 
	});
}, false);

Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myMyNASABookmarks').map(function(myOverlay){

		var infoBody = myOverlay.getElementsBySelector("span")[0].innerHTML;
		var selectorCell = myOverlay.getElementsBySelector("a")[0];
		
		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");

		Event.observe(myOverlay, "mouseover", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 0,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark myMyNASABookmarks_inner',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
				});
			};
		}(myOverlay, floatType[2], infoBody, floatType[3]));
		Event.observe(myOverlay, "focus", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 0,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark myMyNASABookmarks_inner',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': cellContent
					});
				});
			};
		}(myOverlay, floatType[2], infoBody, floatType[3]));
	});


}, false);


Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myOverlayBookmark').map(function(myOverlay){
		
		var theHref = myOverlay.href;
		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");

			
		function renderOverlayBookmarks(contentElement, theHref){
			contentElement.innerHTML = "";
			
			var space = document.createElement("br");
			var space1 = document.createElement("br");
			var space2 = document.createElement("br");
			
			
			var enImage = document.createElement("img");
			enImage.src = "images/uk.png";
			enImage.style.display = "inline";
			contentElement.appendChild(enImage);
			
			
			var enLink = document.createElement("a");
			enLink.style.color = "#FFFFFF";
			enLink.style.marginLeft = "10px";
			enLink.href = "en";
			enLink.innerHTML = "English";
			contentElement.appendChild(enLink);
			
			contentElement.appendChild(space);
			
			
			var geImage = document.createElement("img");
			geImage.src = "images/de.png";
			geImage.style.display = "inline";
			contentElement.appendChild(geImage);
			
			var geLink = document.createElement("a");
			geLink.style.color = "#FFFFFF";
			geLink.style.marginLeft = "10px";
			geLink.href = "de";
			geLink.innerHTML = "German";
			contentElement.appendChild(geLink);
			
			contentElement.appendChild(space1);
			
			
			var arImage = document.createElement("img");
			arImage.src = "images/sy.png";
			arImage.style.display = "inline";
			contentElement.appendChild(arImage);
			
			var arLink = document.createElement("a");
			arLink.style.color = "#FFFFFF";
			arLink.style.marginLeft = "10px";
			arLink.href = "ar";
			arLink.innerHTML = "Arabic";
			contentElement.appendChild(arLink);
			
			contentElement.appendChild(space2);
		}


		Event.observe(myOverlay, "mouseover", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 0,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': function(contentElement_){
											// this render function is called by the overlay
											renderOverlayBookmarks(contentElement_, theHref);
										 }.bind(this)
					});
				});
			};
		}(myOverlay, floatType[2], theHref, floatType[3]));
		Event.observe(myOverlay, "focus", function(cellElement, floatDirection, cellContent, widthClass) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 0,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_bookmark_top',
							'inner':'floatType_bookmark',
							'bottom':'floatType_bookmark_bottom'
							},
						'widthClass': widthClass,
						'contentRender': function(contentElement_){
											// this render function is called by the overlay
											renderOverlayBookmarks(contentElement_, theHref);
										 }.bind(this)
					});
				});
			};
		}(myOverlay, floatType[2], theHref, floatType[3]));
	});
}, false);

Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myOverlayHelp').map(function(myOverlay){
		var theHref = myOverlay.href;
		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");
		var theHelpContents = floatType[4];
		var helpContents = $H({
			'materials_filter_help': $H({
				'title': '<h5>Education Materials Filter</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n'
			 }),
			'popular_content_help': $H({
				'title': '<h5>Popular Content</h5>',
				'body': '<p>These words and phrases are the current most popular searches. The larger the font size, the more frequently the term was searched.</p>\n'
			 }),
			'teaching_materials_help': $H({
				'title': '<h5>Teaching Materials</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n'
			 }),
			'confirm_email_help': $H({
				'title': '',
				'body': '<p>A confirmation email message will be sent to this address asking you to verify your registration.</p>\n'
			 }),
			'comment_on_article_help': $H({
				'title': '<h5>Commenting</h5>',
				'body': '<p>Make your opinion known by adding your comments on this article so other users can read them. Choose any username you wish – your submission can be entirely anonymous.</p>\n'
			 }),
			'satellite_tracking_help': $H({
				'title': '<h5>Hubble Space Telescope</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n' +
				'<a href="">Details</a>\n'
			 }),
			'education_material_types_help': $H({
				'title': '<h5>Lithographs</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n' 
			 }),
			'missions_education_filter_help': $H({
				'title': '<h5>Missions Filter</h5>',
				'body': '<p>Use this filter to quickly narrow your search for NASA missions of interest to you.<br /> Click as many boxes as you wish. As you do, the number of materials will update, showing you the materials that match what you\'re looking for.<br /> Click View Results to see a list of all of the materials.</p>\n'
			 }),
			'nasa_calendar_help': $H({
				'title': '<h5>NASA Calendar</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n' 
			 }),
			'nasa_tv_video_help': $H({
				'title': '<h5>NASA TV &amp; Video</h5>',
				'body': '<p>NASA\'s Video Player is designed to detect your preferred media player and offer video in that format. Videos may play in Windows MediaPlayer, RealPlayer or QuickTime. You may not be able to view all videos in the player unless you have the proper plugins.</p>\n'
			 }),
			'add_panels_help': $H({
				'title': '<h5>Add Panels</h5>',
				'body': '<p>You can add any panel you want to your MyNASA page. Hover your mouse over a panel title to see the description. If you like what you see, hit Add and the panel will appear on the page. We\'ve added a couple for you to get you started.</p>\n'
			 }),
			'mynasa_bookmarks_help': $H({
				'title': '<h5>Bookmarks</h5>',
				'body': '<p>Add NASA site content that you want to read later by hitting the bookmark icon where you see it around the site.</p>\n'
			 }),
			'mynasa_playlists_help': $H({
				'title': '<h5>Playlists</h5>',
				'body': '<p>Add video and audio content that you want to hear later by hitting the bookmark icon where you see it around the site.</p>\n'
			 }),
			'lorem_ipsum_help': $H({
				'title': '<h5>Lorem Ipsum</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n'
			 })
		});
		
		var infoBody = helpContents[theHelpContents]['title'] + helpContents[theHelpContents]['body'];
		
		Event.observe(myOverlay, "mouseover", function(cellElement, floatDirection, cellContent) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 1,
						'floatDirection': floatDirection,
						'arrowClass': 'float_arrow',
						'overlayClasses':
							{
							'top': 'floatType_popular_top',
							'inner': 'floatType_popular',
							'bottom': 'floatType_popular_bottom'
							},
						'contentRender': cellContent
					});
				});
			};
		}(myOverlay, floatType[2], infoBody));
	});
}, false);

/*
document.observe('contentloaded', function() {
	var allOverlays = $$('.myOverlayLogin').map(function(myOverlay){
		var loginContents = $H({
			'login_error': $H({
				'title': '<h5>Error!</h5>',
				'body': '<p>Your name and password do not match our records. Please re-enter.</p>\n<p><a href="#" class="errorGetPassword">&rsaquo; Forgot Username<br />or Password?</a></p>'
			 }),
			'password_retrieval': $H({
				'title': '<h5>Password Retrieval</h5>',
				'body': '<p>Please enter your email address and we will send you an email with your Sign in information.</p>\n <form><p><input type="text" value="" name="" class="password_retrieval_box" /></p><p><input type="image" src="templateimages/redesign/modules/forms/small_grey_submit.gif" value="" name="submit" /></p></form>'
			 }),
			'password_retrieval_error': $H({
				'title': '<h5>Password Retrieval</h5>',
				'body': '<p>Please enter your email address and we will send you an email with your Sign in information.</p>\n <form><p><input type="text" value="" name="" class="password_retrieval_box" /></p><p><input type="image" src="templateimages/redesign/modules/forms/small_grey_submit.gif" value="" name="submit" /></p></form><p class="password_retrieval_error_msg">The email address you have entered is incorrect. Please try again</p>'
			 }),
			'registration_page_error': $H({
				'title': '',
				'body': '<p>The user name you selected is already taken.</p><p>Try something different.</p>\n'
			 })
		});

		var infoBody =  loginContents['login_error']['title'] + loginContents['login_error']['body'];

		_displayError = function(){
			new safariHover('over',myOverlay, "mouseover", function(){
				new FloatingInfo(myOverlay, {
					'float':'auto',
					'padding': 2,
					'floatDirection': 'bottom',
					'arrowClass':'float_arrow',
					'overlayClasses':
						{
						'top':'floatType_error_top',
						'inner':'floatType_error',
						'bottom':'floatType_error_bottom'
						},
					'contentRender': infoBody
				});
		
			});	
		};
		
		var url = 'temp-resources/scripts/login.php';

		Event.observe(myOverlay, "click", function(url) {
			return function (event) {
				var form = $('login_form');
				var formUserInput = form['user'];
				var formPassInput = form['pass'];
				var myRequest = new Ajax.Request( url, 
				{
					method:'post',
					postBody:'user=' + $('user').getValue() + '&pass=' + $('pass').getValue(),
					onSuccess:function(transport)
					{
						if(transport.responseText != 'error'){
							window.location = transport.responseText;
						}else{
							_displayError();
						}
					}
				});
				Event.stop(event);
				return false;
			};
			
			
		}(url));
	});
}, false);*/
	
Event.observe(window, 'load', function() {
	
	var allOverlays = $$('.myOverlayError').map(function(myOverlay){

		var classSplit = myOverlay.classNames().toString();
		var floatType = new Array();
		floatType = classSplit.split(" ");
		
		var theErrorContents = floatType[4];
		
		var errorContents = $H({
			'login_error': $H({
				'title': '<h5>Error!</h5>',
				'body': '<p>Your name and password do not match our records. Please re-enter.</p>\n<p><a href="#" class="errorGetPassword">&rsaquo; Forgot Username<br />or Password?</a></p>'
			 }),
			'general_error': $H({
				'title': '<h5>Error!</h5>',
				'body': '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>\n'
			 }),
			'incorrect_email_error': $H({
				'title': '<h5>Error!</h5>',
				'body': '<p>Sorry that email is not vaild.</p>\n'
			 }),
			'password_retrieval': $H({
				'title': '<h5>Password Retrieval</h5>',
				'body': '<p>Please enter your email address and we will send you an email with your Sign in information.</p>\n <form><p><input type="text" value="" name="" class="password_retrieval_box" /></p><p><input type="image" src="templateimages/redesign/modules/forms/small_grey_submit.gif" value="" name="submit" /></p></form>'
			 }),
			'password_retrieval_error': $H({
				'title': '<h5>Password Retrieval</h5>',
				'body': '<p>Please enter your email address and we will send you an email with your Sign in information.</p>\n <form><p><input type="text" value="" name="" class="password_retrieval_box" /></p><p><input type="image" src="templateimages/redesign/modules/forms/small_grey_submit.gif" value="" name="submit" /></p></form><p class="password_retrieval_error_msg">The email address you have entered is incorrect. Please try again</p>'
			 }),
			'registration_page_error': $H({
				'title': '',
				'body': '<p>The user name you selected is already taken.</p><p>Try something different.</p>\n'
			 })
		});

		var infoBody =  errorContents[theErrorContents]['title'] + errorContents[theErrorContents]['body'];

		Event.observe(myOverlay, "mousedown", function(cellElement, floatDirection, cellContent) {
			return function (event) {
				new safariHover('over',cellElement, event, function(){
					new FloatingInfo(cellElement, {
						'float':'auto',
						'padding': 2,
						'floatDirection': floatDirection,
						'arrowClass':'float_arrow',
						'overlayClasses':
							{
							'top':'floatType_error_top',
							'inner':'floatType_error',
							'bottom':'floatType_error_bottom'
							},
						'contentRender': cellContent
					});
				});
			};
		}(myOverlay, floatType[2], infoBody));
	});
}, false);

var mouseOverClassify = Class.create();
mouseOverClassify.prototype = { 
	initialize: function(options){
		//
		// Note: Positioning-based logic does not work for elements which are heavily z-indexed and overlapping (like StackedDeck)
		// in those cases, options must have ignore_position set to true
		//
		this.options = {};
		if(typeof(options)=='object' && options!=null){
			this.options = options;
		} else {
			this.options['ignore_position'] = false;
		}
		this.options['ignore_position'] = true;
	},
	classify: function(element, nameOfClass) {
		Event.observe(element, "mouseover",
			function(e){
				if(this.options['ignore_position']==true){
					if(typeof(this.options['adderFunction'])=='function'){
						this.options['adderFunction'](element);
					} else {
						element.addClassName(nameOfClass);
					}
				} else {
					var IsItIn = Position.within(element, Event.pointerX(e), Event.pointerY(e));
					if(IsItIn && !element.ItIsIn) {
						element.ItIsIn = true;
						if(typeof(this.options['adderFunction'])=='function'){
							this.options['adderFunction'](element);
						} else {
							element.addClassName(nameOfClass);
						}
					}
				}
				Event.stop(e);
			}.bind(this)
		);
		Event.observe(element, "mouseout",
			function(e){
				if(this.options['ignore_position']==true){
					if(typeof(this.options['removerFunction'])=='function'){
						this.options['removerFunction'](element);
					} else {
						element.removeClassName(nameOfClass);
					}
				} else {
					var IsItIn = Position.within(element, Event.pointerX(e), Event.pointerY(e));
					if(!IsItIn && element.ItIsIn) {
						element.ItIsIn = false;
						if(typeof(this.options['removerFunction'])=='function'){
							this.options['removerFunction'](element);
						} else {
							element.removeClassName(nameOfClass);
						}
					}
				}
				Event.stop(e);
			}.bind(this)
		);
	}
};


/* scan for generic selects to skin */
Event.observe(window, 'load', function() {
	
	if ($$('.select_dropdown')[0]) {
		var allDropDowns = $$('.select_dropdown').map(function(elm){
			if (detectBrowser.whichBrowser() != 'ie') {
				var classSplit = elm.parentNode.classNames().toString();
				var classType = new Array();
				classType = classSplit.split(" ");

				return new SkinnedSelect(elm.parentNode, elm, function(){
					window.location.href = elm.value;
				}, '', classType[0]);
			}
			else {
				elm.removeClassName('select_dropdown');
				elm.removeClassName('hide');
				elm.addClassName('select_dropdown_ie');
				Event.observe(elm, "change", function(e){
					window.location.href = elm.value;
					Event.stop(e);
				});
			}
		});
	}
}, false);

/* text size adjuster 
document.observe ('contentloaded', function(){
	// find each text adjuster, find its adjustee (thing to be adjusted in size), and 
	// listen for clicks and adjust size appropriately.

	$$('.text_adjust').each(function(adjuster){
		var adjustee = adjuster.up().getElementsBySelector('.text_adjust_me')[0];
		if(adjustee){
			var inTheMiddle = true;
			var inTheMax = false;
			var inTheMin = false;
			var adjustBox = adjuster;
			var boxToAdjust = adjustee;
			var growButton = adjustBox.getElementsByClassName('icon_plus')[0];
			var shrinkButton = adjustBox.getElementsByClassName('icon_minus')[0];

			Event.observe (growButton, 'click', function(ev) {
				if(inTheMiddle == true) {
					boxToAdjust.addClassName('article_grow');
					growButton.addClassName('icon_plus_inactive');
					inTheMiddle = false;
					inTheMax = true;
				} else 
				if(inTheMin == true) {
					boxToAdjust.removeClassName('article_shrink');
					shrinkButton.removeClassName('icon_minus_inactive');
					inTheMiddle = true;
					inTheMin = false;
				}
				ev.stop();
				return false;
			}, false);
			Event.observe (shrinkButton, 'click', function(ev) {
				if(inTheMiddle == true) {
					boxToAdjust.addClassName('article_shrink');
					shrinkButton.addClassName('icon_minus_inactive');
					inTheMiddle = false;
					inTheMin = true;
				} else 
				if(inTheMax == true) {
					boxToAdjust.removeClassName('article_grow');
					growButton.removeClassName('icon_plus_inactive');
					inTheMiddle = true;
					inTheMax = false;
				}
				ev.stop();
				return false;
			}, false);			
		}
	});

});*/

/* text size adjuster */
var inTheMiddle = true;
var inTheMax = false;
var inTheMin = false;

function textSizeAdjuster(click){
  // find each text adjuster, find its adjustee (thing to be adjusted in size), and
  // listen for clicks and adjust size appropriately.
  $$('.text_adjust').each(function(adjuster){
    var adjustee = adjuster.up().getElementsBySelector('.text_adjust_me')[0];
    if(adjustee){
      var adjustBox = adjuster;
      var boxToAdjust = adjustee;
      var growButton = adjustBox.getElementsByClassName('icon_plus')[0];
      var shrinkButton = adjustBox.getElementsByClassName('icon_minus')[0];
      if(click == 'grow') {
        if(inTheMiddle == true) {
          boxToAdjust.addClassName('article_grow');
          growButton.addClassName('icon_plus_inactive');
          inTheMiddle = false;
          inTheMax = true;
        } else
        if(inTheMin == true) {
          boxToAdjust.removeClassName('article_shrink');
          shrinkButton.removeClassName('icon_minus_inactive');
          inTheMiddle = true;
          inTheMin = false;
        }
      }
      if (click == 'shrink') {
        if(inTheMiddle == true) {
          boxToAdjust.addClassName('article_shrink');
          shrinkButton.addClassName('icon_minus_inactive');
          inTheMiddle = false;
          inTheMin = true;
        } else
        if(inTheMax == true) {
          boxToAdjust.removeClassName('article_grow');
          growButton.removeClassName('icon_plus_inactive');
          inTheMiddle = true;
          inTheMax = false;
        }
      }
    }
  });
}


/*

	Filters with counters:
	
	Note1: this code looks for elements with class .filterset and creates numeric filters out of them
	Note2: the entire thing should be inside of an element .filter_container if you don't want the code 
	       to confuse various co-existing counters on the same page. Make sure to encapsulate filters 
	       this way or just use counters every time.
	Note3: A visual counter resides inside of an element .totalweight which should either be a descendent 
	       of .filterset or should be a nearby sibling or 'cousin' node. In either case, they should both 
	       share a common .filter_container ancestor in order not to confuse co-existing counters on the 
	       same page.

*/
document.observe("contentloaded",function(){
	$$('.filterset').each(function(filterSetContainer){
		var setNumOnce = false;
		var found = false;
		var p = filterSetContainer;
		while(found==false){
			counterElement = p.getElementsBySelector(".totalweight")[0];
			if(p.hasClassName("filter_container") || p.nodeName=='BODY' || p.nodeName=='body'){
				// we've gone too far up the ancestry chain and there is no visual counter associated with this filter.
				counterElement = null;
				found = true;
			} else if(counterElement && counterElement.hasClassName('totalweight')){
				found = true;
			} else {
				p = p.up();
			}
			// if we've found element.totalweight, we'll be exiting here, else we move up the ancestry chain
		}
		if(counterElement){
			var pc = new PrettyCounter(counterElement,4,0,true);
			var educators_filter = new SetFilter(filterSetContainer,function(updateText){
				pc.setNum(parseInt(updateText),!setNumOnce);
				setNumOnce = true;
			},true);
		}
	});
});

// detect any scrollbars
document.observe("contentloaded",function(){
	var sFactory = new ScrollFactory();
});

/* Search results dropdown */
Event.observe(window, 'load', function() {
	if($$('select.browse_relevance').length > 0){
		var dds = new SkinnedSelect($$('select.browse_relevance')[0].parentNode,$$('select.browse_relevance')[0], function(){
			if($$('select.browse_relevance')[0].value != 0) {
				document.location.href = "search_results.html@sort=" + $$('select.browse_relevance')[0].value;
			}
		},'','white');
	}
}, false);

/*
Event.observe(window, 'load', function() {
 var faqpage = $$('.hideanswer');
 if(faqpage != null){
     showfaq('1');
    }
},false);
*/

Event.observe(window, 'load', function() {
 var nasalogo = $$('.nasa_logo');
 if(nasalogo != null){
        if(nasalogo[0] != null && nasalogo[0].readAttribute('href') != null) {
            nasalogo[0].writeAttribute("href","home/index.html"); 
        } 
    }
},false);


}
