window.addEvent('domready', function() {
	
	var currId = 0;
	
	 fullURL = parent.document.URL;
    term = fullURL.substring(fullURL.indexOf('?')+6, fullURL.length);
    if (term.charAt(0) != '/'){        
        var alphabet = "abcdefghijklmnopqrstuvwxyz";        
        currId =alphabet.indexOf(term.charAt(0).toLowerCase());       
    }
		
	
	var showAll = false;
	// gloss items
	myLetter 	= $$('#glossIndex li a');
	myLetter.set('href', 'javascript:void(0);');
	//term items
	myDef 		= $$('.termItem');
	myDef.setStyle('display','none');
	//if JS enabled, show view all functionality
	$$('#glossIndex li.ignore').setStyle('visibility','');
	
	function swapTerm(viewAll, id) {	
		if (!viewAll) {
			if (showAll) { myDef.setStyle('display','none'); }
			if (myLetter[currId].hasClass('on')) { myLetter[currId].removeClass('on') }
			myDef[currId].setStyle('display','none');			
			myLetter[id].set('class','on');
			myDef[id].setStyle('display','block');	
			currId = id;								
		}
		else if (viewAll) {
			myLetter[currId].removeClass('on');			
			myDef.setStyle('display','block');
			showAll = true;
		}

	}

	myLetter.each(function(el, i) {
		if (i < 26 && !el.hasClass('noDef')) {
			el.addEvent('click', function() {
				swapTerm(false, i);
			})
		}
		else if (i >= 26) {
			el.addEvent('click', function() {
				swapTerm(true);
			})
		}		
	})
	
	//show initial term
    swapTerm(false, currId);
    
});