if (typeof(FOH) == "undefined") FOH = {};





FOH.Data = Class.create();
FOH.Data.prototype = {

	initialize: function(tutorials, tips) {
		var tutorials = new FOH.Data.Tutorials(tutorials);
		this.tutorials = tutorials.items;

		var tips = new FOH.Data.Tips(tips);
		this.tips = tips.items;
	}

};





FOH.Data.General = Class.create();
FOH.Data.General.prototype = {

	// the functions
	initialize: function(array) {
		this.items = {};
		this.parseHTML(array);
	},

	parseHTML: function(array) {
		for (var i=0; i<array.length; i++) {
			var item = $(array[i]);
			if (item.id) {
				var category = item.up('.category');

				if (!this.items[category.id]) this.items[category.id] = this.setCategory(category);
				if (!this.items[category.id].items) this.items[category.id].items = {};

				if (item.id) this.items[category.id].items[item.id] = this.setItem(item);
			}
		}
	},

	// item functions
	setId: function(data) {
		var item = {};

		item.id = data.getAttribute('id') || false;

		return item;
	},

	setCategory: function(data) {
		var item = this.setId(data);

		var title = data.down('h3') || false;
		item.title = (title) ? title.innerHTML.stripTags().strip() : false;

		return item;
	},

	setItem: function(data) {
		var item = this.setId(data);
		
		return item;
	},

	setGallery: function(data) {
		var galleryData = data.down('.gallery') || false;
		if (!galleryData) return false;

		var caption = data.down('.caption');
		var nav = data.getElementsBySelector('ul.nav li');

		var gallery = {
			html: (caption) ? caption.innerHTML.strip() : false,
			images: (nav) ? nav : false
		};
		
		return gallery;
	}

};





FOH.Data.Tutorials = Class.create();
Object.extend(FOH.Data.Tutorials.prototype, FOH.Data.General.prototype);
Object.extend(FOH.Data.Tutorials.prototype, {

	// item functions
	setItem: function(data) {
		var item = this.setId(data);
		
		var title = data.down('a.movielink') || false;
		item.title = (title) ? title.innerHTML : false;

		item.node = data;

		item.video = this.setVideo(data);
		item.gallery = this.setGallery(data);

		return item;
	},

	setVideo: function(data) {
		var url = data.down('a.movielink') || false;
		var poster = data.down('.poster') || false;
		var endState = data.down('.endstate') || false;
		var phobos = data.down('.ituneslink') || false;

		var video = {
			url: (url) ? url.href : false,
			posterFrame: (poster) ? poster.innerHTML.match(/src="(.*)"/)[1] : false,
			endState: (endState) ? endState.innerHTML.strip() : false,
			phobos: (phobos) ? data.down('.ituneslink') : false
		};

		return video;
	}

});





FOH.Data.Tips = Class.create();
Object.extend(FOH.Data.Tips.prototype, FOH.Data.General.prototype);
Object.extend(FOH.Data.Tips.prototype, {

	// item functions
	setItem: function(data) {
		var item = this.setId(data);
		
		var title = data.down('a') || false;
		item.title = (title) ? title.innerHTML : false;

		item.node = data;

		item.gallery = this.setGallery(data);

		return item;
	}

});





FOH.Cookies = Class.create();
FOH.Cookies.prototype = {
	data: [],

	initialize: function() {
		this.read();
	},
	
	resetData: function() {
		this.data = this.data.uniq();
		this.string = this.data.join(',');
	},
	
	read: function() {
		var cookies = document.cookie.split(';');
		
		for (var i=0; i<cookies.length; i++) {
			var cookie = cookies[i];

			if (cookie.match(/findouthow/i)) {
				var seen = cookie.substring(cookie.indexOf('=')+1, cookie.length).split(',');
				for (var j=0; j<seen.length; j++) {
					if (seen[j] != '') this.data.push(seen[j]);
				}

				this.resetData();
				return;
			}
		}
	},
	
	set: function(id) {
		// set cookie to expire in 1 week
		var date = new Date();
		date.setDate(date.getDate()+7);

		// comma delimited to sort later
		this.string = this.data.join(',');
		if (this.string.match(id) == null) {
			this.string = (this.string != '') ? this.string+','+id : id;
		}

		// set the cookie		
		document.cookie = 'findouthow='+this.string+'; expires='+date.toGMTString()+'; path=/; domain=apple.com';

		// remember we added it		
		this.data.push(id);
		this.resetData();
	},
	
	isSet: function(id) {
		if (!this.string) this.resetData();
		return this.string.match(id);
	}

};





