journalMenu = function(maxItems)
{
	this.indexes = new Array();
	this.maxItems = maxItems;
	this.curIndex = 0;
	this.div1Letter = false;
	this.div1Index = 0;
	this.div2Letter = false;
	this.div2Index = 0;
}

journalMenu.prototype.generateHeader = function(targetId)
{
	var target = document.getElementById(targetId);
	for(var i in this.indexes)
	{
		var a = document.createElement('a');
		a = document.createElement('a');
		a.setAttribute('href', '#');
		a.setAttribute('num',i);
		a.onclick = function(){
			Menu.generateContent(this.getAttribute('num'),0); 
			return false;
		}
		//a.setAttribute('onclick', 'Menu.generateContent("'+i+'",0); return false;');
		a.innerHTML = i;
		target.appendChild(a);
				
		var charCode = i.charCodeAt(0);
		if(charCode!=90)
		{
			var nextLetter = String.fromCharCode(charCode+1);
			while(typeof(this.indexes[nextLetter]) != 'object')
			{	
				a = document.createElement('a');
				a.setAttribute('href', '#');
				a.onclick = function(){ 
					return false;
				}
				a.className = 'notActive';
				//a.setAttribute('onclick', 'return false;');
				//a.setAttribute('class','notActive');
				a.innerHTML = nextLetter;
				target.appendChild(a);	
				nextLetter = String.fromCharCode(nextLetter.charCodeAt(0)+1);	
				
			}
		}

	}
}



journalMenu.prototype.generateContent = function(sletter, startIndex)
{
	this.div1Letter = false;
	this.div2Letter = false;

	this.curIndex = 0;
	var div1 = document.getElementById('div1');
	var div2 = document.getElementById('div2');
	var div3 = document.getElementById('div3');
	var div4 = document.getElementById('div4');

	div1.innerHTML = '<ul style="width: 700px;"></ul>';
	div2.innerHTML = '<ul style="width: 700px;"></ul>';
	div3.innerHTML = '<ul style="width: 700px;"></ul>';
	div4.innerHTML = '<ul style="width: 700px;"></ul>';
	var div = div1;
	var newColumn = false;
	var move = 0;
    var n = 0;
    
	for(var letter = sletter.charCodeAt(0); letter<=90; letter++)
	{
		var l = String.fromCharCode(letter);
		if(typeof(this.indexes[l]) == 'object')
		{
		var end = this.indexes[l].length;
			for(var i = startIndex; i < end; i++) 
				{
					if(newColumn)

						{
						//	this.curIndex = this.curIndex + move;
							newColumn = false;
						}
					if(this.curIndex<11)
					{
						if(!this.div1Letter)
						{
							this.div1Letter = letter;
							this.div1Index = i;	
						}		
					}
					

					if(this.curIndex>10 || 21<this.curIndex)
					{
						div = div2;		
						if(!this.div2Letter)
						{
							this.div2Letter = letter;
							this.div2Index = i;	
						}		
					}
					if(this.curIndex>21 || 32<this.curIndex)
						div = div3;	
					if(this.curIndex>32 || 43<this.curIndex)
						div = div4;		
					if(this.curIndex>=this.maxItems)
						return;

																				
						n++;
						var li = document.createElement('li');
						li.setAttribute('id','menu_'+n);
						//li.setAttribute('style', 'overflow:hidden;width:500px;');
						li.style.overflow = 'hidden';
						li.style.width = '500px';

						var journalMenu = 'journal_menu_'+n;
						li.onmouseover = function(){
							show('journal_'+this.id);
						}
						li.onmouseout = function(){
							hide('journal_'+this.id);
						}
						//li.setAttribute('onmouseover','show(\'journal_menu_'+n+'\');');
						//li.setAttribute('onmouseout','hide(\'journal_menu_'+n+'\');');
	
						var popout = document.createElement('div');		
						popout.onclick = function() {
							location.href = this.indexes[l][i][1];
						}				
						//popout.setAttribute('onclick','location.href = \''+this.indexes[l][i][1]+'\'');
						popout.setAttribute('id','journal_menu_'+n);
						popout.style.display = 'none';
						popout.style.marginLeft = '-13px';
						popout.style.cursor = 'pointer';
						//popout.setAttribute('style','display:none;margin-left:-13px;cursor:pointer;');
						popout.className = 'popout';
						///popout.setAttribute('class','popout');
						
						
						var a = document.createElement('a');
						var a2 = document.createElement('a');
						a.setAttribute('href', '#');
						if(i>0)
						{
							a.setAttribute('href', '/'+this.indexes[l][i][1]);
							a.innerHTML = this.indexes[l][i][0];
							a2.setAttribute('href', '/'+this.indexes[l][i][1]);;
							a2.innerHTML = this.indexes[l][i][0];
							
							popout.appendChild(a2); 
							li.appendChild(popout);
							li.appendChild(a);
						}
						else
							li.innerHTML = this.indexes[l][i];


						div.children[0].appendChild(li);
						this.curIndex++;
						if(startIndex>0)
							startIndex = 0;
	
				}

			if(letter==90)
			{
				this.div2Letter = false;
				this.div2Index = i;		
				return;	
			}
		}

	}

}



journalMenu.prototype.moveRight = function()
{					
	if(this.div2Letter!=false)
	this.generateContent(String.fromCharCode(this.div2Letter),this.div2Index);
}



journalMenu.prototype.moveLeft = function()
{
	var first = true;
	count = 0;
	for(var i = this.div1Letter; i>=64; i--)
	{
		var l = String.fromCharCode(i);
		if(typeof(this.indexes[l]) == 'object')
		{
			if(first)
				end = this.div1Index-1;
			else
				end = this.indexes[l].length -1 ; 
			for(var b = end; b>=0; b--)
			{
				count++;
				if(count==11)
					{
						this.div1Index = b;
						break;
					}
			}	
			first = false;		  
		}
		this.div1Letter = i;

		if(count>=11)
			break;

	}
	if(this.div1Letter == 64 && count<11)
		this.div1Index = 0

	this.generateContent(String.fromCharCode(this.div1Letter),this.div1Index);

}


