﻿var FAQBrowser = new Class({
	initialize : function() {

	},
	openFAQ : function(xmlName) {
		var faqRequest = new Request({
			url: 'xml/faq/' + xmlName + '.xml',
			method: 'get',
			onSuccess: function(responseText, responseXML) {
				$('faqbody').empty();
				// Fill in sections
				responseXML.getElements('section').each(function (item, index, array) {
					$('faqbody').adopt(
						new Element('div', { 'class': 'faqheader' }).adopt(
							new Element('div', { 'class': 'downarrow png' })
						).adopt(
							new Element('h2', { html: item.getProperty('title') })
						)
					).adopt(
						new Element('div', { 'class': 'faqdl' }).adopt(
							new Element('dl')
						)
					);
					// Fill in questions
					item.getChildren().each(function (item, index, array) {
						if (item.get('tag') == 'question') {
							$('faqbody').getLast('div').getLast('dl').adopt(
								new Element('dt', { text: item.get('text') })
							);
						} else {
							$('faqbody').getLast('div').getLast('dl').adopt(
								new Element('dd', { html: item.get('text') })
							);
						}
					}, this);
				}, this);

				$('faqcontainer').setStyle('display', 'block');
			}
		});
		faqRequest.send();
	},
	openPage : function(productName) {
		if (productName == 'desktop' || productName == 'games' || productName == 'tools') {
			var urlLoc = 'products/' + productName + '.aspx';
		} else {
			var urlLoc = 'products/' + productName + '/';
		}
		var pageRequest = new Request({
			url: urlLoc,
			method: 'get',
			onSuccess: function(responseText, responseXML) {
				$('faqcontainer').set('html', responseText);
				var mySlide = new Fx.Slide('faqcontainer', { mode: 'horizontal' }).hide()
				var myFx = new Fx.Scroll(window).toBottom().chain(function() {
					mySlide.toggle();
				});
			}
		});
		pageRequest.send();
	}
});