FOH.Swap = Class.create();
FOH.Swap.prototype = {
	type: false,
	lastTrigger: null,
	
	getCategoryAndId: function(search) {
		if (typeof(search) == 'object') {
			if (search.category && search.item) return search;
			if (search.tagName.toLowerCase() != 'a') search = search.down('a');
			search = search.href.substring(search.href.indexOf('#')+1, search.href.length);
		}

		var category = search.split('-')[0];
		var item = search.split('-')[1];

		return { category:category, item:item, string:category+'-'+item };
	},

	initialize: function(data, panels, options) {
		this.data = data;
		this.panels = panels;
		
		this.docTitle = document.title;

		this.init(options);
		this.setNav();

		// to do, # jump to that state
	},

	init: function(options) {
	},

	setNav: function() {
		this.nav = [];

		for (category in this.data) {
			var nav = [];

			// lame... this hacky loop instead of a normal one because IE was failing on
			//for (item in this.data[category].items) {
			var keys = Object.keys(this.data[category].items);
			var values = Object.values(this.data[category].items);
			for (var i=0; i<keys.length; i++) {
				var item = keys[i];
				var data = values[i];

				var trigger = data.node;
				this.nav.push(trigger);
				this.fixNavLink({ category:category, item:item }, trigger);
				this.setNavEvent(data, trigger);

				this.cookies = new FOH.Cookies();
				if (this.cookies.isSet(category+'-'+item)) this.setNavVisited(trigger);
			}
		}
	},

	fixNavLink: function(id, trigger) {
		if (!trigger.href) trigger = trigger.down('a') || false;
		if (trigger.href) trigger.href = "#"+id.category+'-'+id.item;
	},

	setNavEvent: function(data, node) {
		var item = node;
		var link = node.down('a') || item;

		Event.observe(link, 'click', this.activateItem.bind(this, item));
	},

	setNavVisited: function(trigger) {
		if (!trigger) return;
		if (!trigger.hasClassName('visited')) trigger.addClassName('visited');

		if (!trigger.href) trigger = trigger.down('a') || false;
		if (trigger) {
			var id = trigger.href.replace(/.*#/, '');
			if (this.cookies) this.cookies.set(id);
		}
	},

	setNavActive: function(trigger) {
		if (this.lastTrigger) {
			if (this.lastTrigger.hasClassName('active')) this.lastTrigger.removeClassName('active');
		}
		
		if (trigger) {
			trigger.addClassName('active');
			this.lastTrigger = trigger;
		}
	},

	activateItem: function(trigger, options) {
		this.resetExternal(trigger);
		this.resetInternal(trigger);

		this.setNavActive(trigger);
		this.setNavVisited(trigger);

		this.activate(trigger, options);

		this.updateTitle(trigger);
		this.trackClick(trigger);
	},

	activate: function(trigger) {
	},

	resetExternal: function(trigger) {
	},

	resetInternal: function(trigger) {
		this.resetWrapper(trigger);
		this.reset(trigger);
	},

	resetWrapper: function(trigger) {
		if (this.panels.wrapper) this.panels.wrapper.className = '';
	},

	reset: function(trigger) {
	},

	updateTitle: function(trigger) {
		var title = trigger.innerHTML.stripTags();
		var id = this.getCategoryAndId(trigger);
		if (this.data[id.category]) {
			var category = this.data[id.category];
			if (category) {
				title = '';
				if (category.title) title += category.title+' - ';
				if (category.items) title += category.items[id.item].title;
			}
		}
		document.title = this.docTitle +' - '+title;
	},

	trackClick: function(trigger, custom, click) {
		if (!trigger) return;

		// get clicked link
		if (typeof(trigger.nodeType) == 'undefined') {
			var id = trigger;
		} else {
			var link = trigger;
			if (!link.href) link = link.down('a');
			if (!link.href) link = link.up('a');
			var id = this.getCategoryAndId(link);
		}

		var options = (typeof(this.trackOptions) == 'function') ? this.trackOptions(id) : {};
		options.pageName = AC.Tracking.pageName();
		
		// prop6 and 13 get the link + doc title
		var string = '';
		if (custom) {
			string += custom+': ';
		} else if (this.type) {
			string += this.type+': ';	
		} 
		string += AC.Tracking.pageName();
		string = string.replace('Apple - ', '');

		options.prop13 = string;

		// try {
		// 	for (something in options) {
		// 		console.log(something+': '+options[something]);
		// 	}
		// } catch(e) {}
		if (click) {
			options.prop4 = null;
			AC.Tracking.trackClick(options, this, 'o', custom || '');
		} else {
			AC.Tracking.trackPage(options);
		}
	}

};





FOH.Swap.Gallery = Class.create();
Object.extend(FOH.Swap.Gallery.prototype, FOH.Swap.prototype);
Object.extend(FOH.Swap.Gallery.prototype, {
	updateTitle: function() {},
	trackClick: function() {},

	init: function(options) {
		if (!options) options = {};
		this.id = options.id;
		this.defaultIndex = (typeof(options.defaultIndex) == 'number') ? options.defaultIndex : parseInt(0);

		this.setCaption();
	},

	setCaption: function() {
		var caption = Builder.node('div', { className:'caption' })
		caption.innerHTML = this.data.html;
		this.panels.appendChild(caption);
	},

	setNav: function() {
		this.nav = [];

		var list = Builder.node('ul', { className:'nav' });
		this.panels.appendChild(list);

		for (var i=0; i<this.data.images.length; i++) {
			var data = this.data.images[i];

			var trigger = data.cloneNode(true);
			list.appendChild(trigger);

			this.nav.push(trigger);
			this.fixNavLink(i, trigger);
			this.setNavEvent(null, trigger);
		}

		// default state
		if (this.nav[this.defaultIndex]) {
			this.activateItem(this.nav[this.defaultIndex]);
		} else {
			this.activateItem(this.nav[0]);
		}
		if (typeof(this.trackGallery) == 'function') this.trackGallery();
	},

	fixNavLink: function(index, trigger) {
		if (!trigger.href) trigger = trigger.down('a') || false;
		if (trigger.href) trigger.href = '#'+this.id.category+'-'+this.id.item+'-gallery'+index;
	},

	activate: function(item) {
		if (!item) return;

		var index = item.down('a').href;
		index = index.substring(index.indexOf('-gallery')+8, index.length);
		var data = this.data.images[index] || false;
		var src = (data.down('a')) ? data.down('a').href : false;
		
		if (!this.image) {
			this.image = Builder.node('img', { src:src, className:'swapimage' });
			this.panels.appendChild(this.image);
		} else {
			this.image.src = src;
		}
	}

});





FOH.Swap.Tutorials = Class.create();
Object.extend(FOH.Swap.Tutorials.prototype, FOH.Swap.prototype);
Object.extend(FOH.Swap.Tutorials.prototype, {

	type: 'V@S',
	currentId: null,
	lastId: null,
	movieOptions: {
		width: 640,
		height: 400,
		autoplay: false,
		controller: false,
		showlogo: false
	},

	activate: function(trigger) {
		var id = this.getCategoryAndId(trigger);

		// set the class name so we can resize the movie
		this.panels.wrapper.addClassName('movie');

		// set the and other info
		this.setCurrentId(id);

		this.setMovieLinks(id);
		this.setMovie(this.data[id.category].items[id.item].video.url);
		
		this.setLastId(id);
	},

	activateExternal: function(trigger) {
		trigger = (trigger.down('a')) ? trigger.down('a') : trigger;
		trigger = trigger.href.toString();
		trigger = trigger.substring(trigger.indexOf('#')+1, trigger.length);

		for (var i=0; i<this.nav.length; i++) {
			var link = (this.nav[i].down('a')) ? this.nav[i].down('a') : this.nav[i];
			link = link.href.toString();
			link = link.substring(link.indexOf('#')+1, link.length);

			if (trigger == link) this.activateItem(this.nav[i]);
		}
	},

	setCurrentId: function(id) {
		this.currentId = id;
	},

	setLastId: function(id) {
		this.lastId = id;
	},

	setMovieAlernate: function(url) {
		if (!AC.Detector.isValidQTAvailable('7')) {
			this.panels.movie.display.innerHTML = 
				'<div id="noqt">\
					<a href="/uk/quicktime/download/"><img src="http://images.apple.com/global/elements/quicktime/getquicktime.gif" alt="Get QuickTime, Free Download" width="88" height="31" border="0" class="across"></a>\
					<p><a href="/uk/quicktime/download/">QuickTime 7</a> Required.</p>\
				</div>';
		} else {
			return true;
		}
	},

	setMovie: function(url) {
		// setup the movie/controller if we don't have them already
		if (!this.movieController) {
			if (this.setMovieAlernate()) {
				this.panels.movie.controller.innerHTML = '';
	
				// setup the movie
				var movie = AC.Quicktime.packageMovie('fohmovie', url, this.movieOptions);
				this.panels.movie.display.appendChild(movie);
	
				// setup the controller
				this.movieController = new AC.QuicktimeController(movie, {
					onMoviePlayable: function() {
						this.movieController.monitorMovie();
	
						// in essence, autoplay (timeout because JS is faster than the QT plugin)
						this.movieController.Play();
	
						// set the finished callback (timeout because JS is faster than the QT plugin)
						setTimeout(function() {
							this.movieController.options.onMovieFinished = this.movieFinished.bind(this);
						}.bind(this), 1000);
					}.bind(this)
				});
				this.movieController.render(this.panels.movie.controller);
	
				movie = null; // for IE
	
			}
		// otherwise just set the url, and play
		} else {

			// if the urls don't match, set it
			if (this.lastId.string != this.currentId.string) {
				this.movieController.SetURL(url);
			}
			
			// in essence, autoplay (timeout because JS is faster than the QT plugin)
			setTimeout(function() {
				if (!this.movieController.isPlaying()) this.movieController.Play();
			}.bind(this), 300);

			// reset the finished callback (timeout because JS is faster than the QT plugin)
			setTimeout(function() {
				this.movieController.options.onMovieFinished = this.movieFinished.bind(this);
			}.bind(this), 1000);
		}
	},

	setMovieLinks: function(id) {
		this.setPhobosLink(this.data[id.category].items[id.item].video.phobos);
		this.setGalleryLink(this.data[id.category].items[id.item].gallery);
	},

	setPhobosLink: function(phobos) {
		var wrapper = this.panels.movie.links.phobos;

		// only set add the link if we don't have it already
		if (phobos && wrapper.innerHTML == '') {
			var clone = phobos.cloneNode(true);
			wrapper.appendChild(clone);
		}
	},

	setGalleryLink: function(gallery) {
		var trigger = this.panels.movie.links.gallery;
		if (gallery) {
			// set the href to what we want
			trigger.href = '#'+this.currentId.string+'-gallery';

			// only set the url and event if we haven't before
			if (!this.galleryTriggerFlag) {
				Event.observe(trigger, 'click', this.setGallery.bind(this));
				this.galleryTriggerFlag = true;
			}

			// set it to show up
			trigger.style.display = 'block';
		}
	},

	setGallery: function(index) {
		this.resetMovie();
		this.resetMovieLinks();
		this.panels.wrapper.addClassName('gallery');

		var data = this.data[this.currentId.category].items[this.currentId.item].gallery;
		var gallery = new FOH.Swap.Tutorials.Gallery(data, this.panels.gallery, { id:this.currentId, defaultIndex:index });
		
		Event.observe(gallery.backLink, 'click', this.backToMovie.bind(this));
	},

	backToMovie: function() {
		var beforeState = this.panels.wrapper.className.toString().replace('gallery', '').strip();
		beforeState = beforeState.replace('thankyou', '').strip();

		this.resetWrapper();
		this.resetMovie();
		this.resetMovieLinks();
		this.resetGallery();

		// activate the click to play state if that's what we were last looking at
		if (beforeState == 'loading') {
			this.setMovieLinks(this.currentId);
			this.panels.wrapper.addClassName('loading');

		// activate the end state if that's what we were last looking at
		} else if (beforeState == 'endstate') {
			this.activate(this.currentId);
			this.setEndState();

		// otherwise, just show the movie like normal
		} else {
			this.resetExternal(this.data[this.currentId.category].items[this.currentId.item].node);
			this.activate(this.currentId);
		}
	},

	movieFinished: function() {
		// prevent the user from jogging back into movie once controller is hidden
		this.movieController.hardPaused = true;
		this.setEndState();
	},

	setEndState: function() {
		this.resetWrapper();
		this.resetMovie();
		this.resetEndState();
		
		var wrapper = this.panels.movie.endState;
		
		// set the endstate: image and pill buttons
		var currentItem = this.data[this.currentId.category].items[this.currentId.item];
		var replay = Builder.node('p', { className:'pillbutton replay' }, [
			Builder.node('a', { href:document.location}, [
				Builder.node('span', 'Watch again'),
				Builder.node('b', '&gt;')
			])
		]);
		wrapper.innerHTML = currentItem.video.endState;

		var first = wrapper.down('p');
		if (first) {
			wrapper.insertBefore(replay, first);
		} else {
			wrapper.appendChild(replay);
		}
		
		// set the event on the replay button
		var replay = wrapper.getElementsByClassName('replay')[0];
		Event.observe(replay, 'click', this.replay.bind(this));

		this.panels.wrapper.addClassName('endstate');
		
		this.trackClick(this.currentId, 'V@E', true);
	},

	replay: function() {
		this.resetWrapper();
		this.reset();
		this.activate(this.currentId);

		this.trackClick(this.currentId, 'V@R', true);
	},

	reset: function() {
		this.resetGallery();
		this.resetMovie();
		this.resetEndState();
		this.resetMovieLinks();
	},

	resetGallery: function() {
		document.title = document.title.toString().replace(' - Gallery', '');
		this.panels.gallery.innerHTML = '';
	},

	resetMovie: function() {
		if (this.movieController) {
			this.movieController.options.onMovieFinished = null;
			this.movieController.Stop();
			//if (AC.Detector.isWebKit()) this.movieController.SetURL('http://images.apple.com/global/elements/blank.gif');
		}
	},

	resetEndState: function() {
		this.panels.movie.endState.innerHTML = '';
	},

	resetMovieLinks: function() {
		this.panels.movie.links.phobos.innerHTML = '';
		this.panels.movie.links.gallery.style.display = '';
	},

	trackOptions: function(id) {
		var category = this.data[id.category] || false;
		if (category) {
			if (category.items) var item = category.items[id.item] || false;
			if (item) {
				if (item.video) {
					return { prop4: item.video.url };
				}
			}
		}

		return {};
	}

});





FOH.Swap.Tutorials.Gallery = Class.create();
Object.extend(FOH.Swap.Tutorials.Gallery.prototype, FOH.Swap.Gallery.prototype);
Object.extend(FOH.Swap.Tutorials.Gallery.prototype, {

	setCaption: function() {
		var caption = Builder.node('div', { className:'caption' })
		caption.innerHTML = '<h3>Related gallery</h3>\n'+this.data.html;
		this.panels.appendChild(caption);
		this.setBackLink();
	},

	setBackLink: function() {
		this.backLink = Builder.node('a', { id:this.panels.id+'-back', href:'#'+this.id.string }, 'Back to video');
		this.panels.appendChild(this.backLink);
	},

	updateTitle: function(trigger) {
		var title = 'Gallery';
		document.title = this.docTitle +' - '+title;
	},
	
	trackGallery: function() {
		var options = {
			pageName: document.title
		};
		
		AC.Tracking.trackPage(options);
	}

});





FOH.Swap.Tutorials.Featured = Class.create();
Object.extend(FOH.Swap.Tutorials.Featured.prototype, FOH.Swap.prototype);
Object.extend(FOH.Swap.Tutorials.Featured.prototype, {
	updateTitle: function() {},
	trackClick: function() {},

	init: function(data) {
		this.nav = data.nav;
		this.tutorials = data.tutorials;
	},

	setNav: function() {
		for (var i=0; i<this.nav.length; i++) {
			var trigger = this.nav[i];
			this.setNavEvent(null, trigger);
		}
	},

	setNavActive: function(trigger) {
		if (typeof(trigger) == 'string') {
			for (var i=0; i<this.nav.length; i++) {
				var link = this.nav[i].down('a') || this.nav[i];
				var href = link.href;

				// remove the active class
				if (this.nav[i].hasClassName('active')) this.nav[i].removeClassName('active');

				// remove the now playing
				link.innerHTML = link.innerHTML.replace(/<span>Now Playing<\/span>/i, '');
	
				if (href.match(trigger)) {
					this.nav[i].addClassName('active');
					link.update(link.innerHTML+'<span>Now Playing</span>');
				}
			}
		}
	},

	activate: function(trigger) {
		this.tutorials.activateExternal(trigger);
	},

	reset: function(trigger) {
		trigger = (trigger.down('a')) ? trigger.down('a').href : trigger.href;
		trigger = trigger.substring(trigger.indexOf('#')+1, trigger.length);
		this.setNavActive(trigger);
	}

});





FOH.Swap.Tips = Class.create();
Object.extend(FOH.Swap.Tips.prototype, FOH.Swap.prototype);
Object.extend(FOH.Swap.Tips.prototype, {
	type: 'Text',

	activate: function(trigger, galleryOptions) {
		var id = this.getCategoryAndId(trigger);
		var data = this.data[id.category].items[id.item];
		
		this.setGallery(id, data.gallery, galleryOptions.defaultIndex);
	},

	setGallery: function(id, gallery, defaultIndex) {
		this.resetInternal();
		this.panels.wrapper.addClassName('tips');

		this.gallery = new FOH.Swap.Gallery(gallery, this.panels.display, { id:id, defaultIndex:defaultIndex });
	},

	reset: function() {
		this.panels.display.innerHTML = '';
	},

	trackOptions: function(id) {
		var url = document.location.toString().replace(/#.*/, '');
		return { prop4: url+'#'+id.string };
	}

});





FOH.Init = function(xmlUrl) {

	// get most of the DOM
	var wrapper = $('swap');
	var panels = {
		tutorials: {
			wrapper: wrapper,
			movie: {
				wrapper: $('swap-quicktime'),
				display: $('swap-qt-movie'),
				controller: $('swap-qt-controller'),
				endState: $('swap-qt-endstate'),
				links: {
					phobos: $('swap-qt-links-itunes'),
					gallery: $('swap-qt-links-gallery').down('a')
				}
			},
			gallery: $('swap-gallery')
		},
		tips: {
			wrapper: wrapper,
			display: $('swap-tips')
		}
	};

	// get the data
	var data = new FOH.Data($$('#subnav #video .category ul li'), $$('#subnav #text ul li'));

	// set up all the important stuff
	var tutorials = new FOH.Swap.Tutorials(data.tutorials, panels.tutorials);
	var featuredtutorials = new FOH.Swap.Tutorials.Featured(data, $('swap-featured'), { nav:$$('#swap-featured li'), tutorials:tutorials });
	var tips = new FOH.Swap.Tips(data.tips, panels.tips);
	

	function setUpSplashScreen(panels, tutorials, tips) {
		// fake the controller on load
 		var tempcontroller = new AC.QuicktimeController();
		tempcontroller.render(panels.tutorials.movie.controller);

		var play = panels.tutorials.movie.controller.getElementsByClassName('control')[0];

		// set the click to play
		var links = panels.tutorials.movie.endState.getElementsBySelector('a');
		for (var i=0; i<links.length; i++) {
			var link = links[i];
			Event.observe(link, 'click', tutorials.activateExternal.bind(tutorials, link));
			
			if (link.innerHTML.match(/click to play/i)) {
				play.href = link.href;
				Event.observe(play, 'click', tutorials.activateExternal.bind(tutorials, play));
			}
		}
	
		// set the initial itunes/gallery links
		if (links.length>0) {
			var defaultId = links[0].href.replace(/.*#/, '');
			defaultId = {
				category: defaultId.split('-')[0],
				item: defaultId.split('-')[1],
				string: defaultId
			}
	
			tutorials.setCurrentId(defaultId);
			tutorials.setMovieLinks(defaultId);
		}
	}



	// reset the tutorials
	tutorials.resetExternal = function(trigger) {
		this.resetInternal();
		this.setNavActive(null);
		featuredtutorials.resetInternal(trigger);
	}.bindAsEventListener(tips, featuredtutorials);


	if (document.location.hash) {

		// trigger the movie/tip if we were linked to something specfic
		var defaultString = document.location.toString().replace(/.*#/, '');
		if (defaultString.split('-').length>2) {
			if (defaultString.split('-')[2].match('gallery')) {
				var defaultGallery = parseInt(defaultString.split('-')[2].replace('gallery', '')) || parseInt(0);
			}
		}

		var defaultId = {
			category: defaultString.split('-')[0],
			item: defaultString.split('-')[1],
			string: defaultString.split('-')[0]+'-'+defaultString.split('-')[1]
		}
		
		var trigger = $$('#main #'+defaultId.category+' #'+defaultId.item)[0];
		var type = (trigger) ? (trigger.up('.type')) ? trigger.up('.type').id || false : false : false;

		// trigger tutorial
		if (type == 'video') {
			tutorials.setCurrentId(defaultId);

			// trigger tutorial gallery
			if (typeof(defaultGallery) == 'number') {
				panels.tutorials.wrapper.className = 'movie';
				tutorials.setGallery(defaultGallery);

			// trigger tutorial
			} else {
				tutorials.activateItem(trigger);
			}

		// trigger tip
		} else if (type == 'text') {
			tips.activateItem(trigger, { defaultIndex:defaultGallery });
		} else {
			setUpSplashScreen(panels, tutorials, tips);
		}
	} else {
		setUpSplashScreen(panels, tutorials, tips);
	}


	// reset the tips after we know we have one aleady
	tips.resetExternal = function() {
		this.resetInternal();
		this.setNavActive(null);
	}.bind(tutorials);

};
Event.onDOMReady(FOH.Init);
