﻿var delegate = {
	didAppendContent: function(view, content) {
		this.view = view;
		var section = view.currentSection;
		if (section.movieLink) {
			if (!section.close) {
				section.close = new Element('a', { className:'close '+view.triggerClassName, href:'#' }).insert('Close');
				section.content.insertBefore(section.close, section.content.firstChild);
			}
			var previous = (view.previousSection) ? view.previousSection.id : view.orderedSections[0];
			section.close.href = '#'+previous;
		}
	},
	didShow: function(view, outgoing, incoming) {
		this.didAppendContent(view, incoming.content);
		this.didShow = function() {};
	}
};

Event.onDOMReady(function() {
	// set up the view masters
	var hero = new AC.ViewMaster.Viewer($$('a.herolink'), 'hero', 'herolink', { silentTriggers:true });
	hero.setDelegate(Object.extend(delegate, {
		willShow: function(view, outgoing, incoming) {
			var show = incoming.id.match(/^hero-\d$/) ? true : false;
		}
	}));
	var mouse = new AC.ViewMaster.Viewer($$('.gallery-mouse-sections'), 'gallery-mouse', 'gallery-mouse', { silentTriggers:true });
	mouse.setDelegate(delegate);
	var tracker = new AC.ViewMaster.Tracker('click');
});
