var specialinterest = new SpecialInterest();

/**
 * SpecialInterest
 * @extends Page
 * @constructor
 */
function SpecialInterest()
{
	// Call the prototype's constructor
	Page.call(this);

	// Private
	var self			= this,
		dom				= new DOM();

	// Public
	this.showProductCollection = showProductCollection;

	// Constructor
	self.addEventListener(Page.LOADED, addCollectionToggle);

	/**
	 * Adds a toggle to the collection variants.
	 */
	function addCollectionToggle()
	{
		var collection = dom.getById("layout_content").getByClassName("collection_textlinks", "div");

		for (i = 0; i < collection.length; i++)
		{
			if (collection[i].getFirstByTagName("ul") == null)
			{
				var links = collection[i].childNodes;

				if (links.length > 7)
				{
					var	linkContainer = dom.create(
						"span",
						null,
						null
						);

					while (links.length > 6)
					{
						linkContainer.appendChild(links[6]);
					}

					collection[i].appendChild(linkContainer);

					var toggle = dom.create(
						"a", 
						{
							href		: "#",
							className	: "collections_more_variants",
							onclick 	: (function(target)
							{
								return function()
								{
									showProductCollection(this, target);
									return false;
								};
							})(linkContainer)
						},
						[
							"Meer varianten"
						]
					);

					collection[i].appendChild(dom.createText(", "));
					collection[i].appendChild(toggle);
				}
			}
		}

		
		return false;
	}



	/*
	 * Toggles productcollection
	 * @param {Object} toggle the toggle object
	 * @param {Object} target the target object
	 */
	function showProductCollection(toggle,target){
		var toggle = toggle,
			target = target;

		if (target) {
			if (toggle.hasClass("active")) {
				toggle.removeClass("active");
				target.removeClass("active");
				toggle.innerHTML = "Meer varianten";
			} else {
				toggle.addClass("active");
				target.addClass("active");
				toggle.innerHTML = "Minder varianten";
			}
		}
	
		return false;		
	}
}


// Inheritance
SpecialInterest.prototype = new Page();
controller.setPageObject(specialinterest);
