window.addEvent('domready', function() {
									 
	/* IE margin fix */
	if (Browser.Engine.trident4) {
		if ($('right_sidebar')) $('content').setStyles({'float':'left','width': '485px'});
		if ($$('.home-image').length > 0) $('content').setStyles({'float':'left', 'width':'375px'});
	}
	else if (Browser.Engine.trident) {
		$$('.boxed-section').each(function(bs) { bs.setStyle('position','relative'); });
	}
	
	/* Initialize cookie */
	if ($('leftnav')) {
		var cookie = new Hash.Cookie('MichiganTechWeb', {path: location.pathname.slice(0, location.pathname.indexOf('/', 1))});
		if (!cookie.get('quick_links')) {
			if ($$('#quick_links .sublinks').some(function(item) { return item.hasClass('active'); })) {
				cookie.set('quick_links',$$('#quick_links .sublinks').map(function(item) {return item.hasClass('active');}).indexOf(true));
			} else {
				cookie.set('quick_links', -1);
			}
		}
		
		if (location.hostname == 'blogs.mtu.edu') {
			if ($('quick_links')) $('quick_links').removeClass('references_841');
		}
		if ($$('#main_links .sublinks, .references_841 .sublinks').length > 0) {
			var mainAccordion = new Accordion($$('#main_links h2, .references_841 li.sub h3'), $$('#main_links .sublinks, .references_841 .sublinks'), {
				show: ($$('#main_links .sublinks, .references_841 .sublinks').indexOf($('leftnav').getElement('.active')) >= 0) ? $$('#main_links .sublinks, .references_841 .sublinks').indexOf($('leftnav').getElement('.active')) : 0, //cookie.get('main_links') ? cookie.get('main_links') : 0,
				opacity: false,
				alwaysHide: true,
				onActive: function(toggler, element) {
					toggler.removeClass('expand').addClass('collapse');
				},
				onBackground: function(toggler, element) {
					toggler.removeClass('collapse').addClass('expand');
				}
			});
		
			$$('#main_links h2 a, .references_841 li.sub h3 a, #quick_links li.sub h3 a').each(function(item) {
				if (!item.hasChild()) {
					item.getParent().appendText(item.get('text'), 'top');
				}
				else {
					item.getParent().adopt(item.getChildren());
				}
				item.destroy();
			});
			
			$('main_links').getElements('a[href^=#]').each(function(item) {
				item.addEvent('click', function(e) {
					new Event(e).stop();
					var el = $(this.get('href').substring(1));
					if (el && (el.hasClass('slider') || el.hasClass('faq'))) {
						var slider = el.getElement('.answer, .slider-content').get('slide');
						slider.slideIn();
						new Fx.Scroll(window).toElement(el);
					}
				});
			});
		}
		
		
		if ($$('.references_841').length == 0) {
			var qlAccordion = new Accordion($$('#quick_links li.sub h3'), $$('#quick_links .sublinks'), {
				show: cookie.get('quick_links').toInt(),
				opacity: false,
				alwaysHide: true,
				onActive: function(toggler, element) {
					toggler.removeClass('expand').addClass('collapse');
				},
				onBackground: function(toggler, element) {
					toggler.removeClass('collapse').addClass('expand');
				}
			});
		}
		cookie.erase('quick_links');
		$$('#leftnav .sublinks').each(function(item) {
			item.setStyle('display', 'block');
		});
		
		$$('#quick_links li.sub li a').each(function(item) {
			item.addEvent('click', function(e) {
				cookie.set('quick_links', $$('#quick_links li.sub').indexOf(item.getParent('.sub')).toString());
			});
		});
	}
	
	
	/* Add the scroll effect for the Image rotator */
	if ($$('.images .item').length > 1) {
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/SimpleSlide.js', {id: 'SimpleSlide'	});
		$$('.images .item .caption').each(function(item) {
			new Element('img', {
				'src': (location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/images/arrow-small.gif',
				'alt': 'Next'
			}).inject(new Element('span', {'class': 'next'}).appendText((item.get('title') ? item.get('title') : 'more')+' ').inject(item));
			if (item.getPrevious() && item.getPrevious().get('tag') == 'img') {
				item.getPrevious().addClass('nextImage').setStyle('cursor', 'pointer');
			}
		});
		$$('.images').each(function(mainItem, mainIndex) {
			mainItem.getElements('.next, .nextImage').each(function(item, index) {
				item.addEvent('click', function(e) {
					e = new Event(e).stop();
					new SimpleSlide(mainItem, {type: 'scroll', direction: 'forward', duration: 400});
				});
			});
		});
	}
	
	/* Focus -- change on refresh, random
	 * Previous/Next -- Fade in/out on change */
	$$('.focus').each(function(item) {
		var slides = item.getElements('.item');
		if (slides.length > 0) {
			var width = slides[0].getSize().x;
			if (item.hasClass('prev-next')) {
				new Fx.Scroll(item).set(0, 0);
				slides[0].addClass('active').fade('in');
				var elements = {
					wrapper: new Element('div',{styles:item.getStyles('width','overflow')}).wraps(item.getElement('.inner')),
					pager: new Element('div', {'class': 'paginate'}),
					next: new Element('a', {'class':'next','href':'#',events:{
						'click': function(e) {
							new Event(e).stop();
							elements.slide('next');
						}
					}}).set('text','Next'),
					prev: new Element('a', {'class':'prev','href':'#',events:{
						'click': function(e) {
							new Event(e).stop();
							elements.slide('prev');
						}
					}}).set('text','Previous'),
					slide: function(direction) {
						var active = item.getElement('div.active');
						if (!active) return;
						var next = direction == 'prev' ? active.getPrevious() : active.getNext();
						if (!next) return;
						var index = slides.indexOf(next);
						active.removeClass('active').fade('out').get('tween').chain(function() { new Fx.Scroll(elements.wrapper, {duration: 0}).start(width*index-1, 0).chain(function() {next.addClass('active').fade('in'); }); });
					}
				}
				elements.next.inject(elements.pager);
				elements.prev.inject(elements.pager);
				elements.pager.inject(item);
			} else {
				var index = $random(0,slides.length-1);
				slides[index].setStyles({'visibility': 'hidden', 'display': 'block'});
				slides[index].addClass('active').fade('in');
			}
		}
	});
	
	/* Add the tabbed group functionality */
	$$('.tab_group').each(function(group) {
		group.getElements('.tabs li').each(function(item,index) {
			item.addEvent('click',function(e) {
				e = new Event(e).stop();
				group.getElements('.tab_content').each(function(tabItem) {
					tabItem.getChildren('.item').each(function(subitem, item_index) {
						if (index == item_index) {
							subitem.addClass('tabactive');
						} else {
							subitem.removeClass('tabactive');
						}
					});
				});
				group.getElements('.tabs li').each(function(tab, item_index) {
					tab.removeClass('tabactive');
				});
				item.addClass('tabactive');
			});
		});
	});
	
	/* FAQs / Sliders */
	$$('.faqs .question', '.slider .bar').each(function(item, index) {
		if (item.getParent().getElement('.slider-content')) {
			var content = item.getParent().getElement('.slider-content');
			if (content.getStyle('padding-top').toInt() == 0) content.setStyle('padding-top','1px');
			if (content.getStyle('padding-bottom').toInt() == 0) content.setStyle('padding-bottom','1px');
		}
		var slide = new Fx.Slide(item.getParent().getElement('.answer, .slider-content'), {
			link: 'chain',
			onComplete: function() {if (this.open) this.wrapper.setStyle('height','auto'); else this.wrapper.setStyle('height', '0'); }
		});
		if (item.hasClass('open') || (location.hash && item.getParent().get('id') == location.hash.substr(1))) {
			slide.show();
			if (item.getElement('h2,h4')) item.getElement('h2,h4').addClass('collapse');
		} else {
			slide.hide();
			if (item.getElement('h2,h4')) item.getElement('h2,h4').addClass('expand');
		}
		item.addEvents({
			'click': function(e) {
				this.toggle();
				if (this.open && item.getElement('h2,h4')) {
					item.getElement('h2,h4').removeClass('collapse').addClass('expand');
				}
				else if (item.getElement('h2,h4')) {
					item.getElement('h2,h4').removeClass('expand').addClass('collapse');
				}
			}.bind(slide),
			'mouseenter': function() {
				this.addClass('highlight');
			},
			'mouseleave': function() {
				this.removeClass('highlight');
			}
		});
		if (item.getParent().hasClass('announcements')) {
			item.getNext().getElements('.item').each(function(subitem) {
				subitem.addEvents({
					'click': function(e) {
						e = new Event(e).stop();
						location.href = this.getElement('a.link').getProperty('href');
					}.bind(subitem),
					'mouseenter': function() {
						this.addClass('highlight');
					}.bind(subitem),
					'mouseleave': function() {
						this.removeClass('highlight');
					}.bind(subitem)
				});
			});
		}
		if (location.hash && $(location.hash.substr(1))) {
			new Fx.Scroll(window,{duration:0}).toElement($(location.hash.substr(1)));
		}
	});
	
	/* Photo Gallery */
	if ($$('.gallery, .images').length > 0) {
		var mainAccordion = new Accordion($$('.gallery h2'), $$('.gallery .photo_gallery'), {
			show: cookie.get('gallery') ? cookie.get('gallery') : 0,
			opacity: false,
			alwaysHide: true,
			onActive: function(toggler, element) {
				toggler.removeClass('expand').addClass('collapse');
			},
			onBackground: function(toggler, element) {
				toggler.removeClass('collapse').addClass('expand');
			}
		});
	}
	
	/* Label in textfields */
	$$('label.label_in_textfield').each(function(item) {
		var defVal = $(item.get('for')).get('value');
		$(item.get('for')).set('value', item.get('text')).setStyle('color', '#666').addEvents({
			blur: function(e) {
				if (!$(this.get('for')).get('value').length) { $(this.get('for')).setStyle('color', '#666').set('value', this.get('text')); }
			}.bind(item),
			focus: function(e) {
				if($(this.get('for')).get('value')==this.get('text')) {$(this.get('for')).setStyle('color', '#333').set('value', '');}
			}.bind(item)
		});
		var form;
		for (var i=0; i<item.getParents().length; i++) {
			if (item.getParents()[i].get('tag') == 'form') {
				form = item.getParents()[i];
				break;
			}
		}
		form.addEvent('submit', function(e) {
			if (['', defVal].contains($(item.get('for')).get('value'))) {
				new Event(e).stop();
			}
		});
	});
	
	/* Form validation */
	if ($$('form.validate').length > 0) {
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/formvalidator.js', {onload: function() {
			$$('form.validate').each(function(form) {
				form.mtuForm = new FormValidator(form, {useTitle: form.hasClass('useTitles')});
			});
		}});
	}
	
	/* Rollover buttons */
	$$('a.rollover').each(function(item) {
		var img = new Asset.image(item.getStyle('background-image').replace('url("','').replace('")','').replace('url(','').replace(')',''), { onload: function() {
			item.setStyle('display', 'block').setStyle('width', this.get('width').toInt()).setStyle('height',this.get('height').toInt() / 3).setStyle('text-decoration', 'none');
		}});
		item.addEvents({
			'mouseenter': function() {
				this.setStyle('background-position', '0 '+(0-this.getStyle('height').toInt())+'px');
			}.bind(item),
			'mouseleave': function() {
				this.setStyle('background-position', 'top left');
			}.bind(item),
			'mousedown': function() {
				this.setStyle('background-position', '0 '+(0-this.getStyle('height').toInt() * 2)+'px');
			}.bind(item)
		});
	});
		
	/* Make external links popup in new window */
	if ($('main')) {
		$('main').getElements('a[href]').each(function(item) {
			if (!item.get('target') && item.hostname && item.hostname.search(/mtu.edu/)==-1) {
				item.set('target', '_blank');
			} else if (!item.get('target')) {
				var rootFolder = item.href.split('/');
				var siteFolder = location.href.split('/');
				rootFolder = rootFolder[3]; siteFolder = siteFolder[3];
				if (['international'].contains(siteFolder) && ((item.hostname && location.hostname && item.hostname != location.hostname) || (rootFolder && siteFolder && rootFolder != siteFolder))) {
					item.set('target', '_blank');
				}
			}
		});
	}
	
	/* Modal Popups */
	if ($$('a[rel^=popup]').length > 0) {
		new Asset.css((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/styles/squeezebox.css', {media: 'screen,print'});
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/squeezebox.js', {onload: function() {
																																				   
			$$('a[rel^=popup]').each(function(item) {
				if (item.get('href').substr(0,1) == '#') {
					var dims = {x:485, y:400};
					var mtuR = true;
					if (item.get('rel').substring(5).length > 0) {
						dims = JSON.decode(item.get('rel').substring(5));
						mtuR=false;
					}
					SqueezeBox.assign(item, {size: {x:dims.x, y:dims.y}, mtuResize:mtuR});
				}
				else {
					var dims = {x:700,y:500,url:item.get('href')};
					if (item.get('rel').substring(5).length > 0) {
						dims = JSON.decode(item.get('rel').substring(5));
					}
					SqueezeBox.assign(item, {size: {x:dims.x,y:dims.y}, ajaxOptions: { method: 'get' }, handler: 'iframe', url:dims.url});
				}
			});
		}});
	}
	if ($$('a.video').length > 0) {
		new Asset.css((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/styles/squeezebox.css');
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/swfobject.js');
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/squeezebox.js', {onload: function() {
			SqueezeBox.assign($$('a.video'), {
				parse: 'rel'
			});
		}});
	}
	
	if ($$('a[rel^=milkbox]').length > 0) {
		new Asset.css((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/styles/milkbox/milkbox2.0.css');
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/milkbox/milkbox.js');
	}
	
	if (!$('right_sidebar')) {
		if ($$('.home-image').length > 0) {
			$$('hr', '.hr').each(function(hr) {if (hr.getStyle('background-image')) {hr.setStyle('background-image', hr.getStyle('background-image').replace('485','375'));}});
		}
		else {
			$$('hr', '.hr').each(function(hr) {if (hr.getStyle('background-image')) {hr.setStyle('background-image', hr.getStyle('background-image').replace('485','730'));}});
		}
	}

	/* Slideshow */
	if ($('container').getElements('div.mtuslideshow').length > 0) {
		new Asset.javascript((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/script/mtuslideshow.js', {onload: function() {
			new MTUSlideShow({wrapper:$('container').getElement('div.mtuslideshow')});
		}});
		new Asset.css((location.protocol?location.protocol:'http:') + '//www.mtu.edu/mtu_resources/styles/mtuslideshow.css');
	}

	/* AJAX form detection */
	/*if ((location.host == 'www.mtu.edu') && $$('a[href^=http://www.mtu.edu/mtu_resources/php/mtuform.php]', 'a[href^=mailto:][href$=@mtu.edu]').length > 0) {
		new Asset.css('http://www.mtu.edu/mtu_resources/styles/squeezebox-n.css', {id: 'SqueezeboxCSS', type: 'text/css', rel: 'stylesheet'});
		new Asset.javascript('http://api.recaptcha.net/js/recaptcha_ajax.js');
		new Asset.javascript('http://www.mtu.edu/mtu_resources/script/squeezebox-n.js', {id: 'SqueezeBox', onload: function() {
			SqueezeBox.assign($$('a[href^=http://www.mtu.edu/mtu_resources/php/mtuform.php]', 'a[href^=mailto:][href$=@mtu.edu]'), {//$$('a.mtuform-link'), {
				size: {x: 500, y: 100},
				handler: 'mtuemail',
				ajaxOptions: {
					method: 'post' // we use GET for requesting plain HTML
				},
				mtuResize: true,
				onOpen: function () {
					Recaptcha.create("6LcpnAMAAAAAAM1jEJkRkbHdth46Xk5hNllVibYn",
						"recaptcha", {
						   theme: "clean"
						}); }
			});
		}});
		new Asset.javascript('http://www.mtu.edu/mtu_resources/script/validate.js', {id: 'ValidateJS'});
	}*/
	
	/* Detect old browsers and display a message encourage them to update. First bit borrowed from Mootools 1.3 beta 2. */
	var ua = navigator.userAgent.toLowerCase(),
	platform = navigator.platform.toLowerCase(),
	UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0];
	var MTUBrowser = {
		version: parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]),
		name: (UA[1] == 'version') ? UA[3] : UA[1]
	};
	if ( (MTUBrowser.name=='ie' && MTUBrowser.version.toInt() < 7) ||
		 (MTUBrowser.name=='firefox' && MTUBrowser.version.toInt() < 3) ||
		 (MTUBrowser.name=='chrome' && MTUBrowser.version.toInt() < 4) ||
		 (MTUBrowser.name=='safari' && MTUBrowser.version.toInt() < 3) ) {
		var boxalert = new Element('div',{
			'styles': {
				'background-color': '#333',
				'visibility': 'hidden',
				'color': '#fff',
				'padding': '15px',
				'border': '1px solid #000',
				'-moz-border-radius': '15px',
				'-webkit-border-radius': '15px',
				'position': 'fixed',
				'bottom': '5px',
				'right': '5px',
				'width': '300px',
				'font-weight':'bold',
				'font-size':'12px',
				'z-index': 1000
			},
			'html': '<h3>You are using an outdated browser</h3><p>For a better experience using this site, please upgrade to a modern web browser.</p><div style="width:75px;float: left;text-align:center;"><a href="http://www.firefox.com" target="_blank"><img src="http://www.mtu.edu/mtu_resources/images/icons/browsers/firefox.png" alt="Get Firefox" /></a></div><div style="width:75px;float: left;text-align:center;"><a href="http://www.microsoft.com/windows/internet-explorer/" target="_blank"><img src="http://www.mtu.edu/mtu_resources/images/icons/browsers/internet-explorer.png" alt="Get Internet Explorer" /></a></div><div style="width:75px;float: left;text-align:center;"><a href="http://www.apple.com/safari/download/" target="_blank"><img src="http://www.mtu.edu/mtu_resources/images/icons/browsers/safari.png" alt="Get Safari" /></a></div><div style="width:75px;float: left;text-align:center;"><a href="http://www.google.com/chrome" target="_blank"><img src="http://www.mtu.edu/mtu_resources/images/icons/browsers/google-chrome.png" alt="Get Google Chrome" /></a></div>'
		}).inject(document.body).fade(1);
		if (Browser.Engine.trident4) {
			boxalert.setStyles({'top': '120px', 'position':'absolute'});
		}
		boxalert.fade.delay(15000,boxalert,0);
	}
});


