/*****************************   anDeRan   ************************************/

var is_ie  = !!document.uniqueID;
var is_ie6 = is_ie && navigator.appVersion.match(/MSIE [56]/) && !navigator.appVersion.match(/MSIE [789]/);

function isset(varname)
{
  return(typeof(window[varname])!='undefined');
}

if (is_ie6) {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
}

if (is_ie) {
	var XMLHttpRequest = function () {
		return (new ActiveXObject("Msxml2.XMLHTTP")) || (new ActiveXObject("Microsoft.XMLHTTP")) || false;
	};
}

var request = function () {
	try {
		var link = new XMLHttpRequest();
	} catch (e) {
		alert('Your browser doesn\'t support XMLHttpRequest. Please enable XMLHTTPRequest if disabled or update if your browser is old.');
	}

	var loading = document.getElementById('ajax-loading');
	document.onmousemove = function (e) {
		e = e || event;
		if (loading) {
			loading.style.display = 'block';
			loading.style.top = (e.clientY + (document.documentElement.scrollTop || window.scrollY || document.body.scrollTop) - 16) + 'px';
			loading.style.left = (e.clientX + (document.documentElement.scrollLeft || window.scrollX || document.body.scrollLeft) - 16) + 'px';
		}
	};

	this.get = function (path, analyze, params, no_loading) {
		if (no_loading) {
			loading.style.display = 'none';
		}
		link.onreadystatechange = function () {
			if (link.readyState == 4 && link.status == 200) {
				if (loading) {
					loading.style.display = 'none';
				}
				document.onmousemove = null;
				if (analyze) {
					analyze(link, params);
				}				
			}
		};
		link.open('GET', path, true);

		if (is_ie6) {
			link.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
		}
		link.send('');
	};

	this.post = function (path, analyze, form, no_loading) {
		if (no_loading) {
			loading.style.display = 'none';
		}
		link.onreadystatechange = function () {
			if (link.readyState == 4 && link.status == 200) {
				loading.style.display = 'none';
				document.onmousemove = null;
				if (analyze) {
					analyze(link);
				}
			}
		};
		link.open("POST", path, true);
		link.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if (is_ie6) {
			link.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
		}

		var i, j, send = '';
		for (i = 0; i < form.elements.length; i++) {
			if (form.elements[i].name) {
				if (form.elements[i].nodeName == "SELECT" && form.elements[i].name.indexOf("[]")) {
					for (j = 0; j < form.elements[i].options.length; j++) {
						if (form.elements[i].options[j].selected) {
							send += '&' + form.elements[i].name + '=' + form.elements[i].options[j].value;
						}
					}
				} else {
					if ((form.elements[i].type == "radio" || form.elements[i].type == "checkbox") && form.elements[i].checked || form.elements[i].type != "radio" && form.elements[i].type != "checkbox") {
						send += '&' + form.elements[i].name + '=' + form.elements[i].value.replace(/\+/g, '%2B');
					}
				}
			}
		}
		link.send(send.substring(1));
	};
};

var setOpacity = function (obj, num) {
	if (is_ie && obj.style.filter != undefined) {
		obj.style.filter = 'alpha(opacity=' + (num * 100) + ')';
	} else {
		obj.style.opacity = num;
	}
};

var hideShop = function () {
	var child  = document.getElementById('child');
	var parent = child.parentNode;
	var shop   = parent.parentNode;

	var fullWidth  = child.offsetWidth;
	var fullHeight = child.offsetHeight;

		var sWidth  = child.offsetWidth;
		var sHeight = child.offsetHeight;
		var fWidth  = 100;
		var fHeight = 100;
		var stepX = sWidth / fWidth * 4;
		var stepY = sHeight / fHeight * 4;

		var currWidth  = sWidth;
		var currHeight = sHeight;
		var currLeft = (sWidth - currWidth) / 2;
		var currTop  = (sHeight - currHeight) / 2;
		var fixedLeft = fWidth / 2;
		var fixedTop = fHeight / 2;

		parent.style.width  = currWidth + 'px';
		parent.style.height = currHeight + 'px';
		child.style.left = -currLeft + 'px';
		child.style.top  = -currTop + 'px';
		parent.style.marginLeft = currLeft + 'px';
		parent.style.marginTop  = currTop + 'px';

		var interval = setInterval(function () {
			currWidth  -= stepX;
			currHeight -= stepY;
			currWidth  = currWidth > fWidth ? currWidth : fWidth;
			currHeight = currHeight > fHeight ? currHeight : fHeight;
			currLeft = (sWidth - currWidth) / 2;
			currTop  = (sHeight - currHeight) / 2;
			currLeft = currLeft > 0 ? currLeft : 0;
			currTop  = currTop > 0 ? currTop : 0;

			parent.style.width  = currWidth + 'px';
			parent.style.height = currHeight + 'px';
			parent.style.marginLeft = currLeft + 'px';
			parent.style.marginTop  = currTop + 'px';
			child.style.left = -currLeft + 'px';
			child.style.top  = -currTop + 'px';

			if (currHeight == fHeight && currWidth == fWidth) {
				clearInterval(interval);
				shop.parentNode.removeChild(shop);
			}
		}, 50);
	return false;
};

