var boxHeight = '180px';
var boxMaxElements = 5;

function boxGet(categoryId){
	return $(document.getElementById('box' + categoryId));
}

function boxItems(box,show){
	var items = box.getElementsBySelector('ul[class="subcategories"] li');
	for(var i = 0; i < items.length; i++){
		if(show)
			items[i].show();
		else if(i >= boxMaxElements){
			items[i].hide();
		}
	}	
}

function boxLinks(box,show){
	var showLinks = box.getElementsBySelector('a[class="boxShow"]');
	for(var i = 0; i < showLinks.length; i++){
		if(!show)
			showLinks[i].hide();
		else
			showLinks[i].show();
	}
	var hideLinks = box.getElementsBySelector('a[class="boxHide"]');
	for(var i = 0; i < hideLinks.length; i++){
		if(show)
			hideLinks[i].hide();
		else
			hideLinks[i].show();
	}
}

function openCategoryBox(categoryId){
	
	var box = boxGet(categoryId);
	if(!box)
		return false;
		
	boxItems(box,true);
	boxLinks(box,false);
	
	box.style.height = "auto";
	
	return false;
}

function closeCategoryBox(categoryId){
	
	var box = boxGet(categoryId);
	if(!box)
		return false;
		
	boxItems(box,false);
	boxLinks(box,true);
	
	box.style.height = boxHeight;
	return false;
}
