
var ExpandBox = Class.create({
	container: null,
	trigger: null,
	display: null,
	
	toggleDisplay: function () {
		Effect.toggle(this.display, 'blind');
	},
	
	initialize: function(container) {
		this.container = container;
		
		this.trigger = container.select('h2').first();
		this.display = container.select('.faq-text').first();
		this.trigger.observe('click', this.toggleDisplay.bind(this));
	}
});

var GoogleDownloadTracker = Class.create({
	links: null,
	
	setHandler: function (item) {
		itemHref = item.readAttribute('href');
		itemHref = itemHref.slice(itemHref.lastIndexOf('/')+1);
		pathToTrack = this.pathToTrack + itemHref;
		
		// Set onclick event handler for Google Analytics
		if (pageTracker) {
			item.observe('click', function (event) {
				pageTracker._trackPageview(pathToTrack);
			})
		}
	},
	
	initialize: function(container) {
		try {
			this.baseUrl = window.location.protocol + "//" + window.location.hostname;
			this.pathToTrack = window.location.href.replace(this.baseUrl, "");
			this.links = $$('a[href$=".pdf"], a[href$=".PDF"]');
			this.links.each(function (item) {
				this.setHandler(item);
			}.bind(this));
		} catch (e) {
			if (Object.isFunction(console.log)) {
				console.log(e);
			}
		}
	}
});


Event.observe(document, "dom:loaded", function (event) {
	$$('.faq-list .faq-item').each( function (container) {
		new ExpandBox(container);
	});
	
	new GoogleDownloadTracker();
});