var showShop = function (current) {
	current |= '';
	var shop = document.createElement('DIV');
	shop.id = 'shop';
	var parent = document.createElement('DIV');
	parent.id = 'parent';
	shop.appendChild(parent);
	var child = document.createElement('DIV');
	child.id = 'child';
	parent.appendChild(child);
	document.body.appendChild(shop);
	(new request).get('scripts/requests.php?action=shop&current=' + current, function (req) {
		//shadow.style.backgroundImage = 'none';
		child.innerHTML = req.responseText;

		var sWidth  = 100;
		var sHeight = 100;
		var fWidth  = child.offsetWidth;
		var fHeight = child.offsetHeight;
		var stepX = fWidth / sWidth * 4;
		var stepY = fHeight / sHeight * 4;

		var currWidth  = sWidth;
		var currHeight = sHeight;
		var currLeft = (fWidth - currWidth) / 2;
		var currTop  = (fHeight - currHeight) / 2;
		var fixedLeft = fWidth / 2;
		var fixedTop = fHeight / 2;

		parent.style.width  = currWidth + 'px';
		parent.style.height = currHeight + 'px';
		child.style.left = -currLeft + 'px';
		child.style.top  = -currTop + 'px';
		parent.style.marginLeft = currLeft + 'px';
		parent.style.marginTop  = currTop + 'px';
		shop.style.visibility = 'visible';

		var title = document.getElementById('title');
		child.style.backgroundPosition = '6px ' + (title.offsetHeight - 80) + 'px';

		var is_min = child.offsetHeight < title.offsetHeight + 141;
		if (is_ie6) {
			child.style.height = is_min ? title.offsetHeight + 141 + 'px' : 'auto';
		} else {
			child.style.minHeight = is_min ? title.offsetHeight + 141 + 'px' : 'auto';
		}

		var interval = setInterval(function () {
			currWidth  += stepX;
			currHeight += stepY;
			currWidth  = currWidth < fWidth ? currWidth : fWidth;
			currHeight = currHeight < fHeight ? currHeight : fHeight;
			currLeft = (fWidth - currWidth) / 2;
			currTop  = (fHeight - currHeight) / 2;
			currLeft = currLeft > 0 ? currLeft : 0;
			currTop  = currTop > 0 ? currTop : 0;

			parent.style.width  = currWidth + 'px';
			parent.style.height = (currHeight == fHeight ? 'auto' : currHeight + 'px');
			parent.style.marginLeft = currLeft + 'px';
			parent.style.marginTop  = currTop + 'px';
			child.style.left = -currLeft + 'px';
			child.style.top  = -currTop + 'px';

			if (currHeight == fHeight && currWidth == fWidth) {
				clearInterval(interval);
				//shadow.style.height = fHeight + 'px';
			}
		}, 50);
	});
};

