DISCO = ({	
	 options: {
		 animationSpeed : 1000
		,containerSelector : '#container'
		,debug : false
		,contentItemClass : 'content-item'
		,easing : 'easeInOutSine'
		,expandoContentSelector: '.expando > article'
		,navItemSelector : 'header nav ul a'
		,sectionTriggerSelector: '.section-trigger'
		,siteDefinition : '/desktop.json'
		,siteName : 'EURO Discovery'
		,urlSubPageIdentifier : '?page='
	}
	// find a page by friendly url
	,getPageByFriendlyURL: function (url) {
		var subpage = url.split(site.options.urlSubPageIdentifier);
		$.each(site.pages, function (i, page) {
			if (page.friendlyURL == subpage[0]) {
				site.showPage(page, (subpage.length == 2 ? $('#' + subpage[1]) : ''));
			}
		});
	}
	// a friendly URL from a regular URL
	,createFriendlyURL: function (url) {
		var subpage = url.replace('index.cfm', '').split('#');
		subpage[0] = subpage[0].substr(0, subpage[0].lastIndexOf('/'));
		return '!' + subpage[0] + (subpage.length > 1 ? site.options.urlSubPageIdentifier + subpage[1] : '');
	}
	// start 'er up
	,init: function () {
		// some things we're gonna need...
		site = this;
		site.container = $(site.options.containerSelector).html('');
		site.navigation = $(site.options.navItemSelector);
		site.loadCount = 0;
		// start 'er up, yo
		site.loadSite();
		// bindings
		site.navigation.live('click', function (e) {
			e.preventDefault();
			var url = site.createFriendlyURL($(e.currentTarget).attr('href'));
			window.location.hash = url;
			site.getPageByFriendlyURL(url);
		});
		// section/page triggers
		$(site.options.sectionTriggerSelector).live('click', function (e) {
			e.preventDefault();
			var $trigger = $(e.currentTarget);
			window.location.hash = site.createFriendlyURL($trigger.attr('href'));
		});
		// expando triggers
		$('.trigger, .expando-trigger, .close').live('click', function (e) {
			e.preventDefault();
			var $trigger = $(e.currentTarget);
			if ($trigger.hasClass('trigger')) {
				var $target = $($trigger.attr('href'));
				$target.slideDown(750, function() {site.loadImages($target)});
				if ($trigger.hasClass('view-more')) {
					var yOffset = Math.abs(site.container.offset().top - $('>h1', $trigger.parents('article')).offset().top + 15);
					$.scrollTo(yOffset, {duration: site.options.animationSpeed, easing: site.options.easing});
				}
			}
			else if ($trigger.hasClass('expando-trigger')) {
				var  $target  = $($trigger.attr('data-target'))
					,$page = $target.parents('.' + site.options.contentItemClass)
					,url = window.location.hash.split(site.options.urlSubPageIdentifier);
				window.location.hash = $page.attr('data-friendlyURL') + site.options.urlSubPageIdentifier + $trigger.attr('href').substr(1);
				$('.expando-trigger').not($trigger).removeClass('active');
				$trigger.addClass('active');
				var yOffset = Math.abs(site.container.offset().top - $page.offset().top);
				$.scrollTo(yOffset, {duration: site.options.animationSpeed, easing: site.options.easing});
				$('.expando-trigger[href="' + $trigger.attr('href') + '"]').addClass('active');
			}
			else if ($trigger.hasClass('close')) {
				var  $target = $($trigger.attr('href'))
					,$page = $target.parents('.' + site.options.contentItemClass);
				if ($trigger.hasClass('view-more')) {
					$target.slideUp(750);
				}
				else {
					$('.close, .more-info', $target).hide();
					var subpage = window.location.hash.split(site.options.urlSubPageIdentifier);
					window.location.hash = subpage[0];
				}
				$('>article', $target).slideUp(750);
				$('.expando-trigger').removeClass('active');
				var yOffset = Math.abs(site.container.offset().top - $page.offset().top);
				$.scrollTo(yOffset, {duration: site.options.animationSpeed, easing: site.options.easing});
			}
		});
		$(window).bind('hashchange scroll', function (e) {
			if (e.type == 'hashchange') {
				site.getPageByFriendlyURL(window.location.hash.substr(1));
			}
			else {
				var  center = e.currentTarget.pageYOffset
					,minLim = center - 150
					,maxLim = center + 150;
				$('.' + site.options.contentItemClass, site.container).each(function () {
					var  $section = $(this)
						,top = $section.offset().top;
					if (top > minLim && top < maxLim) {
						var  url = $section.attr('data-friendlyURL').replace('!', '')
							,$navTrigger = site.navigation.filter('[href^="' + url + '"]').addClass('active');
						site.navigation.not($navTrigger).removeClass('active');
					}
				});
			}
		});
		if (!$('html').hasClass('hashchange')) {
			$(window).hashchange(function () {
				site.getPageByFriendlyURL(window.location.hash.substr(1));
			});
		}
	}
	// show hidden images inside expandos
	,loadImages: function ($container) {
		$('img.delay-load', $container).each(function (i) {
			$(this).attr('src', $(this).attr('data-load')).removeClass('delay-load');
		});
	}
	// fetch the site definition and load the page objects
	,loadSite: function () {
		$.ajax({
			 url: site.options.siteDefinition
			,dataType: 'json'
			,success: function (response) {
				$.each(response.pages, function (i, page) {
					page.friendlyURL = site.createFriendlyURL(page.url);
					site.pages.push(page);
					site.loadPage(page);
				});
				$.each(response.metas, function (i) {site.metas.push(response.metas[i]);})
			}
		});
	}
	// create, load, and add each page section to the main content area
	,loadPage: function (page) {
		var $section = $('<section>');
		$section
			.attr({
				 'class' : site.options.contentItemClass
				,'data-opened' : 'false'
				,'data-friendlyURL' : page.friendlyURL
				,'id' : page.htmlID
			})
			.load(page.url + '?fetch=true', function () {
				if ($.browser.msie && parseInt($.browser.version) < 9) {
					var tmp = $(this).html();
					$(this).html('').append(innerShiv(tmp));
					ieHacker();
				}
				// hide the crap in the expando, but don't hide the expando itself
				$('.expando article', $(this)).hide();
				// don't wanna load all of the images at once or it's gonna go slooooooow, so set up delayed image loader for all of the images in expandos
				$('.expando img', $(this)).each(function (i) {
					$(this)
						.addClass('delay-load')
						.attr({
							 'data-load' : $(this).attr('src')
							,'src' : '/elements/images/global/blank.png'
						});
				});
				site.loadCount++;
				if (site.loadCount == site.pages.length) {
					if (window.location.hash !== '') {
						var url = window.location.hash.substr(1);
						site.getPageByFriendlyURL(url);
					}
					else {site.showPage(site.pages[0], '');}
				}
			});
		site.container.append($section);
	}
	// close the opened page sections, open the target page section, slide target page section to top
	,showPage: function (page, $subpage) {
		var  $currentlyOpened = $('[data-opened="true"]', site.container).attr('data-opened', 'false')
			,$openExpandos = $(site.options.expandoContentSelector, $currentlyOpened).filter(':visible')
			,$target = $('#' + page.htmlID, site.container).attr('data-opened', 'true')
			,$navTrigger = site.navigation.filter('[href^="' + page.url.replace('index.cfm', '') + '"]');
		if ($openExpandos.length) {
			if ($('html').hasClass('video') && $('video', $openExpandos).length) {$('video', $openExpandos).get(0).pause();}
			$openExpandos.slideUp(site.options.animationSpeed / 2, function () {
				var yOffset = Math.abs(site.container.offset().top - $target.offset().top);
				$.scrollTo(yOffset, {duration: site.options.animationSpeed, easing: site.options.easing, onAfter: function () {site.navigation.removeClass('active'); $navTrigger.addClass('active'); site.setTitle();}});
			});
		}
		else {
			var yOffset = Math.abs(site.container.offset().top - $target.offset().top);
			$.scrollTo(yOffset, {duration: site.options.animationSpeed, easing: site.options.easing, onAfter: function () {site.navigation.removeClass('active'); $navTrigger.addClass('active'); site.setTitle();}});
		}
		site.doTracking(window.location.hash.substr(2).replace(site.options.urlSubPageIdentifier, '/#'));
		if ($subpage != '') {site.showSubPage($subpage);}
		else {$('.close:visible').click();}
	}
	// subpages
	,showSubPage: function ($subpage) {
		var $parent = $subpage.parents('.expando').eq(0);
		$('>article', $parent).not($subpage).slideUp(750);
		$subpage.slideDown(750, function() {site.loadImages($parent)}).trigger('opened');
		$('.close', $parent).show();
	}
	,setTitle: function () {
		$.each(site.metas, function (i) {
			if (site.metas[i].friendlyURL == window.location.hash) {
				document.title = site.metas[i].title;
			}
		});
	}
	// handle the tracking/analytics stuff for a page
	,doTracking: function (url) {
		_gaq.push(['_trackPageview', url]);
	}
	// holds all of the page objects pulled from the site definition
	,pages: []
	// holds all of the metas pulled from the site definition
	,metas: []
});
