// setListClasses function
//
// Loops through the UL elements inside a specified
// container (divName), and through each LI within 
// those ULs, ignoring a specified number of ULs
// from the beginning (ignoreFirst).  Checks if a
// list has more than a specified number of entries
// to always be shown (listInitial), and hides the
// rest appropriately.  Finally, the script assigns
// an onclick action to the last list item if there
// are hidden entries.


function browseL2lists() {
	var logos = document.getElementById('logolist');
	var textlinks = document.getElementById('textattributes');
	if (logos != null) {
		textlinks.style.display = 'none';
		
		var lis = logos.getElementsByTagName('li');
		for (y = 0; y < lis.length; y++) {
			if (y == lis.length - 1) {
				lis[y].className = 'showmore';
				$(lis[y]).show();
				lis[y].onclick = function() {
					showHideL2(logos, textlinks);
				}
			}
		}
		
		var textlis = textlinks.getElementsByTagName('li');
		for (y = 0; y < textlis.length; y++) {
			textlis[y].className = '';
		}
		
	} else {
		setListClasses('catattributes',1 ,4);
	}
}

// showHide function for browse level 2 only
//
// Shows any hidden list items and hides link clicked

function showHideL2(logos, textlinks) {
	
	$('li.showmore').show();
	var logolst = logos.getElementsByTagName('li');
	for (i = 0; i < logolst.length; i++) {
		if (logolst[i].className == 'showmore'){
			$(logolst[i]).removeClass('showmore');
			$(logolst[i]).addClass('hide');
			$(logolst[i]).html('<span>Hide</span>');
			//logolst[i].style.display = 'none';
		
			textlinks.style.display = 'block';
			var textlis = textlinks.getElementsByTagName('li');
			for (y = 0; y < textlis.length; y++) {
				textlis[y].style.display = 'block';
			}
			return;
		}
		 
		if (logolst[i].className == 'hide'){
			$(logolst[i]).removeClass('hide');
			$(logolst[i]).addClass('showmore');
			$(logolst[i]).html('+ <span>Show me more</span>');
			//logolst[i].style.display = 'none';
		
			textlinks.style.display = 'none';
			
		}
	}
	
}



function setListClasses(divName, ignoreFirst, listInitial) {
	var leftCol = document.getElementById(divName);
	
	if (leftCol != null) {	
		var uls = leftCol.getElementsByTagName('ul');
		for (x = ignoreFirst; x < uls.length; x++) {
			if(uls[x].className.indexOf('l3grouping')>-1);continue;
			var lis = uls[x].getElementsByTagName('li');
			for (y = 0; y < lis.length; y++) {
				if (y < listInitial) {
					lis[y].className = 'first4';
				}
				else if (lis.length >= listInitial && y == lis.length - 1) {
					lis[y].className = 'showmore';
					lis[y].onclick = function() {
						showHide(this);
					}
				}
				else if (y >= listInitial) {
					lis[y].className = 'therest';
					lis[y].style.display = 'none';
				}
			}
		}
	}
}


// showHide function
//
// Shows any hidden list items and hides link clicked

function showHide(targetList) {
	var target = targetList.parentNode;
	var list = target.getElementsByTagName('li');
	for (i = 0; i < list.length; i++) {
    	if(list[i].className == 'therest' && list[i].style.display == 'none') {
      		list[i].style.display = 'block';
        }
		if (list[i].className == 'showmore'){
			list[i].style.display = 'none';
		}
	}
}
