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 = "";
		    
			if($('url')){
				theHref = $('url').value;
			}

			function addBookPop(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();";
			}
		
			if($('titleUrl')){
				var bookmarkTitle = $('titleUrl').value;
			}
			//var bookmarkTitle = document.title;
			if($('documentId')){
				var documentId = $('documentId').value;
			}
			var mynasaUrl	=	"http://mynasa.nasa.gov/portal/bookmarks/BookmarkServlet?bookmark_title="+encodeURI(bookmarkTitle)+"&bookmark_url="+encodeURI(theHref)+
				                "&bookmark_label="+documentId;
			
			var title = new Element('h5',{});
			title.update('Bookmark this');
			
			var description = new Element('p',{});
			description.update('Select a bookmarking site.');
			
			var nasaLink = new Element('a',{'className':'rss_mynasa', 'href':mynasaUrl});
			nasaLink.update('MyNASA');
			
			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 links = [
				{className:'bookmark_digg', 'title':'Digg It'},
				{className:'bookmark_delicious', 'title':'del.icio.us'},
				{className:'bookmark_stumble', 'title':'StumbleUpon'},
				{className:'bookmark_technorati', 'title':'Technorati'},
				{className:'bookmark_yahoo', 'title':'Yahoo'}
			];
			var list = new Element('ul');
			for(var i=0;i<links.length;i++){
				list.insert(makeListLink(links[i]['title'],links[i]['className'],links[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);
			
			list = $(list);
						
			var bookDigg = list.getElementsBySelector('.bookmark_digg')[0];
			var bookDiggURL = 'http://digg.com/submit?phase=2&title=' + encodeURI(bookmarkTitle) + '&url=' + encodeURI(theHref);
			
			Event.observe(bookDigg, "click", function(e) {
				addBookPop(960, 450, bookDiggURL);
				Event.stop(e);
			});		

			var bookDelicious = list.getElementsBySelector('.bookmark_delicious')[0];
			var bookDeliciousURL = 'http://del.icio.us/post?t&v=4&noui&jump=close&title='+ encodeURI(bookmarkTitle) +'&url='+ theHref;
			
			Event.observe(bookDelicious, "click", function(e) {
				addBookPop(750, 450, bookDeliciousURL);
				Event.stop(e);
			});
			
			var bookStumble = list.getElementsBySelector('.bookmark_stumble')[0];
			var bookStumbleURL = 'http://www.stumbleupon.com/submit?title='+ encodeURI(bookmarkTitle) +'&url='+ theHref;
			
			Event.observe(bookStumble, "click", function(e) {
				addBookPop(750, 450, bookStumbleURL);
				Event.stop(e);
			});

			var bookTechnorati = list.getElementsBySelector('.bookmark_technorati')[0];
			var bookTechnoratiURL = 'http://technorati.com/faves?add='+ theHref;
			
			Event.observe(bookTechnorati, "click", function(e) {
				addBookPop(980, 460, bookTechnoratiURL);
				Event.stop(e);
			});
			
			var bookYahoo = list.getElementsBySelector('.bookmark_yahoo')[0];
			var bookYahooURL = 'http://bookmarks.yahoo.com/toolbar/savebm?t='+ encodeURI(bookmarkTitle) +'&u='+ theHref;
			
			Event.observe(bookYahoo, "click", function(e) {
				addBookPop(750, 450, bookYahooURL);
				Event.stop(e);
			});	

			contentElement.appendChild(title);
			contentElement.appendChild(description);
			contentElement.appendChild(nasaLink);
			contentElement.appendChild(list);
			contentElement.appendChild(br);
			contentElement.appendChild(footer);
			contentElement.appendChild(textArea);
			
		}


		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);
