var ua = {};
with (ua) {
	ua.toString = function() { return navigator.userAgent; };
	ua.test = function(s) { return toString().toLowerCase().indexOf(s.toLowerCase()) > -1; };
	ua.gecko = test("gecko") && !test("khtml");
	ua.khtml = test("khtml");
	ua.opera = test("opera");
	ua.ie = test("msie");
	ua.mac = test("mac");
	ua.win = test("windows");
}

function createStoreTabs(ids) {
	var root = document.getElementById("store-city").appendChild(document.createElement("div"));
	root.className = "tabs";
	if (!root || ids.length < 2) return;
	var tabs = [];
	for (var i = 0, l = ids.length; i < l; i++) {
		var id = ids[i];
		var n = document.getElementById(id);
		if (!n) continue;
		n.className = "tabbed";
		var tab = document.createElement("a");
		tab.className = "tab";
		tab.href = "#" + id;
		tab.linked = n;
		tab.onclick = function() {
			if (activeStoreTab != this) {
				if (activeStoreTab != null) {
					activeStoreTab.className = "tab";
					activeStoreTab.linked.className = "tabbed";
				}
				activeStoreTab = this;
				this.className = "tab tab-active";
				this.linked.className = "tabbed tabbed-active";
			}
			this.blur();
			return false;
		};
		var title = "Tab";
		if (n.getElementsByTagName("h2").length > 0)
			title = n.getElementsByTagName("h2")[0].firstChild.nodeValue;
		tab.appendChild(document.createTextNode(title));
		tabs[tabs.length] = tab;
		root.appendChild(tab);
	}
	if (tabs[0]) tabs[0].onclick();
}
var activeStoreTab = null;


// execute on DOM load
window.onload = function() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	// execute following
	createStoreTabs(["store-bulletin", "store-openinghours", "store-address", "store-salesactions"]);
}
if (document.addEventListener) document.addEventListener("DOMContentLoaded", window.onload, false);
if (ua.ie) {
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") window.onload();
	};
}
if (ua.khtml && document.readyState) {
	function checkReady() {
		if (document.readyState != "loading") window.onload();
		else setTimeout(checkReady, 10);
	}
	checkReady();
}