var showMarket = function (current) {
	current |= '';
	var shop = document.createElement('DIV');
	shop.id = 'shop';
	var parent = document.createElement('DIV');
	parent.id = 'parent';
	shop.appendChild(parent);
	var child = document.createElement('DIV');
	child.id = 'child';
	parent.appendChild(child);
	document.body.appendChild(shop);
	(new request).get('scripts/requests.php?action=market&current=' + current, function (req) {
		//shadow.style.backgroundImage = 'none';
		child.innerHTML = req.responseText;

		var sWidth  = 100;
		var sHeight = 100;
		var fWidth  = child.offsetWidth;
		var fHeight = child.offsetHeight;
		var stepX = fWidth / sWidth * 4;
		var stepY = fHeight / sHeight * 4;

		var currWidth  = sWidth;
		var currHeight = sHeight;
		var currLeft = (fWidth - currWidth) / 2;
		var currTop  = (fHeight - currHeight) / 2;
		var fixedLeft = fWidth / 2;
		var fixedTop = fHeight / 2;

		parent.style.width  = currWidth + 'px';
		parent.style.height = currHeight + 'px';
		child.style.left = -currLeft + 'px';
		child.style.top  = -currTop + 'px';
		parent.style.marginLeft = currLeft + 'px';
		parent.style.marginTop  = currTop + 'px';
		shop.style.visibility = 'visible';

		var title = document.getElementById('title');
		child.style.backgroundPosition = '6px ' + (title.offsetHeight - 80) + 'px';

		var is_min = child.offsetHeight < title.offsetHeight + 141;
		if (is_ie6) {
			child.style.height = is_min ? title.offsetHeight + 141 + 'px' : 'auto';
		} else {
			child.style.minHeight = is_min ? title.offsetHeight + 141 + 'px' : 'auto';
		}

		var interval = setInterval(function () {
			currWidth  += stepX;
			currHeight += stepY;
			currWidth  = currWidth < fWidth ? currWidth : fWidth;
			currHeight = currHeight < fHeight ? currHeight : fHeight;
			currLeft = (fWidth - currWidth) / 2;
			currTop  = (fHeight - currHeight) / 2;
			currLeft = currLeft > 0 ? currLeft : 0;
			currTop  = currTop > 0 ? currTop : 0;

			parent.style.width  = currWidth + 'px';
			parent.style.height = (currHeight == fHeight ? 'auto' : currHeight + 'px');
			parent.style.marginLeft = currLeft + 'px';
			parent.style.marginTop  = currTop + 'px';
			child.style.left = -currLeft + 'px';
			child.style.top  = -currTop + 'px';

			if (currHeight == fHeight && currWidth == fWidth) {
				clearInterval(interval);
				//shadow.style.height = fHeight + 'px';
			}
		}, 50);
	});
};

var getProducts = function (link, cat_id) {
	(new request).get('scripts/requests.php?action=products&cat_id=' + cat_id, function (req) {
		var products = document.getElementById('products');
		products.innerHTML = req.responseText;
		var categories = document.getElementById('categories').getElementsByTagName('A');
		var i = categories.length;
		while (i-- > 0) {
			var curr_id = parseInt(categories[i].onclick.toString().replace(/[^\d\-]+/g, ''), 10);
			if (curr_id == cat_id) {
				categories[i].className = 'active';
			} else {
				categories[i].className = '';
				categories[i].removeAttribute('class');
			}
		}
		var title = document.getElementById('title');
		document.getElementById('child').style.backgroundPosition = '6px ' + (title.offsetHeight - 80) + 'px';
	});
	link.blur();
	return false;
};

var getProducts_shop = function (link, cat_id) {
	(new request).get('scripts/requests.php?action=products_shop&cat_id=' + cat_id, function (req) {
		var products = document.getElementById('products');
		products.innerHTML = req.responseText;
		var categories = document.getElementById('categories').getElementsByTagName('A');
		var i = categories.length;
		while (i-- > 0) {
			var curr_id = parseInt(categories[i].onclick.toString().replace(/[^\d\-]+/g, ''), 10);
			if (curr_id == cat_id) {
				categories[i].className = 'active';
			} else {
				categories[i].className = '';
				categories[i].removeAttribute('class');
			}
		}
		var title = document.getElementById('title');
		document.getElementById('child').style.backgroundPosition = '6px ' + (title.offsetHeight - 80) + 'px';
	});
	link.blur();
	return false;
};

var appendCell = function (parent, value, classes) {
	var td = document.createElement('TD');
	td.innerHTML = value;
	if (classes) {
		td.className = classes;
	}
	parent.appendChild(td);
};

