/* Footer */
function footer () {
	setupCategorieBlocks();
}
/* End footer */


/* Category Blocks */
var slideCategoryBlockSpeed = 15;

var categoryBlocks              = 0;
var categoryBlocksContent       = new Array();
var categoryBlocksContentHeight = new Array();
var categoryBlocksContentState  = new Array();

function setupCategorieBlocks () {
	var allDivs = document.getElementsByTagName('div');
	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].className == 'categoryblock') {
			allDivs[i].value = categoryBlocks;
			allDivs[i].onmousedown = function() {
				toggleCategoryBlock(this, this.value);
			};
			
			var currentInnerHTML = allDivs[i].innerHTML;
			allDivs[i].innerHTML = '<img class="close" /><div class="label">' + currentInnerHTML + '</div>';
			categoryBlocks++;
		}
		if (allDivs[i].className == 'categoryblock-content') {
			categoryBlocksContent[categoryBlocksContent.length]             = allDivs[i];
			categoryBlocksContentHeight[categoryBlocksContentHeight.length] = allDivs[i].offsetHeight;
			categoryBlocksContentState[categoryBlocksContentState.length]   = 0;
			allDivs[i].style.height = '0px';
		}
	}	
}

function toggleCategoryBlock (target, index) {
	if (categoryBlocksContent[index] == undefined) return;
	
	switch (categoryBlocksContentState[index]) {
		case 0:
			categoryBlocksContentState[index] = 1;
		break;
		case 1:
			categoryBlocksContentState[index] = 3;
		break;
		case 2:
			categoryBlocksContentState[index] = 3;
		break;
		case 3:
			categoryBlocksContentState[index] = 1;
		break;
		default:
			return;
	}
	
	var allImgs = target.getElementsByTagName('img');
	if (allImgs.length > 0) {
		switch (categoryBlocksContentState[index]) {
			case 1:
				allImgs[0].className = 'open';
			break;
			case 3:
				allImgs[0].className = 'close';
			break;
		}
	}

	changeCategoryBlockSize(index);
}

function changeCategoryBlockSize (index) {
	if (categoryBlocksContent[index] == undefined) return;
	
	var minHeight = 0;
	var maxHeight = categoryBlocksContentHeight[index];
	var curHeight = categoryBlocksContent[index].offsetHeight; 
	var valHeight = slideCategoryBlockSpeed;
	var newHeight = 0;
	
	var timeOutInMilliSeconds = 10;
	
	switch (categoryBlocksContentState[index]) {
		case 1:
			if (curHeight < maxHeight) {
				newHeight = categoryBlocksContent[index].offsetHeight + valHeight;
			}
		
			if (newHeight >= maxHeight) {
				newHeight = maxHeight;
			}
	
			categoryBlocksContent[index].style.height = newHeight + 'px';

			if (newHeight != maxHeight) {
				setTimeout('changeCategoryBlockSize(' + index + ')', timeOutInMilliSeconds);
			} else {
				categoryBlocksContentState[index] = 2;
			}
		break;
		case 3:
			if (curHeight > minHeight) {
				newHeight = categoryBlocksContent[index].offsetHeight - valHeight;
			}
		
			if (newHeight <= minHeight) {
				newHeight = minHeight;
			}
	
			categoryBlocksContent[index].style.height = newHeight + 'px';

			if (newHeight != minHeight) {
				setTimeout('changeCategoryBlockSize(' + index + ')', timeOutInMilliSeconds);
			} else {
				categoryBlocksContentState[index] = 0;
			}
		break;
	}
}
/* End category blocks */


/* Menu Items */
var activeHRId = -1;
var prevHRId   = -1;

function onMouseMenuItemOver (id) {
	if (activeHRId == id) return;
	document.getElementById('menulabel-' + id).className = 'label_hover';
	document.getElementById('menuhr-' + id).className    = 'horizontalrule_hover';
	prevHRId = id;
}

function onMouseMenuItemOut () {
	if (prevHRId == -1) return;
	document.getElementById('menulabel-' + prevHRId).className = 'label';
	document.getElementById('menuhr-' + prevHRId).className    = 'horizontalrule';
}

function activateMenuItem (id) {
	document.getElementById('menulabel-' + id).className = 'label_activated';
	document.getElementById('menuhr-' + id).className    = 'horizontalrule_activated';	
	if (activeHRId != -1 && activeHRId != id) {
		prevHRId = activeHRId;
	}
	activeHRId = id;
}

function menuItemGotoURL (id, url) {
	activateMenuItem (id);
	location.href = url;
}
/* End menu items */