Event.observe(window, 'load', function() {
	// do some CSS magic for no javascript version
	Element.addClassName('main', 'hasjs');

	//---------
	// swapper
	//---------

	// some DOM stuff
	var triggers = $$('#main .swapnav');
	var contents = $$('#main .swapcontent');

	// all the important stuff
	if (triggers.length>0 && contents.length>0) {
		var pagenav = new PageNav($$('#main .pagenav'), $$('#main #subnav li'), 'swapcontent');
		var swapper = new FadeSwap(triggers, contents, 'click');

		// fix the local nav
		var localnav = $$('#main #localnav ul li a');
		if (localnav.length>0) {
			for (var i=0; i<localnav.length; i++) {
				var section = document.location.toString().match(/(.*)#/);
				section = (section) ? section[1] : document.location.toString();
				if (localnav[i].href.match(section)) {
					if (section.match('logicpro')) {
						localnav[i].href += '#new';
					} else {
						localnav[i].href += '#overview';
					}
				}
			}
		}

		// fix the anchor links for Safari (so it doesn't enter a constantly loading state)
		// and make anchor links fade and swap instead of browser default
		var anchors = new AnchorFix(triggers, contents, swapper);
		
		// find the default
		var id = 0;
		if (document.location.hash) {
			var initial = document.location.hash;
			initial = initial.match(/#(.*)/)[1];
			var doesContentExist = anchors.doesContentExist(initial)
			if (doesContentExist) {
				id = doesContentExist.index;
			}
		}

		// swap to the default
		swapper.swapContent(null, id);
	}

	//--------
	// overlays
	//--------

	// image gallery overlay
	var imageGalleryNav = $$('#main .gallerybox ul.popupnav li a.overlaythumb');
	var imageGallery = (imageGalleryNav.length>0) ? new AC.ImageOverlay(imageGalleryNav) : false;
	
	// movie overlay
	var movieOverlayNav = $$('#main .gallerybox .watchvideo');
	var movieOverlay = (movieOverlayNav.length>0) ? new AC.MovieOverlay(movieOverlayNav, {movieheight:400}) : false;

	// movie gallery overlay
	var movieGalleryOverlayNav = $$('#main .watchvideotour');
	var movieGalleryOverlay = (movieGalleryOverlayNav.length>0) ? new AC.MovieGalleryOverlay(movieGalleryOverlayNav, {movieheight:400}) : false;

	// audio overlay
	var audioOverlayNav = $$('#main .gallerybox .listen');
	var audioOverlay = (audioOverlayNav.length>0) ? new AC.AudioOverlay(audioOverlayNav) : false;
	
	// audio vr overlay
	var audioVrGalleryOverlayNav = $$('#main .gallerybox .vritem');
	var audioVrGalleryOverlay = (audioVrGalleryOverlayNav.length>0) ? new AC.AudioVrGalleryOverlay(audioVrGalleryOverlayNav) : false;

	// close the other ones when we pop the other
	if (imageGallery) {
		Event.observe(imageGallery, 'beforePop', function() {
			if (movieOverlay) movieOverlay.close();
			if (movieGalleryOverlay) movieGalleryOverlay.close();
			if (audioOverlay) audioOverlay.close();
			if (audioVrGalleryOverlay) audioVrGalleryOverlay.close();
		}.bind(movieOverlay, movieGalleryOverlay, audioOverlay, audioVrGalleryOverlay), false);
	}
		
	if (movieOverlay) {
		Event.observe(movieOverlay, 'beforePop', function() {
			if (imageGallery) imageGallery.close();
			if (movieGalleryOverlay) movieGalleryOverlay.close();
			if (audioOverlay) audioOverlay.close();
			if (audioVrGalleryOverlay) audioVrGalleryOverlay.close();
		}.bind(imageGallery, movieGalleryOverlay, audioOverlay, audioVrGalleryOverlay), false);
	}
		
	if (movieGalleryOverlay) {
		Event.observe(movieGalleryOverlay, 'beforePop', function() {
			if (imageGallery) imageGallery.close();
			if (movieOverlay) movieOverlay.close();
			if (audioOverlay) audioOverlay.close();
			if (audioVrGalleryOverlay) audioVrGalleryOverlay.close();
		}.bind(imageGallery, movieOverlay, audioOverlay, audioVrGalleryOverlay), false);
	}
		
	if (audioOverlay) {
		Event.observe(audioOverlay, 'beforePop', function() {
			if (imageGallery) imageGallery.close();
			if (movieOverlay) movieOverlay.close();
			if (movieGalleryOverlay) movieGalleryOverlay.close();
			if (audioVrGalleryOverlay) audioVrGalleryOverlay.close();
		}.bind(imageGallery, movieOverlay, movieGalleryOverlay, audioVrGalleryOverlay), false);
	}
		
	if (audioVrGalleryOverlay) {
		Event.observe(audioVrGalleryOverlay, 'beforePop', function() {
			if (imageGallery) imageGallery.close();
			if (movieOverlay) movieOverlay.close();
			if (movieGalleryOverlay) movieGalleryOverlay.close();
			if (audioOverlay) audioOverlay.close();
		}.bind(imageGallery, movieOverlay, movieGalleryOverlay, audioOverlay), false);
	}

}, false);// JavaScript Document