// JavaScript Document

	var initActiveMenuItem = 1; 
	var activeSmallSquareColor = ['#D60E0E'];
	var colorSquareWidth = 3;
	var marginSquare = 1;

	var bgColorLinks = ["#F0F0F0"];	
	var degreesToDarkenOrLighten = [11];
	var changeBrightnessOrSaturation = ['brightness'];
	var textColorMenuItems = ['#000000'];

	var darkenOnMouseOver = [true,true];
	var timeStepOpacitySquare = 15;
	var opacityChangePerStep = 10;
	var timeStepSwitchBgColor = 10;
	var bgColorStep  = [1,1];
	var activeMenuItem = false;
	var activeMenuLink = false;	
	var menuObj;
	var brightnessLink = new Array(); 
	var saturationLink = new Array(); 
	var brightnessLinkMin = new Array();
	var saturationLinkMin = new Array();
	var darkenBrightnessCounter = new Array();
	var startHue = new Array();
	var startSat = new Array();
	var startBri = new Array();

	function showMenuItem()
	{
		var hsb = toHSV(this.getAttribute('bgColorItem'));
		currentIndex = this.className.replace(/[^\d]/g,'');
		if(changeBrightnessOrSaturation[currentIndex]=='saturation'){
			if(darkenOnMouseOver[currentIndex]){
				var saturation = hsb[1] - (degreesToDarkenOrLighten[currentIndex]/100);
			}else{
				var saturation = hsb[1] + (degreesToDarkenOrLighten[currentIndex]/100);
			}
			if(saturation<0)saturation=0;
			if(saturation>1)saturation=1;
			var rgb = toRgb(hsb[0],saturation,hsb[2]);
		}else{
			if(darkenOnMouseOver[currentIndex]){
				var brightness = hsb[2] - (degreesToDarkenOrLighten[currentIndex]/100);
			}else{
				var brightness = hsb[2] + (degreesToDarkenOrLighten[currentIndex]/100);
			}
			if(brightness<0)brightness=0;
			if(brightness>1)brightness=1;
			var rgb = toRgb(hsb[0],hsb[1],brightness);
		}
		this.style.backgroundColor = rgb;
		this.currentBgColorItem = rgb;
		this.setAttribute('currentBgColorItem',rgb);
		
		var obj = this.parentNode.getElementsByTagName('DIV')[0];
		obj.setAttribute('okToHide','0');
		obj.okToHide = 0;
		this.setAttribute('okToHide','0');
		this.okToHide = 0;
		obj.style.visibility = 'visible';
		
		obj.style.opacity = 0.98;	
		obj.style.filter = 'alpha(opacity=98)';
	}

	function hideMenuItem()
	{
		if(this.getAttribute('initActive')=='1')return;
		if(this.initActive=='1')return;
		var obj = this.parentNode.getElementsByTagName('DIV')[0];
		obj.setAttribute('okToHide','1');
		obj.okToHide = 1;
		this.setAttribute('okToHide','1');
		this.okToHide = 1;
		obj.style.visibility = 'visible';		
		if(navigator.userAgent.indexOf('Opera')>=0){
			obj.style.visibility = 'hidden';
		}else{
			progressHideSquare(obj.id,(opacityChangePerStep*-1));	
		}		
		progressShowHideBgColor(this.id);	
	}

	function progressShowHideBgColor(inputId)
	{
		var obj = document.getElementById(inputId);
		var currentBgColor = obj.getAttribute('currentBgColorItem');
		if(obj.getAttribute('okToHide')=='0')return;
		if(!currentBgColor)currentBgColor = obj.currentBgColorItem;
		if(currentBgColor){
			var index = obj.className.replace(/[^\d]/g,'');
			var hsb = toHSV(currentBgColor);
			if(changeBrightnessOrSaturation[index]=='saturation'){
				var saturation = hsb[1];			
				saturation+=darkenBrightnessCounter[index];
				if((saturation>saturationLink[index] && darkenOnMouseOver[index]) || (saturation<saturationLink[index] && !darkenOnMouseOver[index]))saturation = saturationLink[index];
				var rgb = toRgb(startHue[index],saturation,startBri[index]);	
				
				obj.style.backgroundColor = rgb;
				obj.currentBgColorItem = rgb;
				obj.setAttribute('currentBgColorItem',rgb);		
				if((hsb[1]<saturation && darkenOnMouseOver[index]) || (hsb[1]>saturation && !darkenOnMouseOver[index])){
					setTimeout('progressShowHideBgColor(\'' + inputId + '\')',timeStepSwitchBgColor);				
				}else{
					var index = obj.className.replace(/[^\d]/g,'');				
					obj.style.backgroundColor = bgColorLinks[index];
				}
										
			}else{
				var brightness = hsb[2];			
				brightness+=darkenBrightnessCounter[index];
				if((brightness>brightnessLink[index] && darkenOnMouseOver[index]) || (brightness<brightnessLink[index] && !darkenOnMouseOver[index]))brightness = brightnessLink[index];
				var rgb = toRgb(startHue[index],startSat[index],brightness);
				obj.style.backgroundColor = rgb;
				obj.currentBgColorItem = rgb;
				obj.setAttribute('currentBgColorItem',rgb);		
				if((hsb[2]<brightness && darkenOnMouseOver[index]) || (hsb[2]>brightness && !darkenOnMouseOver[index])){
					setTimeout('progressShowHideBgColor(\'' + inputId + '\')',timeStepSwitchBgColor);				
				}else{
					var index = obj.className.replace(/[^\d]/g,'');				
					obj.style.backgroundColor = bgColorLinks[index];
				}
			}
		}			
	}	
	
	function progressHideSquare(inputId,step)
	{
		var obj = document.getElementById(inputId);
		if(obj.getAttribute('okToHide')=='0' && step<0)return;
		if(document.all){
			var currentOpacity = obj.style.filter.replace(/[^\d]/g,'')/1;
			if(currentOpacity>=99){
			}
			else if(currentOpacity==11){
				obj.style.visibility='hidden';
			}else{
				currentOpacity = currentOpacity + step;
				if(currentOpacity<1)currentOpacity=1;
				if(currentOpacity>99)currentOpacity=9;
				obj.style.filter = 'alpha(opacity=' + currentOpacity + ')';
				setTimeout('progressHideSquare("' + inputId + '",' + (step) + ')',timeStepOpacitySquare);
			}				
		}else{
			step = step / 100;
			var currentOpacity = obj.style.opacity/1;
			if(currentOpacity>=0.99){
			}
			else if(currentOpacity==0.01){
				obj.style.visibility='hidden';
			}else{
				currentOpacity = currentOpacity + step;
				if(currentOpacity<0.01)currentOpacity=0.01;
				if(currentOpacity>0.99)currentOpacity=0.99;
				obj.style.opacity = currentOpacity;
				setTimeout('progressHideSquare("' + inputId + '",' + (step*100) + ')',timeStepOpacitySquare);
			}	
		}		
	}
	
	function tak_initMenu()
	{
		menuObj = document.getElementById('tak_menu');
		for(var no=0;no<bgColorLinks.length;no++){
			var hsbArray = toHSV(bgColorLinks[no]);
			brightnessLink.push(hsbArray[2]);
			saturationLink.push(hsbArray[1]);
			startHue.push(hsbArray[0]);
			startSat.push(hsbArray[1]);
			startBri.push(hsbArray[2]);
			if(darkenOnMouseOver[no]){
				brightnessLinkMin.push(Math.max(hsbArray[2] - (degreesToDarkenOrLighten[no]/100),0));
				saturationLinkMin.push(Math.max(hsbArray[1] - (degreesToDarkenOrLighten[no]/100),0));
				darkenBrightnessCounter.push(bgColorStep[no]/100);
			}else{
				brightnessLinkMin.push(Math.min(hsbArray[2] + (degreesToDarkenOrLighten[no]/100),1));
				saturationLinkMin.push(Math.min(hsbArray[1] + (degreesToDarkenOrLighten[no]/100),1));
				darkenBrightnessCounter.push((bgColorStep[no]/100)*-1);
			}
		}
		var listItems = menuObj.getElementsByTagName('LI');
		for(var no=0;no<listItems.length;no++){
			var menuLink = listItems[no].getElementsByTagName('A')[0];
			if(menuLink){
				if(!menuLink.className)menuLink.className = 'menuGroup0';
				var groupIndex = menuLink.className.replace(/[^\d]/g,'');
				listItems[no].id = 'listItem' + no;	
				var height = menuLink.offsetHeight;	
				menuLink.style.display='block';
				menuLink.style.height=height + 'px';
				menuLink.style.lineHeight=height + 'px';
				menuLink.onmouseover = showMenuItem;		
				menuLink.onmouseout = hideMenuItem;		
				menuLink.style.backgroundColor = bgColorLinks[groupIndex];
				menuLink.setAttribute('bgColorItem',bgColorLinks[groupIndex]);
				menuLink.bgColorItem = bgColorLinks[groupIndex];
				menuLink.setAttribute('currentBgColorItem',bgColorLinks[groupIndex]);
				menuLink.currentBgColorItem = bgColorLinks[groupIndex];
				menuLink.id = 'listLink' + no;
				menuLink.style.color = textColorMenuItems[groupIndex];
				
				var colorDiv = document.createElement('DIV');
				colorDiv.innerHTML = '<span><\/span>';
				colorDiv.style.height = height + 'px';
				colorDiv.style.width = colorSquareWidth + 'px';
				colorDiv.style.backgroundColor = activeSmallSquareColor[groupIndex];
				colorDiv.style.marginRight = marginSquare + 'px';
				colorDiv.style.visibility = 'hidden'			
				colorDiv.id = 'colorSquare' + no;
				colorDiv.style.opacity = 0.99;
				colorDiv.style.filter = 'alpha(opacity=100)';
				
				if(initActiveMenuItem==no){
					colorDiv.style.visibility = 'visible';
					if(changeBrightnessOrSaturation[groupIndex]=='saturation'){
						menuLink.style.backgroundColor = toRgb(startHue[groupIndex],saturationLinkMin[groupIndex],startBri[groupIndex]);
					}else{
						menuLink.style.backgroundColor = toRgb(startHue[groupIndex],startSat[groupIndex],brightnessLinkMin[groupIndex]);
					}
					menuLink.initActive = '1';
					menuLink.setAttribute('initActive','1');
				}
				
				listItems[no].appendChild(colorDiv);			
				listItems[no].appendChild(menuLink);
				var clearDiv = document.createElement('DIV');
				clearDiv.style.clear='both';
				listItems[no].appendChild(clearDiv);
				clearDiv.innerHTML = '<span></span>';
				var currentWidth = (listItems[no].offsetWidth - colorDiv.offsetWidth - marginSquare);
				menuLink.style.width =  currentWidth + 'px';
				while(listItems[no].offsetHeight>=(menuLink.offsetHeight*2)){		
					currentWidth--;	
					menuLink.style.width =  currentWidth + 'px';
				}
				listItems[no].style.overflow='hidden';
			}
		}		
	}
	window.onload = tak_initMenu;