/**
* CSShiarchMenu v0.6
*	written by: me[AT]daantje[DOT]nl
*	last update: Sat Nov 26 13:08:45 CET 2005
*
*	Documentation:
*		Build this small script cause all the gpl-ed scripts I found where too big
*		and had too many options I never going to use, or the config for the menu
*		was not easy to set with a PHP routine.
*
*	License:
*		LGPL. (http://www.gnu.org/copyleft/lesser.txt)
*
*	Dontate:
*		Please, when you like my script, click a view banners on
*		http://www.dantje.nl Or use my pay-pal donation button.
*/

//declare
var submenu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';


// EXAMPLE CONFIG
var alignSubmenu 	= 'bottom';		//bottom or right side of the main button.
var useLastItemCSS	= true;			//generate last menu item too
									//if false, it will behave as a normal item
									//and the css menuItemLast class will not be used
var adjustFirst		= false;		//overlap the first submenu too?
var adjustTop		= -10;			//move the submenu's some pixels. Positive number (10) for down, negative (-10) for up.
var adjustLeft		= 5;			//move the submenu's some pixels. Positive number (10) for right, negative (-10) for left.

/*
//fisrt submenu tree
submenu['menu1'] = new Array();
submenu['menu1'][0] = menuItem('my own website','http://www.daantje.nl','_top');
submenu['menu1'][1] = menuItem('other sites');
	submenu['menu1_1'] = new Array();
	submenu['menu1_1'][0] = menuItem('google','http://www.google.nl','demoFrame');
	submenu['menu1_1'][1] = menuItem('/.','http://www.slashdot.org','demoFrame');
	submenu['menu1_1'][2] = menuItem('Open in _BLANK:');
		submenu['menu1_1_2'] = new Array();
		submenu['menu1_1_2'][0] = menuItem('check test','http://www.google.nl','_blank');
		submenu['menu1_1_2'][1] = menuItem('test again','http://www.slashdot.org','_blank');
submenu['menu1'][2] = menuItem('This should be the last one');

//second submenu tree
submenu['menu2'] = new Array();
submenu['menu2'][0] = menuItem('project 1','http://www.daantje.nl','_self');
submenu['menu2'][1] = menuItem('project 2');

//side menu item 1
submenu['menu4'] = new Array();
submenu['menu4'][0] = menuItem('test 1','http://www.daantje.nl','_self');
submenu['menu4'][1] = menuItem('test 2');
	submenu['menu4_1'] = new Array();
	submenu['menu4_1'][0] = menuItem('test 1','http://www.daantje.nl','_self');
	submenu['menu4_1'][1] = menuItem('test 2','http://www.daantje.nl','_self');
	submenu['menu4_1'][2] = menuItem('test 3','http://www.daantje.nl','_self');
*/

// END OF EXAMPLE CONFIG

function buildSubmenu(obj,align,load){
/*
Sven: 06.12.2006
Thinking again and simplyfiying: there is a need for target div at the template, then
the div is populated with submenuitems from here. Now reloading should work, too

Todo: the submenuitems text into div so that it can be aligned with its main menu item

*/

	//check if we have a submenu of the obj...
	if(submenu[obj.id]){
  	//build html for submenu
  	content = "";
		m = submenu[obj.id];
				




					//alert(obj.offsetLeft)
		//			alert(obj.offsetLeft)
				
//		document.getElementById('submenuitems').style.width = '100%'		
		//building the submenu items list Sven, 05.12.2006
  	for(i=0; i<m.length; i++){
      //determin target for onclick...
			//	(sorry, I should rewrite this routine...)
			if(m[i][1]){
  			if(m[i][1].substring(0,11) == 'javascript:'){
  				act = m[i][1].substring(11);
				}else{
  				if(!m[i][2] || m[i][2] == '_self')
    				act = "self.location.href='" + m[i][1] + "';";
					else if(m[i][2] == '_top')
						act = "top.location.href='" + m[i][1] + "';";
					else if(m[i][2] == '_parent')
						act = "parent.location.href='" + m[i][1] + "';";
					else if(m[i][2] == '_blank')
						act = "window.open('" + m[i][1] + "');";
					else
						act = "window.frames['"+m[i][2]+"'].location.href='" + m[i][1] + "';";
				}
			}

      m[i][0] = m[i][0].toLowerCase(); 

//document.getElementById('"+ obj.id + "_" + i +"').innerHTML=document.getElementById('"+ obj.id + "_" + i +"').innerHTML.toLowerCase();

          
          //important: the case when page is loaded and the case when item is the last one on 
          
					//make item, change css margin-left, according to the main menuitem position
					content+= "<span class='submenu' style='color:#8B0000; text-align:left; vertical-align:bottom; margin-right:0px;'" + " cursor:pointer;' onmouseout=\"this.style.fontWeight='600'; this.style.fontSize='1.0em'; this.style.color='#8B0000';\" onmouseover=\"style.color='#3333ff';this.style.fontWeight='600'; this.style.fontSize='1.0em';\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem" + (i==0 ? 'First' : (i==(m.length -1) && useLastItemCSS ? 'Last' : '')) + " id=\"" + obj.id + "_" + i +"\">" + m[i][0] + "</span>&nbsp;&nbsp;";
					adj[i] = obj.id + "_" + i;
				}
        
        //finding out if submenu div is for the last item, then 

				//insert new menu
				try
				{
					document.getElementById('submenuitems').innerHTML = content;			
				}
				catch(e)
				{
					return false;
				}
				//subObj.innerHTML = content;
			}
}