var addToCart = function (button) {
	button.blur();
	var lines = button.parentNode.parentNode.getElementsByTagName('P');
	var price = parseFloat(lines[1].getElementsByTagName('STRONG')[0].innerHTML);
	var item_id = lines[1].getElementsByTagName('SMALL')[0].innerHTML;
	var calories = parseInt(lines[3].getElementsByTagName('SPAN')[0].innerHTML, 10);
	if(isNaN(calories)) calories = "";
	var parent = document.getElementById('cart');
	var cart = parent.getElementsByTagName('TABLE')[0].tBodies[0];
	var i = cart.rows.length;
	if (!i) {
		parent.style.display = 'block';
		var step = 15;
		var height = 10;
		var full = parent.offsetHeight;

		parent.style.height = height + 'px';
		parent.style.visibility = 'visible';
		parent.style.position = 'static';

		var interval = setInterval(function () {
			height += step;
			if (height > full) {
				clearInterval(interval);
				parent.style.height = 'auto';
			} else {
				parent.style.height = height + 'px';
			}
		}, 30);
	}
	var last = i - 1;
	var in_cart = false;
	while (i-- > 0) {
		if (cart.rows[i].cells[0].innerHTML == item_id) {
			in_cart = true;
			break;
		}
	}

	if (in_cart) {
		setAmount(cart.rows[i], 1);
	} else {
		var td, tr = document.createElement('TR');
		appendCell(tr, item_id, 'code');
		appendCell(tr, 1, 'amount');
		appendCell(tr, '<img src="images/common/arrow_up.png" width="12" height="6" alt="Увеличить количество" title="Увеличить количество" class="arrow-up" onclick="setAmount(this, 1)" /><img src="images/common/arrow_down.png" width="12" height="6" alt="Уменьшить количество" title="Уменьшить количество" class="arrow-down" onclick="setAmount(this, -1)" />', 'arrows');
		appendCell(tr, price.toFixed(2));
		appendCell(tr, calories);
		appendCell(tr, price.toFixed(2));
		appendCell(tr, '<img src="images/common/remove.png" width="10" height="10" alt="Удалить из корзины" title="Удалить из корзины" onclick="removeItem(this)" />', 'remove');
		cart.appendChild(tr);
		setTotal(cart);
	}

	var hint = document.getElementById('hint');
	if (hint) {
		hint.parentNode.removeChild(hint);
		clearInterval(window.s_interval);
		clearTimeout(window.s_timeout);
	}

	var hint = document.createElement('P');
	hint.id = 'hint';
	hint.className = 'hint';
	var span = document.createElement('SPAN');
	span.className = 'corner';
	hint.appendChild(span);
	var span = document.createElement('SPAN');
	span.className = 'content';
	span.innerHTML = 'добавлено в заказ';
	hint.appendChild(span);
	button.parentNode.insertBefore(hint, button);

	var opacity = 0.3, _step = 0.05;
	setOpacity(hint, opacity);
	window.s_interval = setInterval(function () {
		opacity += _step;
		if (opacity > 1) {
			clearInterval(window.s_interval);
			window.s_timeout = setTimeout(function () {
				var opacity = 0.95, _step = 0.05;
				setOpacity(hint, opacity);
				window.s_interval = setInterval(function () {
					opacity -= _step;
					if (opacity < 0) {
						clearInterval(window.s_interval);
						hint.parentNode.removeChild(hint);
					} else {
						setOpacity(hint, opacity);
					}
				}, 30);
			}, 800);
		} else {
			setOpacity(hint, opacity);
		}
	}, 30);
};

var setAmount = function (button, value) {
	var parent = button.parentNode.parentNode;;

	if (button.nodeName == 'IMG') {
		parent = button.parentNode.parentNode;
	} else {
		parent = button;
	}

	var cells = parent.cells;
	var amount = parseInt(cells[1].innerHTML, 10) + value;
	if (amount > 0) {
		var total = amount * parseFloat(cells[3].innerHTML);
		cells[1].innerHTML = amount;
		cells[5].innerHTML = total.toFixed(2);
		setTotal(parent.parentNode);
	} else {
		removeItem(button);
	}
};

var removeItem = function (button) {
	var parent = button.parentNode.parentNode;
	var tbody  = parent.parentNode;
	parent.parentNode.removeChild(parent);
	setTotal(tbody);
	if (!tbody.rows.length) {
		parent = tbody.parentNode.parentNode;
		var step = 15;
		var height = parent.offsetHeight;
		parent.style.height = height + 'px';

		var interval = setInterval(function () {
			height -= step;
			if (height < 1) {
				clearInterval(interval);
				parent.style.display = 'none';
				parent.style.height = 'auto';
			} else {
				parent.style.height = height + 'px';
			}
		}, 30);
	}
};

