﻿$(document).ready(function() {

	// FAQ
	faqCategories();
	faqQuestions();

});


function faqCategories() {
	// When an category is clicked, open it - and close the rest
	$(".faq-head").click(function() {

		// Get the id of the object
		var object = this.id;
		var variable = object.substr(13, 2);

		// Walk tru the objects
		for (teller = 1; teller <= 6; teller++) {
			if (teller == variable) {

				// Open the clicked one
				opencategory(teller);
			} else {
				// Otherwise close it
				closecategory(teller);
			}
		}
	});
}
function faqQuestions() {
	// When an item is clicked, open it - and close the rest
	$(".faq-link-closed").click(function() {

		// Get the id of the object
		var object = this.id;
		var variable = object.substr(16, 2);

		// Walk tru the objects
		for (teller = 1; teller <= 20; teller++) {
			if (teller == variable) {

				// Open the clicked one
				open(teller);
			} else {

				// Otherwise close it
				close(teller);
			}
		}
	});
}

// close all categories and all questions
function closeAll() {
	// Walk tru the objects
	for (teller = 1; teller <= 6; teller++) {
		closecategory(teller);
	}
	// Walk tru the objects
	for (teller = 1; teller <= 20; teller++) {
		close(teller);
	}
}
// open a category
function opencategory(counter) {
	// close all categories and all questions
	closeAll();
	$("#faq-subquestions-" + counter).show("fast");
	var object = $("#faq-subquestions-" + counter).children(":first").attr("id");
	open(object.substr(4, 2));
};

// close a category
function closecategory(counter) {
	$("#faq-subquestions-" + counter).hide("fast");
};

// open a question
function open(counter) {
	$("#faq-text-" + counter).show("fast");
	$("#faq-" + counter).removeClass("faq-closed").addClass("faq-open");
};

// close a question
function close(counter) {

	$("#faq-text-" + counter).hide("fast");
	if ($("#faq-" + counter).hasClass("faq-open")) {
		$("#faq-" + counter).removeClass("faq-open").addClass("faq-closed");
	}
};

