function TabbedNavigation(navigation) {
	this.current = 0;
	this.tabLinks = navigation.select("a");
	this.initTabPanes();
	this.initTriggers();
}

TabbedNavigation.prototype = {
	initTabPanes: function() {
		var panes = new Array();
		
		for (i=0; i<this.tabLinks.length; i++) {
			Event.observe(this.tabLinks[i], "click", this.switchActiveTab.bindAsEventListener(this, i));
			
			var paneId = this.tabLinks[i].href.substring(this.tabLinks[i].href.indexOf("#") + 1);
			panes[panes.length] = paneId;
			
			if (Element.hasClassName(this.tabLinks[i].up("li"), "active")) {
				// currently active tab
				this.current = i;
			} 
		}
		this.tabPanes = panes;
		
		// initial hide tabpanes
		for (i=0; i<this.tabPanes.length; i++) {
			if ($(this.tabPanes[i])) {
				Element.addClassName($(this.tabPanes[i]), "disabled");
			}
		}
		
		this.switchActiveTab(null, this.current);
	},
	
	initTriggers: function()
	{
		Event.observe("trigger-suppliers",		"click", this.switchActiveTab.bindAsEventListener(this, 1));
		Event.observe("trigger-specifications",	"click", this.switchActiveTab.bindAsEventListener(this, 2));
	},
	
	switchActiveTab: function(e, newActiveTab) {
		for (i=0; i<this.tabLinks.length; i++) {
			Element.removeClassName(this.tabLinks[i].up("li"), "active");
			
			if ($(this.tabPanes[i]))
			{
				Element.removeClassName($(this.tabPanes[i]), "enabled");
				Element.addClassName($(this.tabPanes[i]), "disabled");
			}
		}
		
		// enable active element
		Element.addClassName(this.tabLinks[newActiveTab].up("li"), "active");
		
		if ($(this.tabPanes[newActiveTab]))
		{
			Element.removeClassName($(this.tabPanes[newActiveTab]), "disabled");
			Element.addClassName($(this.tabPanes[newActiveTab]), "enabled");
		}
		
		this.current = newActiveTab;
		
		if (e) {
			Event.stop(e);
		}
	}
}

Event.observe(window, "load", function() {
	/* 
		Tabbed navigation init
	*/
	
	/*
	$$(".tabbed-nav").each(function(el) {
		new TabbedNavigation(el);
	});
	*/
	
	/* 
		Product page: 
		Complete "vergelijkbare producten" product block is clickable to 
		toggle checkbox. When clicking a link the script will be cancelled and 
		the link will be followed.
	*/
	$$(".comparable .product").each(function(el) {
		var checkboxDiv = Element.select(el, ".checkbox").first();
		
		checkboxDiv.style.paddingTop	= Math.floor(el.getHeight() / 2 - 10) + "px";
		checkboxDiv.style.height		= Math.floor(el.getHeight() / 2 + 10) + "px";
		
		Event.observe(checkboxDiv, "click", function(e) {
			var checkbox = Element.select(el, "input[type='checkbox']").first();
			if (Event.findElement(e, "input") == checkbox) {
				if (checkbox.checked) {
					Element.addClassName(el, "checked");
				} else {
					Element.removeClassName(el, "checked");
				}
			} else {
				if (checkbox.checked) {
					checkbox.checked = false;
					Element.removeClassName(el, "checked");
				} else {
					checkbox.checked = true;
					Element.addClassName(el, "checked");
				}
			}
		});
	});
	
	/*
		Recently viewed
	*/
	if (typeof Tooltip != "undefined") {
		$$("#recently-viewed li a").findAll(function(node) {
			return node.getAttribute('title');
		}).each(function(node) {
			new Tooltip(node,node.title);
		    node.removeAttribute("title");
			var imgs = node.getElementsByTagName("img");
			if (imgs) {
				for (i=0; i<imgs.length; i++) {
					imgs[i].removeAttribute("alt");
				}
			}
		});
		$$(".table-suppliers .payment-options li img").findAll(
			function(node) {
				return node.getAttribute('alt');
			}).each(function(node) {
				new Tooltip(node, node.alt);
				node.removeAttribute("alt");
			}
		);
		$$(".table-suppliers .certification li img").findAll(
			function(node) {
				return node.getAttribute('alt');
			}).each(function(node) {
				new Tooltip(node, node.alt);
				node.removeAttribute("alt");
			}
		);
		$$(".table-suppliers .pick-up img").findAll(
			function(node) {
				return node.getAttribute('alt');
			}).each(function(node) {
				new Tooltip(node, node.alt);
				node.removeAttribute("alt");
			}
		);
	}
	
	/* 
		Search field
		- clear the search field's value when it gets focused on
		- set its value back to its default value* when it gets blurred on, and no value has been enterd
		
		* no defaultValue property is available, use getAttribute('value') instead - no alias for getValue()!
	*/
	
	$('search-keyword').observe('focus', function(e) {
		if (this.getAttribute('value') == this.getValue()) {
			this.clear();
		}
		Event.stop(e);
	});
	$('search-keyword').observe('blur', function(e) {
		if (this.getValue() == "") {
			this.setValue(this.getAttribute('value'));
		}
		Event.stop(e);
	});
});