var setTotal = function (tbody) {
	var i = tbody.rows.length;
	var total = 0;
	while (i-- > 0) {
		total += parseFloat(tbody.rows[i].cells[5].innerHTML);
	}
	tbody.parentNode.tFoot.rows[0].cells[1].innerHTML = total.toFixed(2);
};

var showForm = function (link) {
	link.blur();
	var form = link.parentNode.parentNode.getElementsByTagName('FORM')[0];
	var step = 15;
	var height = 10;
	var full = form.offsetHeight;

	form.style.height = height + 'px';
	form.style.visibility = 'visible';
	form.style.position = 'static';

	var interval = setInterval(function () {
		height += step;
		if (height > full) {
			clearInterval(interval);
			form.style.height = 'auto';
		} else {
			form.style.height = height + 'px';
		}
	}, 30);
	return false;
};

var hideForm = function (button) {
	var form = button.form;
	var step = 15;
	var height = form.offsetHeight;

	form.style.height = height + 'px';

	var interval = setInterval(function () {
		height -= step;
		if (height < 1) {
			clearInterval(interval);
			form.style.visibility = 'hidden';
			form.style.position = 'absolute';
			form.style.height = 'auto';
		} else {
			form.style.height = height + 'px';
		}
	}, 30);
	return false;
};

var sendForm = function (button) {
	var errors = false;
	var i = button.form.elements.length;
	while (i-- > 0) {
		if (button.form.elements[i].type == 'text') {
			var title = button.form.elements[i].parentNode.firstChild.innerHTML;
			if (title.indexOf('*') != -1) {
				if (!button.form.elements[i].value) {
					if (button.form.elements[i].className.indexOf('error') == -1) {
						button.form.elements[i].className += ' error';
					}
					errors = true;
				} else {
					button.form.elements[i].className = button.form.elements[i].className.replace(/ error/, '');
				}
			}
		}
	}
	
	if (!errors) {
		var parent = document.getElementById('cart');
		var cart = parent.getElementsByTagName('TABLE')[0].tBodies[0];
		var i = cart.rows.length;
		var products = '';
		while (i-- > 0) {
			products += cart.rows[i].cells[0].innerHTML + '|' + cart.rows[i].cells[1].innerHTML + '||';
		}

		if (button.form.elements['products']) {
			button.form.elements['products'].value = products.substr(0, products.length-2);
		} else {
			var input = document.createElement('INPUT');
			input.type = 'hidden';
			input.name = 'products';
			input.value = products.substr(0, products.length-2);
			button.form.appendChild(input);		
		}

		(new request).post('scripts/requests.php?action=form', function (req) {
			var i = cart.rows.length;
			while (i-- > 0) {
				cart.removeChild(cart.rows[i]);
			}

			var step = 15;
			var height = parent.offsetHeight;
			parent.style.height = height + 'px';

			var opacity = 1, o_step = 0.03;
			var table = cart.parentNode;
			setOpacity(table, opacity);

			var interval = setInterval(function () {
				height -= step;
				opacity -= o_step;
				if (height < 1) {
					clearInterval(interval);
					parent.style.display = 'none';
					parent.style.height = 'auto';
					setOpacity(table, 1);
					var note = document.createElement('P');
					note.className = 'note';
					note.innerHTML = '<br />' + req.responseText;
					parent.parentNode.appendChild(note);
					setTimeout(function () {
						note.parentNode.removeChild(note);
					}, 2000);
				} else {
					if (opacity > 0) {
						setOpacity(table, opacity);
					}
					parent.style.height = height + 'px';
				}
			}, 30);
		}, button.form);
	}
	return false;
};

