window.addEvent('domready', function() {
									 
	/* If home page, load a background */
	if ($(document.body).hasClass('home')) {
		var homepages = ['innovation','solutions'];
		var activeIndex = $random(0,homepages.length-1);
		$(document.body).addClass(homepages[activeIndex]);
		$(homepages[activeIndex]).setStyle('display','block');
	}
	
	/* Navigation Sliders */
	if ($('main_links')) {
		$('main_links').getElements('li.slider').each(function(slider) {
			if (slider.getElement('ul')) {
				slider.mySlide = new Fx.Slide(slider.getElement('ul'), {'link':'cancel'});
				if (!slider.hasClass('active')) { 
					slider.mySlide.hide();
					slider.addEvents({
						'mouseenter': function(e) {
							this.mySlide.slideIn();
						},
						'mouseleave': function(e) {
							this.mySlide.slideOut();
						}
					});
				}
			}
		});
	}
	
	/* 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)
				});
			});
		}
	});
	
	/* 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[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 ($$('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',
				ytplayer: true
			});
		}});
	}
	
	/* 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)
		});
	});
	
	/* 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')});
			});
		}});
	}
	
});

function ajaxNews(el) { return; }
