// application.js

/*global Element, $$, $ */
/*global console, window, document */

/*jslint white: false, eqeqeq: false */


function replaceAllCss( o, css ) {
	// ie way:
	if ( o.styleSheet ) {
		o.styleSheet.cssText = css;
	} else {
		// mozilla & opera way
		o.textContent = css;
	}
}
function consoler( text ) {
	if (window.console) {
		if (console.log) {
			console.log( text );
		}
	}
}

function enable_stylesheet( id ) {
	$$('link.interchangeable').each( function( link ) {
		if ( link.id == id  ) {
			link.disabled = ''; // stylesheet will show
			//alert(link.id + 'made true');
		} else {
			link.disabled = 'true'; // stylesheet will not show
		}
	});
}
function initCustomElementMethods() {
	var ownMethods = {
		refactor : function(element, sNode) {
			var newNode = new Element(sNode);
			newNode.className = element.className;
			newNode.update( element.innerHTML );
			$(element).replace( newNode );
			return newNode;
		},
		copyClassAndId : function(element, source) {
			if (source.id) {
				element.id = source.id;
			}
			if (source.className) {
				element.className = source.className;
			}
			return element;
		}
	}; 
	Element.addMethods(ownMethods);
}
// from http://gist.github.com/6618 :
(function() {
  
  function getText(element, shallow) {
    return $(element).textNodes(shallow)
     .inject('', function(text, node) { return node.nodeValue });
  }
 
  function setText(element, text) {
    element = $(element);
    var nodes = Element.textNodes(element);
    if (nodes.length) {
      nodes.shift().nodeValue = text;
      nodes._each(Element.remove);
    }
    else Element.insert(element, text);
    return element;
  }
  
  if ('innerText' in document.documentElement) {
    var __method = getText;
    getText = function(element, shallow) {
      return shallow ? __method(element, true) : $(element).innerText;
    };
  }
  
  Element.addMethods({
    getText: getText,
    setText: setText,
    textNodes: function(element, shallow) {  
      var results = [], node = $(element).firstChild;
      while (node) {
        if (node.nodeType === 3)
          results.push(node);
        else if (!shallow && node.hasChildNodes())
          results = results.concat(arguments.callee(node));
        node = node.nextSibling;
      }
      return results;
    }
  })
})();
function ietable(tableLike) {
	var d = document;
	var table = d.createElement('table');
	$(table).copyClassAndId( tableLike ).removeClassName('make-table');
	$(tableLike).select('.make-caption').each( function(captionLike) {
		var newCaption = table.createCaption();
		newCaption.innerHTML = captionLike.innerHTML;
		$(newCaption).copyClassAndId( captionLike ).removeClassName('make-caption');
	});
	$(tableLike).select('.make-tbody').each( function(tbodyLike) {
		var tbody = table.appendChild( d.createElement('tbody') );
		$(tbody).copyClassAndId(tbodyLike).removeClassName('make-tbody');
		tbodyLike.select('.make-tr').each( function(trLike) {
			var tr = $(tbody.insertRow(-1)).copyClassAndId(trLike).removeClassName('make-tr');
			$(trLike).select('.make-td').each( function(tdLike) {
				$(tr.insertCell(-1)).copyClassAndId(tdLike).removeClassName('make-td').update( tdLike.innerHTML );
			});
		});
	});
	$(tableLike).replace(table);
}
function makeManualTableElements() {
	$$('#container-three').invoke( 'addClassName', 'make-table');
	//$$('.ny-type').invoke( 'addClassName', 'make-caption');
	$$('#container-four').invoke( 'addClassName', 'make-tbody');
	$$('#container-five').invoke( 'addClassName', 'make-tr' ); $$('.page-content', '.section-b', '.section-a').invoke( 'addClassName', 'make-td' ); }

