// bytefx presentation page (C) Andrea Giammarchi
function getElementsByClass(etype, className){
	var	result = [],
		re = new RegExp("(^|\\s)" + className + "(\\s|$)"),
		elements = document.getElementsByTagName(etype),
		i = elements.length;
	while(i--) {
		if(re.test(elements[i].className))
			result.push(elements[i]);
	};
	result.reverse();
	return result;
};
if((window.opera && window.opera.version() > 7) || !/msie 5.0|msie 4/i.test(navigator.userAgent)) {
	bytefx.$event(window, "onload", function() {
		var	bg = "backgroundColor",
			footer = document.getElementById("footer"),
			section = getElementsByClass("DIV", "clear"),
			menu = getElementsByClass("A", "menu"),
			api = getElementsByClass("DIV", "api"),
			open = document.location.href.split("#"),
			h3 = null,
			lastview = null,
			element = null,
			index = 0,
			i = menu.length;
		while(i--) {
			bytefx.$event(menu[i], "onmouseover", function(){bytefx.color(this, bg, "#F5F5F5", "#099", 5)});
			bytefx.$event(menu[i], "onmouseout", function(){bytefx.color(this, bg, "#099", "#F5F5F5", 5)});
			menu[i].onclick = function(){
				function show() {
					bytefx.alpha(section, 0);
					section.className = "clear";
					bytefx.fade(section, 0, 100, 2, function(){bytefx.fade(footer, 0, 100, 2)});
					lastview = section;
				};
				var	section = this.section, force = lastview !== null;
				if(lastview !== section) {
					if(force)
						bytefx.clear(lastview);
					bytefx.fade(footer, (footer.style.opacity * 100 || 100), 0, 4, function(){
						if(force)
							bytefx.fade(lastview, (lastview.style.opacity * 100 || 100), 0, 4, function(){
								this.className = "hide";
								show();
							});
						else
							show();
					});
				};
				this.blur();
				return false;
			};
			menu[i].section = section[i];
		};
		i = api.length;
		while(i--) {
			h3 = api[i].getElementsByTagName("H3");
			index = h3.length;
			while(index--) {
				bytefx.$event(h3.item(index), "onmouseover", function(){bytefx.color(this, bg, "#EFEFEF", "#FFF", 1)});
				bytefx.$event(h3.item(index), "onmouseout", function(){bytefx.color(this, bg, "#FFF", "#EFEFEF", 1)});
				bytefx.$event(h3.item(index), "onclick", function() {
					var	check = this.clicked;
					if(!this.div) {
						this.div = this.parentNode.getElementsByTagName("DIV").item(this.index);
						this.div.className = "";
						this.realheight = bytefx.$size(this.div).height;
						this.div.style.overflow = "hidden";
						this.div.style.height = "1px";
						this.div.className = "hide";
					};
					if(!check) {
						this.div.className = "";
						bytefx.size(this.div, {width:350, height:this.realheight}, 7);
					}
					else 
						bytefx.size(this.div, {width:350, height:1}, 24, function(){this.className = "hide"});
					this.clicked = !this.clicked;
					return false;
				});
				h3.item(index).index = index;
			}
		};
		if(open.length == 2) {
			api = ["introduction", "examples", "faq", "api", "download"];
			i = api.length;
			while(i--) {
				if(api[i] === open[1]) {
					menu[i].onclick();
					api = [];
					i = 0;
				}
			};
			if(api.length)
				menu[0].onclick();
		}
		else
			menu[0].onclick();
	});
	document.write('<style type="text/css" media="screen">.hide{display: none}</style>');
};