var mdialog = [];
var mask;

window.addEvent('domready', function() {
	$$('input').each(function(item) { 
		if(item.get('disabled'))
		{
			item.addClass('disabled');
		}
	});

	
	
	var content = $('copy');
	if(content) {
		// force a blank div at the bottom of the content div that clears the floating
		new Element('div', {'class': 'clear'}).inject(content);


		// apply a proper style to a selected item in the submenu
		var submenu = content.getElement('.submenu')
		if(submenu) {
			var uri = new URI(location.href);
			submenu.getElements('a').each(function(item) {
				if(item.get('href') == uri.get('directory')) {
					item.addClass('selected');
				}
			});
		}
	}
	
	

	
	// find and build a dialog box for all popup elements
	mask = new Mask($('page'), {useIframeShim: true});
	$$('.openpopup').each(function(popup) {
		popup.addEvent('click', function() {
			var msg = $(popup.get('rel'));
			var titleBar = msg.getElement('.title');
			var title = titleBar ? titleBar.get('text') : '';
			
			mdialog[mdialog.length] = new MavDialog({
				'title': title,
				'width': '700',
				'message': $(popup.get('rel')),
				'onShow': function() {
					mask.show();
				},
				'onClose': function() {
					mask.hide();
				}
			});
		});
	});



	
	// align sideBar
	var sidebar = $('sideBar');
	if(sidebar) {
		//var sb = new SlidingSidebar(sidebar);
	
		sidebar.getElements('.section').each(function(section) {
			// there is a bug where the sidebar covers links and makes them unclickable,
			// as a result, we need to only expand the sidebar to its full length when
			// its in use and we know the user wont be clicking these links
			section.style.width = '57px';
			
			section.addEvents({
				'mouseenter': function(){
					this.set('tween', {
						duration: 300,
						transition: Fx.Transitions.Quad.easeOut
					}).tween('width', '400px'); 
				},
				'mouseleave': function(){
					this.tween('width', '57px');
				}
			});
		});

		centerElementVertically(sidebar);
		sidebar.pin();
		
		// when the window is resized, make sure the sidebar stays pinned centered and on the right
		window.addEvent('resize', function() {
			sidebar.unpin();
			sidebar.style.left = '';
			centerElementVertically(sidebar);
			sidebar.pin();
		});
	}
	
	
	var ffCarousel = $('famousFacesCarousel');
	if(ffCarousel) {
		var carousel = new ImpCarousel(ffCarousel);
		carousel.start();
	}
	
	var mhCarousel = $('mainHeaderCarousel');
	if(mhCarousel) {
		var carousel = new ImpCarousel(mhCarousel, {
			scrollDuration: 1000,
			childType: 'div'
		});
		carousel.start();
	}
	
	
	/*
	window.addEvent('domready', function() {
		swfobject.registerObject("leftFlash", "9.0.115", "expressInstall.swf");
		swfobject.registerObject("rightFlash", "9.0.115", "expressInstall.swf");
	});
	*/
});