/*
					content+= "<span class='submenu' style='"+ (i < (m.length-1) ? "margin-left:"+ obj.offsetLeft +"px;" : '"text-align:right; margin-right:0px;"') + " cursor:pointer;' onmouseout=\"this.style.fontWeight='600';this.style.color='#868686';\" onmouseover=\"style.color='#ff0000';this.style.fontWeight='600';\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem" + (i==0 ? 'First' : (i==(m.length -1) && useLastItemCSS ? 'Last' : '')) + " id=\"" + obj.id + "_" + i +"\">" + m[i][0] + "</span>&nbsp;";
*/



function is_last(obj){
/*
finding out if the menu item is the last one
then align the submenu div to the right, do not try to

*/


}



function find_active(){
/*
  finds the currently active menu and prints out its submenus accordingly
  Todo:
  expand this function to get just ?path=0x42 - addresses, too
    
*/
  path = window.location.search //"?path=0x40x67"
  //alert(path)
  //finding out the part after =
  if(path !== '') {
    path_items = path.split('=')[1]; //also the 0x42 - case
    //but then path=0x42x89&forum=2 - case!
    //alert(path_items)
    path_more_get = path_items.split('&')[0] 
    
    //  document.getElementById('submenuitems').innerHTML = path
    i = 1
    found = false
    while(submenu['menu'+i] && !found){
      //alert(submenu['menu'+i])
      j = 0
      while(submenu['menu'+i][j]){
        if(submenu['menu'+i][j][1] == path || submenu['menu'+i][j][1].lastIndexOf(path_items) > -1 || submenu['menu'+i][j][1].lastIndexOf(path_more_get) > -1){
          buildSubmenu(document.getElementById('menu'+i))
          found = true
          break
        }
        j++
      }
      i++    
    }
  }
}

function is_active(id){
/*
if one submenuitem of a menu is currently "active", build the submenu 
*/
  path = window.location.search //"?path==0x40x67"
  for(i = 0; i < submenu[id].length; i++){
    if(submenu[id][i][1] == path)
      buildSubmenu(document.getElementById(id))
  }
}


//add an menu item to the config array (called in the config lines)
function menuItem(txt,url,tar){
	return new Array(txt,url,tar);
}

//change div's on mouse over and out...
document.onmouseover = function(e){
	obj = document.all ? event.srcElement : e.target;
	if(obj.className == 'menuItemFirst' || obj.className == 'menuItem' || obj.className == 'menuItemLast')
		obj.className+='Over';
}

document.onmouseout = function(e){
	obj = document.all ? event.srcElement : e.target;
	if(obj.className == 'menuItemFirstOver' || obj.className == 'menuItemOver' || obj.className == 'menuItemLastOver')
		obj.className = obj.className.substring(0,(obj.className.length - 4));
}

//*** Patch for firefox bug with focus on mouseover...
//		This function should be called onMouseOver of every iFrame that's under the menu structure.
function iFramePatch(){
	if(!document.all && lastOverId)
		hideSubmenu(document.getElementById(lastOverId));
}