function ajaxNews(item) {
	if (item.getElement('.parsed_content').getChildren().length > 0) {
		item.getElements('.item').each(function(subitem) {
			subitem.addEvents({
				'click': function(e) {
					e = new Event(e).stop();
					if (this.getElement('a.link')) location.href = this.getElement('a.link').getProperty('href');
				}.bind(subitem),
				'mouseenter': function() {
					this.addClass('highlight');
				}.bind(subitem),
				'mouseleave': function() {
					this.removeClass('highlight');
				}.bind(subitem)
			});
		});
	}
	else {
		// Nothing was returned, so destroy the element
		if (item.getParent().hasClass('item'))
			item.getParent().destroy();
		else
			item.destroy();
	}
}

function submitform(form) {
	if (form.get('tag') != 'form') {
		form = form.getElement('form');
	}
	if (form.get('tag') == 'form') {
		var req = new Request.HTML({
			url: form.get('action'),  // Gets the URL from the form
			onRequest: function() { form.getElement('input[type=submit]').setProperties({value:'Sending...', disabled:'disabled'}); },
			update: form.getElement('.response'),
			onSuccess: function(response) {
				if (response && response.item(0) && response.item(0).data && response.item(0).data.trim() == 'Incorrect. Try Again.') {
					form.getElement('input[type=submit]').setProperty('value', 'Send').removeProperty('disabled');
					//form.getElement('.response').setStyle('display','none');
					if(Recaptcha) {
						Recaptcha.reload();
						//$('recaptcha').inject(new Element('span', {'class': 'errorMessage'}).set('text','Incorrect. Try Again'));
					}
				}
				else {
				form.getElements('input[type=submit], .destroy').each(function(item) {item.destroy();});
				}},
			onFailure: function() { form.getElements('input[type=submit], .destroy').each(function(item) {item.destroy();}); form.getElement('.response').set('html','<span class="error">Sending failed.  Please try again later.</span>'); }
		}).send(form); 
	}
}