/*
function TabbedNavigation(navigation, handlers) {
	this.current = 0;
	this.tabLinks = navigation.select("a");
	
	var customHandlers = Object.extend(
		{},
		handlers || {}
	);
	this.customHandlers = customHandlers;
	
	this.initTabPanes();
}

TabbedNavigation.prototype = {
	initTabPanes: function() {
		var panes = new Array();
		
		for (i=0; i<this.tabLinks.length; i++) {
			Event.observe(this.tabLinks[i], "click", this.switchActiveTab.bindAsEventListener(this, i));
			
			var paneId = this.tabLinks[i].href.substring(this.tabLinks[i].href.indexOf("#") + 1);
			panes[panes.length] = paneId;
			
			if (Element.hasClassName(this.tabLinks[i].up("li"), "active")) {
				// currently active tab
				this.current = i;
			} 
		}
		this.tabPanes = panes;
		
		// initial hide tabpanes
		for (i=0; i<this.tabPanes.length; i++) {
			if ($(this.tabPanes[i])) {
				Element.addClassName($(this.tabPanes[i]), "disabled");
			}
		}
		
		this.switchActiveTab(null, this.current);
	},
	
	switchActiveTab: function(e, newActiveTab) {
		for (i=0; i<this.tabLinks.length; i++) {
			Element.removeClassName(this.tabLinks[i].up("li"), "active");
			if ($(this.tabPanes[i])) {
				Element.addClassName($(this.tabPanes[i]), "disabled");
			}
			if (this.customHandlers[this.tabPanes[i]]) {
				this.customHandlers[this.tabPanes[i]].disable(this);
			}
		}
		
		// enable active element
		Element.addClassName(this.tabLinks[newActiveTab].up("li"), "active");
		if ($(this.tabPanes[newActiveTab])) {
			Element.removeClassName($(this.tabPanes[newActiveTab]), "disabled");
		}
		if (this.customHandlers[this.tabPanes[newActiveTab]]) {
			this.customHandlers[this.tabPanes[newActiveTab]].enable(this);
		} 
		this.current = newActiveTab;
		
		if (e) {
			Event.stop(e);
		}
	}
}

$$(".tabbed-nav").each(function(el) {
	new TabbedNavigation(el, {
		"tab-overview": {
			enable: function(nav) {
				for (i=0; i<nav.tabPanes.length; i++) {
					var tab = $(nav.tabPanes[i]);
					if (tab) {
						Element.addClassName(tab, "overview-only");
					}
				}
			}, 
			disable: function(nav) {
				for (var j=0; j<nav.tabPanes.length; j++) {
					var tab = $(nav.tabPanes[j]);
					if (tab) {
						Element.removeClassName(tab, "overview-only");
					}
				}
			}
		}
	});
});

*/