function makeTranslationMenu() {
	var c = YAHOO.util.Cookie;
	var cookieOptions = {
		path : '/', // all sub paths
		domain: 'northwestern.edu',
		expires: new Date("January 12, 2025"),
		secure: false // don't want only over SSL
	};
	var curLang = c.get( 'glang' );
	var hLangs = $H( google.language.Languages );
	var l = new Element( 'label', { 'for': 'langSelect' } ).update( 'Language:' );
	var s = new Element( 'select', { id: 'langSelect' } );
	hLangs.each( function(p,i) {
		if ( p.value && google.language.isTranslatable( p.value )) {
			var o = new Element( 'option', { value: p.value } ).update( p.key.gsub('_',' ').capitalize() );
			if ( curLang == p.value ) {
				o.selected = true;
			}
			s.insert({ bottom: o  });
		}
	});
	var p = new Element( 'div' ).update( s );
	var en = new Element( 'a', { href: '#', id: 'readInEng' } ).update( new Element( 'span' ).update('English Version' ));
	if ( curLang == null || curLang == 'en' ) {
		en.style.display = 'none';
	}
	$( 'gtranslate' ).update( en );
	$( 'gtranslate' ).insert({ bottom: l } ).insert({ bottom: p });
	$( 'gtranslate' ).insert({ bottom: new Element( 'div', { id: 'gbranding' }) });

	var loadLang = function(lang) {
		c.set( 'glang', lang , cookieOptions );
		location.reload();
	};
	$( 'langSelect' ).observe( 'change', function(e) {
		var sel;
		$$( '#langSelect option' ).each( function(o) {
			if ( o.selected ) {
				sel = o;
			}
		});
		loadLang( sel.value );
	});
	$( 'readInEng' ).addClassName( 'do-not-translate' ); // ie8 made me add this when actually in DOM
	$( 'readInEng' ).observe( 'click', function(e) {
		e.stop();
		loadLang( 'en' );
	});
	google.language.getBranding( 'gbranding' );
	$$( '.gBrandingText' ).invoke( 'addClassName', 'do-not-translate' );
	
}
function googleLanguageLoaded() {
	if ($( 'gtranslate' )) {
			makeTranslationMenu();
	}
	$$( 'body' )[0].cleanWhitespace();
	var lang = YAHOO.util.Cookie.get( 'glang' );
	if ( lang != 'en' && lang != null ) {
		var nodes = $$( 'body' )[0].textNodes();
		nodes.each( function(o) {
			if (!( $(o.parentNode).up( '.do-not-translate' ) || $(o.parentNode).hasClassName('do-not-translate' ))) {
				var s = o.nodeValue;
				var b = /^\s/.test(s)?' ':'';
				var e = /\s$/.test(s)?' ':'';
				google.language.translate( s, 'en', lang, function(t) {
					if (!t.error) {
						var t = t.translation.unescapeHTML();
						var t = t.gsub( '&quot;', '"' );
						var t = t.gsub( '&#39;' , "'" );
						if ( o.parentNode.nodeName == "OPTION" ) {
							o.parentNode.text = b+t+e;
						} else {
							o.nodeValue = b+t+e;
						}


					}
				});
			}
		});
	}
}
function tweetsLoaded( tweets ) {
	consoler( 'saferide tweets loaded' );
	var n = $('bigGauge');
	if ( n ) {
		n.style.width = '300px';
		n.style.position = 'relative';
		n.style.height = '300px';
		n.style.margin = 'auto';
		n.style.display = 'block';
		var options = {
		    max: 120,
		    width: 300,
		    minorTicks: 2,
		    majorTicks: ['0','10','20','30','40','50','60','70','80','90','100','110','120'],
		    greenFrom: 0,
		    greenTo: 45,
		    yellowFrom: 45,
		    yellowTo: 90,
		    redFrom: 90,
		    redTo: 120
		};
		var v = google.visualization;
		var d = new v.DataTable();
		d.addColumn( 'string' , 'Label' );
		d.addColumn( 'number' , 'Value' );
		d.addRows( 1 );
		d.setValue( 0, 0, 'Mins' );
		d.setValue( 0, 1, 40 );
		g = new v.Gauge( n );
		setGauge = function( x ) {
			d.setValue( 0,1,x);
			g.draw( d, options );
		};
		setGauge( 60 );
		tweet2gauge = function( x ) {
			var text = tweets[x].text;
			var mins = text.match( /(\d+)/ )[0];
			if ( mins ) {
				setGauge( mins*1 );
			}
		}
		tweet2gauge( 1 );
	}
}
function googleLibsLoaded() {
	consoler( 'googlelibsloaded' );
	var h = $$( 'head' )[0];
	if ( SERVER.page_title.include('wait')) {
		var s = new Element( 'script', 
			{ type: 'text/javascript',
			  id:   'twitter',
			  src:  'http://twitter.com/statuses/user_timeline/37356824.json?callback=tweetsLoaded'
		});
		h.insert({ bottom: s });
	}
}
function googleMapsLoaded() {
	consoler( 'googlemapsloaded' );
	var m = google.maps;
	n = $('gMap');
	if (n) {
		var c = new m.LatLng( 42.045552,-87.683516 );
		var mm = new m.Map2( n );
		mm.setCenter( c, 14 ); 
		mm.setUIToDefault();
		mm.setMapType( G_NORMAL_MAP );
		//var mark = new GMarker( c );
		//mm.addOverlay( mark );
		//var h = new Element( 'p' ).insert( 'hey there!' );
		//mm.openInfoWindow( c, h );
		var options = {
			geodesic: false
		};
		var p = new GPolyline([
			new GLatLng(42.06406 ,-87.676976 ),
			new GLatLng(42.064255 ,-87.698627 ),
			new GLatLng(42.058759 ,-87.694041 ),
			new GLatLng(42.053848,-87.69411),
			new GLatLng(42.053928,-87.692844),
			new GLatLng(42.052103,-87.692764),
			new GLatLng(42.052072,-87.69337),
			new GLatLng(42.04109,-87.693558 ), 
			new GLatLng(42.041122,-87.694459 ), 
			new GLatLng(42.040039,-87.69433 ), 
			new GLatLng(42.040134,-87.693472 ), 
			new GLatLng(42.038668,-87.693515 ), 
			new GLatLng(42.038636,-87.694416 ), 
			new GLatLng(42.037553,-87.694373 ), 
			new GLatLng(42.037489,-87.692914 ), 
			new GLatLng(42.033919,-87.693043 ), 
			new GLatLng(42.033919,-87.692227 ), 
			new GLatLng(42.026396,-87.69227 ), 
			new GLatLng(42.026364,-87.678709 ), 
			new GLatLng(42.027097,-87.678666 ), 
			new GLatLng(42.02697,-87.668109 ) 
			], '#ff0000', 10, .6, options
		);
		mm.addOverlay( p );

	}
}
function googleLoaderLoaded() {
	if ( true ) {
		google.load( 'language', '1', {
			'callback': googleLanguageLoaded
		});
	}
	google.load( 'visualization', '1', {
		packages: ['gauge', 'orgchart'],
		'callback': googleLibsLoaded 
	});
	google.load( 'maps', '2', {
		'other_params': 'sensor=false',
		'callback': googleMapsLoaded
	});
}
/* window load events ========================================================== */
// don't put the window load handler inside the dom loader functions
Event.observe( window, 'load', function(e) {

	// get google loader
	var h = $$( 'head' )[0];
	var key = 'ABQIAAAA-fbNd4KfkL4CM0_U22ClXhRE8b0A_bNKcx6XlU5gyTSxMjBCbxTL4hpxApw703ZYdxOEwUuMorSZyA'; //dev.dosa
	if ( location.hostname == 'www.northwestern.edu' ) {
		key='ABQIAAAA-fbNd4KfkL4CM0_U22ClXhT5NS0vbwHjW_iUsam6CTE6fIqBpxQmUeIeNi2Y9RWkFDbKKgjbTL-QQw';
	}
	if ( location.hostname == 'test.dosa.northwestern.edu' ) {
		key='ABQIAAAA-fbNd4KfkL4CM0_U22ClXhTmPt0-XUS-QVAR9xI-cWgj-q4zRhS8ZSBLC5Q0iu6MplXHqS_aYblkxQ';
	}
	var cb = "&callback=googleLoaderLoaded";
	if (!location.href.include( 'SelfService' )) {
		var s = new Element( 'script', 
			{ type: 'text/javascript',
			  id:   'google-loader',
			  src:  'http://www.google.com/jsapi?key='+key+cb
		});
		h.insert({ bottom: s });
	}

	// animating sitemap
	if ( !SERVER.user_login && false) { // animate only if user not logged in, disable totally for now
		var original = "3em"; // get this dynamically, see related in dom load handler 
		setTimeout( function() {
			$$( '.page-content .sitemap ul' ).each( function(o) {
				    var anim = new Effect.Morph( o, {
					style: {
					    marginLeft: original
					},
					duration: 1.7,
					transition: Effect.Transitions.sinoidal
				    }); 
			});
		}, 500 );
	}
	// fun with breadcrumbs:
	if ( window.browserIsIELessThan8 ) {
		$$('.breadcrumbs .arrow').each( function(o) {
			o.insert( '&nbsp;&gt;&nbsp;' );
		});
	}
	// start after 4/10 sec after window load:
	var initialDelay = 0.4 * 1000;
	setTimeout( function() {
		$$( '.breadcrumbs a' ).each( function(o, i) {
		    // each <a> initially will have no underline:
		    o.setStyle({ textDecoration: 'none' });
		    // each affect start half second before last effect:
		    // delay the start of each delay based on iteration var i:
		    var eachDelay = i * 0.5;
		    setTimeout( function() {
			    o.style.textDecoration = 'underline';
		    }, eachDelay * 1000 );
		});
	}, initialDelay );

	//fix some text replacement stuff, backgrounds, for accessibility
	$$( '.university-name span' ).each( function(o) {
		var no = o.cloneNode( false ); // do NOT get contents underneath, too
		// FIX var bi = $( o.parentNode ).getStyle( 'background-image' );
		//console.log( bi  );
		var bi = 'url(/disability/styles/new-design/images/nu_seal_sprite.png)';
		o.insert( { bottom: no } );
		no.style.backgroundImage = bi;
		no.style.backgroundColor = 'transparent';
		no.style.top = '0';
		no.style.left = '0';
		no.style.position = 'absolute';
		no.update( '&nbsp;' );
	});

	// load google analytics
	if ( location.hostname == 'www.northwestern.edu' ) {
		if ( _gat ) {
			try{
			    var pageTracker = _gat._getTracker( SERVER.ga_tracking_code );
			    pageTracker._trackPageview();
			} catch(err) {}
		}
	}
	e.stop();

	// check if on the editing domain:
	if ( ( location.href.include( 'bokug' ) ) || (location.href.include( 'dev' ) ) || (location.href.include( 'localhost' ) )  ) {
		// add top edit control panel
		$('control-panel').style.display = 'inline';
		$$( '.wp-button' ).each( function(o) {
			o.setStyle({ display: 'inline' });
		});
		// add edit buttons for the inner-boxes
		$$('.edit-container.logged-in-true').each( function(inner_container) {
			var post_id = "";
			if ( inner_container.className.match(/post-id-(\d+)/) ) {
				var post_id = inner_container.className.match(/post-id-(\d+)/)[1];
				var href = "wp-admin/page.php?&action=edit&post=" + post_id;
				inner_container.insert('<span class="wp-button edit-inner-box"><a href="'+href+'">Edit</a></span>');
			}
		});
	}
	// add accesskeys
	$$('.edit-post-link a').invoke( 'writeAttribute', { accesskey: "e" } );
	$$('.wp-loginout a'   ).invoke( 'writeAttribute', { accesskey: "o" } );
	$$('.dashboard-link a').invoke( 'writeAttribute', { accesskey: "d" } );
	$$('.email-sa-help a' ).invoke( 'writeAttribute', { accesskey: "m" } );

	if ( $$('.email-sa-help a')[0] ) {
		// we don't want the query string in location.href:
		var currentLocation = location.protocol + "//" + location.hostname + location.pathname; 
		$$('.email-sa-help a')[0].observe( 'click', function(e) {
			Modalbox.show( 'libs/modalform.php', {
				title: 'Send an email to sa-help',
				autoFocusing: false, // ie doesn't like
				overlayClose: false,
				afterLoad: function() {
					$('mb-to').value =
					'cewalker@northwestern.edu';
					if (SERVER.user_email ) {
						$('mb-from').value =
						SERVER.user_email;
					}
					$$('#mb-form textarea')[0].value =
					currentLocation +'\n\nPlease clarify any'+
					' other issues here:\n\n';
					$('mb-cancel').observe( 'click', function(e) {
						Event.stop( e ); 
						$('MB_content').highlight({
							startcolor: '#ff0000',
							duration: 0.8,
							afterFinish: function() {
								Modalbox.hide();
							}
						});
					});
					$( 'mb-submit' ).observe( 'click', function(e) {
						$( 'mb-form' ).request({
							method: 'post',
							onComplete: function(r) {
								Modalbox.show( r.responseText, {
									afterLoad: function() {
										$( 'mb-done' ).observe( 'click',
										function(e) {
											Modalbox.hide();
										});
									}
								});
							}
						});
						e.stop();
					});
				}
			});
			Event.stop( e );
		});
	}
});
/* dom load events ============================================================== */
document.observe('dom:loaded', function(e) {
	if ( SERVER.blogurl == '/orientation' ) {
		var o = $$('.page-content .content')[0];
		o.addClassName( 'orientation-logo' );
	}
	// do not display legal information for katie's blog
	if ( SERVER.blogurl == '/katie' ) {
		$$( '.legal-info' )[0].style.display = 'none';
	}

	var lv = YAHOO.util.Cookie.getSubs( 'lv' );
	if ( lv ) {
		var h = $H( lv );
		// global
		window.schemeIndex = 0;
		var ds = $( 'default-style' ).content;
		var url = SERVER.blogurl + '/styles/' + ds + '/low-vision.css';
		var a = new Ajax.Request( url, {
			method: 'post',
			onSuccess: function(r) {
				// global:
				lowVisionCss = r.responseText;
				var style = new Element( 'style', { type: 'text/css', id: 'lowvision' } );
				$$( 'head' )[0].insert({ bottom: style });
				var css = lowVisionCss;
				h.each( function(p) {
					css = css.gsub( p.key, p.value );
				});
				// global
				window.schemeIndex = 0;
				lowVisionEnabled = true;
				setTimeout( function() {
					var styleNode = $( 'lowvision' );
					replaceAllCss( styleNode , css );
				}, 1 );
			}
		});
	}
	// get object query params, and turn boolean strings to native booleans	
	// ones using: iphone (boolean), 
	var queryParamsHash = $H( window.location.search.toQueryParams() );
	queryParamsHash.each( function(pair) {
		if (pair.value === "false") {
			queryParamsHash.set( pair.key, false ); 
		}
		if (pair.value === "true") {
			queryParamsHash.set( pair.key, true ); 
		}
	});
	queryParams = queryParamsHash.toObject(); // global for now, doesn't have to be
	
	if ( queryParams.javascript === false ) {
		return;
	}

	initCustomElementMethods();
	var is_iPhone = (navigator.userAgent.indexOf( 'iPhone') > -1);
	

	if (window.browserIsIELessThan8) {
		makeManualTableElements();
		$$('.make-table').each( function(tableLike) {
			ietable(tableLike);
		});
	}

	// fix ie6 some CSS selector parts ( '+' not supported, etc. ):
	if ( true || window.browserIsIELessThan7 ) {
		// allows for first side box on left to be styled:
		$$('.section-a div + div').each( function(o) {
			o.addClassName( 'notfirst' );
		});
		// helps puts address on the left side of footer:
		$$('.section-c h2 + h3').each( function(o) {
			o.addClassName( 'h2before' );
		});
		$$('.section-c h2 + h3 + ul').each( function(o) {
			o.addClassName( 'h3beforeh2before' );
		});
	}

	// centering icons like on gogreek
	// (IE<8 doesn't apply inline-block to block elements)
	if ( window.browserIsIELessThan8 ) {
		$$('.centered-inline-blocks .wp-caption').each( function(o) {
			var t= o.outerHTML.replace(/([/<])div([ >])/ig, "$1span$2");
			o.outerHTML = t;
		});
	}


	// add ARIA roles based on classnames "role-..."
	// do it this way so XHTML will still validate
	$$('[class*="role-"]').each( function( node ) {
		var roleName = node.className.match( /.*role-(.+)/ )[1];
		node.writeAttribute( "role", roleName );
	});

	// fix Mozilla no border on <object>
	if (Prototype.Browser.Gecko) {
		$$('object').each( function(o) {
			    w = o.width;
			    h = o.height;
			    r = o.wrap('div', {className: 'moz-border'});
			    r.style.width =  w+'px';
			    r.style.height = h+'px';

		});
	}

	// add focus to img links inside caption
	$$( 'a' ).each( function(o) {
		if ( o.up( '.wp-caption', 0 ) ) {
			//change title
			if ( o.down( 'img', 0 ) ) {
				o.down( 'img' , 0 ).title = '';
			}
			var div = o.up( '.wp-caption', 0 );
			o.observe( 'focus', function(e) {
				div.addClassName( 'focus' );
			});
			o.observe( 'blur', function(e) {
				div.removeClassName( 'focus' );
			});
		}
	});

	//fix ie form elements, fix with css
	// background bleeding outside fieldset
	if ( window.browserIsIE ) {
		$$( 'legend', 'fieldset' ).each( function(o) {
			o.addClassName( 'ie' );
		});
	}

	// fix that IE less than 8 doesn't support CSS :focus
	// actually make this apply to all
	if ( window.browserIsIELessThan8 || true) {
		$$('a', 'input', 'textarea', 'select' ).each( function(node) {
			node.observe( 'focus' , function(e) {
				node.addClassName( 'focus' );
				if ( node.id ) {
					$$( '*[for='+node.id+']' ).each( function(f) {
						f.addClassName( 'focus' );
					});
				}
			});
			node.observe( 'blur' , function(e) {
				node.removeClassName( 'focus' );
				if ( node.id ) {
					$$( '*[for='+node.id+']' ).each( function(f) {
						f.removeClassName( 'focus' );
					});
				}
			});
		});
	}


	if ( window.browserIsIELessThan7 ) {
		$$( '.header-montage a' ).each( function(o) {
			o.observe( 'mouseover', function(e) {
				o.addClassName( 'hover' );
				e.stop();
			});
			o.observe( 'mouseout',  function(e) {
				o.removeClassName( 'hover' );
				e.stop();
			});
		});
		$$( 'input' ).each( function(o) {
			if ( o.type ) {
				o.addClassName( o.type );
			}
		});
	}

	// CSS on fieldset focused legends 
	$$( 'select', 'input', 'textarea' ).each( function(o) {
		o.observe( 'focus', function(e) {
			var fs = o.up( 'fieldset' );
			if ( fs ) {
				var label = fs.down( 'legend' );
				if ( label ) {
					label.addClassName( 'focus' );
				}
			}
		});
		o.observe( 'blur', function(e) {
			var fs = o.up( 'fieldset' );
			if ( fs ) {
				var label = fs.down( 'legend' );
				if ( label ) {
					label.removeClassName( 'focus' );
				}
			}
		});
	});

	$$( '.page-content li input[type="checkbox"] + label' ).each( function(o) {
		o.addClassName( 'inputPLUScheckbox' );
		var li = o.up( 'li' );
		var input = o.previous( 'input' );
		input.observe( 'focus', function(e) {
			li.addClassName( 'focus' );
		});
		input.observe( 'blur', function(e) {
			li.removeClassName( 'focus' );
		});
	});
	$$( '.page-content li input[type="radio"] + label' ).each( function(o) {
		o.addClassName( 'inputPLUSradio' );
		var li = o.up( 'li' );
		var input = o.previous( 'input' );
		input.observe( 'focus', function(e) {
			li.addClassName( 'focus' );
		});
		input.observe( 'blur', function(e) {
			li.removeClassName( 'focus' );
		});
	});


	// fix so no :focus border on <a> with image inside
	$$('div.wp-caption > a > img', 'p > a > img').each( function( img ) {
		$(img.parentNode).addClassName( 'no-focus-outline');
	});

	// *******************************************************************************

	// fun with sitemap page
	if ( !SERVER.user_login ) { // animate only if user not logged in
		var ul = $$( '.page-content .sitemap' )[0];
		if (ul) {
			var original = $$('.page-content .sitemap ul')[0].getStyle(
			    'marginLeft'
			);
			$$('.page-content .sitemap ul').each( function(o) {
			    o.setStyle({
				marginLeft: '0em'
			    });
			});
			Event.observe(window, 'load', function(e) {
			    $$('.page-content .sitemap ul').each( function(o) {
				    new Effect.Morph( o, {
					style: {
					    marginLeft: original
					},
					duration: 1.7,
					delay: 0.3,
					transition: Effect.Transitions.sinoidal
				    }); 
			    });
			});
		}
	}

	// reveal FAQ animation:
	if ( $$('.page-title')[0].innerHTML.include('FAQ') ||
	     $$('.page-title')[0].innerHTML.include('Common Academic')  ||
	     $$('.page-title')[0].innerHTML.include('Frequently Asked Questions')  ||
	     $$('.page-title')[0].innerHTML.include('delme') ) {
		$$( '.content dt' ).each( function(o) {
			o.addClassName( 'revealer' );
			var duration = 0.3;
			var s = o.next( 'dd' );
			s.style.display  = 'none';
			o.observe( 'click', function(e) {
				o.down( 'a' ).toggleClassName( 'showing' );
				new Effect.toggle( s, 'appear', {
					duration: duration
				});
				e.stop();
			});
		});
	}

	$$( '.header-montage img' ).each( function(o) {
		var span = new Element( 'span' );
		span.style.height = '150px';
		span.style.width = '150px';
		span.className = 'container';
		var d2 = new Element( 'span' );	
		d2.className = 'title';
		d2.update( o.title );
		var o2 = o.cloneNode( true );
		o2.title = ''; // clear out title
		span.update( d2 );
		span.insert( { bottom: o2 } );
		o.replace( span );
	});

	// temporarily unengage SAIT website clickable banner images
	if ( SERVER.blogurl === '/sait' || SERVER.blogurl === '/studentaffairs/sait' || location.href.include('SelfService')  ) {
		$$('.header-montage a').each( function(o) {
			o.observe( 'click', function(e) {
				e.stop();
			});
			o.observe( 'focus', function(e) {
				e.stop();
				o.blur();
			});
			o.style.cursor = 'default';
		});
		$$('.header-montage .title').each( function(o) {
			o.remove();
		});
	}

		
	// ajax form stuff
	$$( '.page-content formDISENGEFORNOW' ).each( function(o) {
		o.addClassName( 'procdessed' );
		o.observe( 'submit', function(e) {
			var action = '/disability/proxy.php?proxy_url=' + o.action; //encodeURIComponent( o.action );
			e.stop();
			var spinner = $$( '.spinning-wheel' )[0]; 
			var anim = new Effect.SlideDown( spinner.parentNode, {
				duration: 0.5,
				afterFinish: function() {
					var parameters = o.serialize( true );
					myAjax = new Ajax.Request( action, {
						method: 'post',
						parameters: parameters,
						onSuccess: function(r) {
							new Effect.SlideUp( spinner.parentNode, {
								delay: 1.5,
								duration: 0.3,
								afterFinish: function() {
									/*var x = r.responseXML;
									var d = x.getElementsByTagName( 'div' )[0];
									d.setAttribute( 'style', 'display: none' );
									if ( d.xml ) {
										var s = d.xml;
									} else if ( window.XMLSerializer ) {
										var s = (new XMLSerializer()).serializeToString( d );  
									} else {
										alert( 'there was a problem' );
									}*/
									var s = r.responseText;
									var par = $( o.parentNode );
									
									if ( s.include( 'Thank You' ) ) {
										var ic = new Element( 'div', { id : 'inner-content', style : 'display: none', className: 'valid' } );
											var h4 = new Element( 'h4' ).update( 'Form Completed' ); 
											var check = new Element( 'div', { className : 'checkmark' } ).update('&#10003;');
											var p  = new Element( 'p'  ).update( 'Your form has been submitted' );
										ic.insert( h4 );
										ic.insert( check );
										ic.insert( p );
										var dl = new Element( 'dl' );
										$H( parameters ).each( function( pair ) {
											//if ( pair.key != 'recipient' && pair.key != 'required' ) {
											if ( $( pair.key ).type != 'hidden' ) {
												var dt = new Element( 'dt' );
												var label = $$( 'label[for=' + pair.key + ']' )[0].firstChild.cloneNode( false );
												//dt.update( label );
												dt.appendChild( label );
												var dd = new Element( 'dd' );
												dd.update( pair.value );
												dl.insert( dt );
												dl.insert( dd );
											}
										});
										ic.insert( dl );
										var btn = new Element( 'input', { value: 'Fill out another form', onclick: 'window.location.href = window.location.href'});
										ic.insert( btn );
									} else {
										ic = "There was an error";
									}
									new Effect.ScrollTo( o.previous(0), {
										duration: 0.3,
										afterFinish: function() {
											o.down( 0 ).replace( ic );

											new Effect.BlindDown( $( 'inner-content' ), { 
												afterFinish: function() {
													if ( window.browserIsIE ) {
														$( 'actual-form' ).style.visibility = 'hidden';
													} else {
														new Effect.Opacity( 'actual-form' , {
															duration: 1,
															from: 1,
															to: 0 
														});
													}
												}
											});

										}
									});

								}
							});
						}
					});
				}
			});
		});
	});

	window.invalidFields = function() {
		$$( '.page-content form .invalid a').each( function(o) {
			o.observe( 'click', function(e) {
				var the_id = o.href.replace( /(.*)#(.+)/, '$2' );
				if ( $( the_id ) ) {
					var fieldset = $( the_id ).up( 'fieldset' );
					var eff = new Effect.ScrollTo( fieldset, {
						duration: 2,
						afterFinish: function() {
							$(the_id).focus();
						}
					 });
					//$(the_id).focus();
					e.stop();
				}
			});
		});
	};
	invalidFields(); // run this once at startup

	//global
	setLowVision = function() {
		var styleNode = $( 'lowvision' );
		var schemes = [ $H({
		// high contrast
			'black'  : '#000000',
			'white'  : '#FFFF00',
			'blue'  : '#00FFFF',
			'green' : '#00FFFF'
		}),
		// lightblue back
		$H({
			'black'  : '#EFF8FB',
			'white'  : '#010066',
			'blue'  :  '#FF0000',
			'green'  : '#FF0000'
		}),
		// cream back:
		$H({
			'black'  : '#FFF9D2',
			'white'  : '#010066',
			'blue'   : '#908000',
			'green'  : '#908000'
		}),
		// black and white
		$H({
			'black'  : 'black',
			'white'  : 'white',
			'blue'  :  'white',
			'green'  : 'white'
		}) ];

		var cookieOptions = {
			path : '/', // all sub paths
			domain: 'northwestern.edu',
			expires: new Date("January 12, 2025"),
			secure: false // don't want only over SSL
		};
		if ( schemeIndex == schemes.length ) {
			replaceAllCss( styleNode, '' );
			YAHOO.util.Cookie.remove( "lv", cookieOptions );
			schemeIndex = 0;
			return;
		}
		var cookieData = schemes[schemeIndex].toObject();
		YAHOO.util.Cookie.setSubs( "lv", cookieData, cookieOptions ); 
		var changes = $H({
			'black'  : 'black',
			'white'  : 'white'
		});
		var css = lowVisionCss;
		schemes[schemeIndex].each( function(p) {
			css = css.gsub( p.key, p.value );
		});
		window.schemeIndex += 1;
		lowVisionEnabled = true;
		replaceAllCss( styleNode , css );
	};

	$$( '.accessView' ).each( function(o) {
		var c = YAHOO.util.Cookie;
		var cookieOptions = {
			path : '/', // all sub paths
			domain: 'northwestern.edu',
			expires: new Date("January 12, 2025"),
			secure: false // don't want only over SSL
		};
		var a = new Element( 'a', {href: '#'} ).update( 'Switch Stylesheet' );
		o.update(a);
		a.addClassName( 'toggleStyle' );
		//slider:
		var s = YAHOO.widget.Slider;
		$( 'hsliderbg' ).style.width = '160px';
		$( 'hsliderbg' ).style.outline = 'none';
		$( 'hsliderbg' ).style.tabIndex = '-1';
		var sl = s.getHorizSlider( 'hsliderbg', 'hsliderthumb', 0, 150 );
		sl.animate = true;
		sl.subscribe( 'change', function(v) {
			var fs = v * 2;
			$$( 'body' )[0].style.fontSize = fs+'%';
			c.set( 'fontsize', fs, cookieOptions );

		});
		sl.setValue( ( c.get( 'fontsize' ) || 100 ) / 2 );
		$$( '#fontsizeslider label' )[0].observe( 'click', function(e) {
			e.stop();
			sl.setValue( 50 );
		});
	});

	$$( '.toggleStyle' )[0].observe( 'click', function(e) {
		e.stop();
		if ( !window.lowVisionCss ) {
			window.schemeIndex = 0;
			//var ds = $( 'default-style' ).content;
			var ds = 'new-design';
			var url = SERVER.blogurl + '/styles/' + ds + '/low-vision.css';
			var a = new Ajax.Request( url, {
				method: 'post',
				onSuccess: function(r) {
					lowVisionCss = r.responseText;
					var style = new Element( 'style', { type: 'text/css', id: 'lowvision' } );
					$$( 'head' )[0].insert({ bottom: style });
					setTimeout( setLowVision, 0 );
				}
			});
		} else {
			setLowVision();
		}
	});

	if ($('rotating-banner-source')) {
		$('rotating-banner-source').style.display = 'none';
		var banners = [];
		var next = 0;
		$$( '#rotating-banner-source img' ).each( function(o) {
			banners.push (o.src);
		});
		
		var bo = new Element('div', {'id':'banner-over'} );
		bo.style.backgroundImage = 'url('+banners[next]+')';
		next++;
		var bb = new Element('div', {'id':'banner-behind'} );
		bb.style.backgroundImage = 'url('+banners[next]+')';
		var bc = $('rotating-banner-container');
		bc.update('');
		bc.insert( { bottom: bb } );
		bc.insert( { bottom: bo } );
		new PeriodicalExecuter( function() {
			$('banner-over').fade({
				duration: 2,
				afterFinish: function() {
					$('banner-over').style.backgroundImage='url('+banners[next]+')';
					$('banner-over').style.display = 'block';
					next++;
					if (next==(banners.length)) {
						next=0;
					}
					$('banner-behind').style.backgroundImage='url('+banners[next]+')';
					
				}
			});
		},3);
	}
	e.stop();
	
	$$('a.modalbox').each( function(a) {
		a.observe( 'click', function(e) {
			e.stop();
			var e = new Element( 'div', { id: 'mb-inner-content' } ).update( ' ' );
			Modalbox.show( e, {
				title: 'Chapter Details',
				transitions: false,
				overlayOpacity: .9,
				afterLoad: function() {
					var myAjax = new Ajax.Request( a.href, {
						method: 'post',
						evalJS: false,
						onSuccess: function(r) {
							var regex = new RegExp('(id="ac-main-content">)([\\s\\S]*)(<div class="section-b)', '' );
							var result = r.responseText.match(regex)[2];
							var mb = $('mb-inner-content');
							mb.style.visibility = 'hidden';
							mb.update(result);
							var btn = new Element( 'button', {style: 'margin: auto; display: block'} ).update(' Close ');
							mb.insert({ bottom: btn });
							btn.observe( 'click', function(e) {
								e.stop();
								Modalbox.hide();
							});
							Modalbox.resizeToContent({
								afterResize: function() {
									mb.style.display = 'none';
									mb.style.visibility = 'visible';
									mb.appear({duration:1});
								}
							});
						}
					});
				}
			});
		});
	});
	
});