var sendForm_shop = function (button) {
	var errors = false;
	var i = button.form.elements.length;
	while (i-- > 0) {
		if (button.form.elements[i].type == 'text') {
			var title = button.form.elements[i].parentNode.firstChild.innerHTML;
			if (title.indexOf('*') != -1) {
				if (!button.form.elements[i].value) {
					if (button.form.elements[i].className.indexOf('error') == -1) {
						button.form.elements[i].className += ' error';
					}
					errors = true;
				} else {
					button.form.elements[i].className = button.form.elements[i].className.replace(/ error/, '');
				}
			}
		}
	}
	
	if (!errors) {
		var parent = document.getElementById('cart');
		var cart = parent.getElementsByTagName('TABLE')[0].tBodies[0];
		var i = cart.rows.length;
		var products = '';
		while (i-- > 0) {
			products += cart.rows[i].cells[0].innerHTML + '|' + cart.rows[i].cells[1].innerHTML + '||';
		}

		if (button.form.elements['products']) {
			button.form.elements['products'].value = products.substr(0, products.length-2);
		} else {
			var input = document.createElement('INPUT');
			input.type = 'hidden';
			input.name = 'products';
			input.value = products.substr(0, products.length-2);
			button.form.appendChild(input);		
		}

		(new request).post('scripts/requests.php?action=form_shop', function (req) {
			var i = cart.rows.length;
			while (i-- > 0) {
				cart.removeChild(cart.rows[i]);
			}

			var step = 15;
			var height = parent.offsetHeight;
			parent.style.height = height + 'px';

			var opacity = 1, o_step = 0.03;
			var table = cart.parentNode;
			setOpacity(table, opacity);

			var interval = setInterval(function () {
				height -= step;
				opacity -= o_step;
				if (height < 1) {
					clearInterval(interval);
					parent.style.display = 'none';
					parent.style.height = 'auto';
					setOpacity(table, 1);
					var note = document.createElement('P');
					note.className = 'note';
					note.innerHTML = '<br />' + req.responseText;
					parent.parentNode.appendChild(note);
					setTimeout(function () {
						note.parentNode.removeChild(note);
					}, 2000);
				} else {
					if (opacity > 0) {
						setOpacity(table, opacity);
					}
					parent.style.height = height + 'px';
				}
			}, 30);
		}, button.form);
	}
	return false;
};

var showPhoto = function (link) {
	link.blur();
	return false;
};

var sendComment = function (button) {
	var errors = false;
	var i = button.form.elements.length;
	while (i-- > 0) {
		if (button.form.elements[i].nodeName.toUpperCase() == 'TEXTAREA' || button.form.elements[i].type == 'text') {
			var title = button.form.elements[i].parentNode.firstChild.innerHTML;
			if (!button.form.elements[i].value) {
				if (button.form.elements[i].className.indexOf('error') == -1) {
					button.form.elements[i].className += ' error';
				}
				errors = true;
			} else {
				button.form.elements[i].className = button.form.elements[i].className.replace(/ error/g, '');
			}
		}
	}

	if (!errors) {
		(new request).post('/scripts/requests.php?action=comments', function (req) {
			if (req.responseText.indexOf('Err') === 0) {
				if (req.responseText.indexOf('wrong code') != -1) {
					button.form.elements['code'].className += ' error';
				}
			} else {
				var products = document.getElementById('products');
				products.innerHTML = req.responseText;

				var form = products.getElementsByTagName('FORM')[0];
				var i = form.elements.length;
				while (i-- > 0) {
					if (form.elements[i].nodeName.toUpperCase() == 'TEXTAREA' || form.elements[i].type == 'text') {
						form.elements[i].value = '';
					}
				}
			}
		}, button.form);
	}
	return false;
};

var setPage = function (page_num) {
	(new request).get('/scripts/requests.php?action=set_page&page_num=' + page_num, function (req) {
		
	});
	
	var cat_id = '-2'; // comments only
	
	(new request).get('scripts/requests.php?action=products&cat_id=' + cat_id, function (req) {
		var products = document.getElementById('products');
		products.innerHTML = req.responseText;
		var categories = document.getElementById('categories').getElementsByTagName('A');
		var i = categories.length;
		while (i-- > 0) {
			var curr_id = parseInt(categories[i].onclick.toString().replace(/[^\d\-]+/g, ''), 10);
			if (curr_id == cat_id) {
				categories[i].className = 'active';
			} else {
				categories[i].className = '';
				categories[i].removeAttribute('class');
			}
		}
		var title = document.getElementById('title');
		document.getElementById('child').style.backgroundPosition = '6px ' + (title.offsetHeight - 80) + 'px';
	});
	scroll(0,0);
	
	return false;
};

window.onload = function () {
	var loading = document.createElement('DIV');
	loading.id = 'ajax-loading';
	loading.style.display = 'none';
	document.body.appendChild(loading);
};

