//##############################################################################
/**
 *	ssm.js
 *	
 *	The popup menu engine
 *	
 *	@author		Jan / Re@PeR <jan@mycee.net>
 *	@link		http://blog.mycee.net
 *	@version	1.0
 *	
 *	@package 	common/x/js
 *
 */
//##############################################################################

NS6 = (document.getElementById&&!document.all);
IE = (document.all);
NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4");

tempBar='';
barBuilt=0;
ssmItems=new Array();
moving=setTimeout('null',1);

//------------------------------------------------------------------------------ 
/**
 *	Hack to make the menu not flicker
 *
 */	function truebody(){
		return (document.compatMode!="BackCompat")? document.documentElement : document.body;
	}
//------------------------------------------------------------------------------ 
/**
 *	Move the menu outwards
 *
 */	function moveOut() {
		if ((NS6||NS)&&parseInt(ssm.left) < 0 || IE && ssm.pixelLeft < 0) {
			clearTimeout(moving);
			moving = setTimeout('moveOut()', slideSpeed);
			slideMenu(10);
		} else {
			clearTimeout(moving);
			moving=setTimeout('null',1);
		}
	}
//------------------------------------------------------------------------------ 
/**
 *	Move the menu back to its origin
 *
 */	function moveBack() {
		clearTimeout(moving);
		moving = setTimeout('moveBack1()', waitTime)
	}
//------------------------------------------------------------------------------ 
/**
 *	Move the menu back to its origin
 *
 */	function moveBack1() {
		if ((NS6||NS) && parseInt(ssm.left)>(-menuWidth) || IE && ssm.pixelLeft>(-menuWidth)) {
			clearTimeout(moving);
			moving = setTimeout('moveBack1()', slideSpeed);
			slideMenu(-10);
		} else {
			clearTimeout(moving);
			moving=setTimeout('null',1);
		}
	}
//------------------------------------------------------------------------------ 
/**
 *	Slide the menu to position num
 *
 *	@param int num						The position to slide the menu to
 *
 */	function slideMenu(num){
		if (IE) {
			ssm.pixelLeft += num;
		}
		if (NS6) {
			ssm.left = parseInt(ssm.left)+num+"px";
		}
		if (NS) {
			ssm.left = parseInt(ssm.left)+num; bssm.clip.right+=num;bssm2.clip.right+=num;
		}
	}
//------------------------------------------------------------------------------ 
/**
 *	Make menu static before retracting
 *
 */	function makeStatic() {
		if (NS||NS6) {
			winY = window.pageYOffset;
		}
		if (IE) {
			winY = truebody().scrollTop;
		}
		if (NS6||IE||NS) {
			if (winY!=lastY&&winY>YOffset-staticYOffset) {
				smooth = .2 * (winY - lastY - YOffset + staticYOffset);
			} else if (YOffset-staticYOffset+lastY>YOffset-staticYOffset) {
				smooth = .2 * (winY - lastY - (YOffset-(YOffset-winY)));
			} else {
				smooth=0;
			}
		
			if(smooth > 0)
				smooth = Math.ceil(smooth);
			else
				smooth = Math.floor(smooth);
			
			if (IE)
				bssm.pixelTop+=smooth;
			if (NS6)
				bssm.top=parseInt(bssm.top)+smooth+"px";
			if (NS)
				bssm.top=parseInt(bssm.top)+smooth;
				
			lastY = lastY+smooth;
			setTimeout('makeStatic()', 1);
		}
	}
//------------------------------------------------------------------------------ 
/**
 *	Build the meny sidebar
 *
 */	function buildBar() {
		if(barText.indexOf('<IMG')>-1) {
			tempBar=barText2;
		} else {
			for (b=0;b<barText.length;b++) {
				tempBar+=barText.charAt(b)+"<BR>";
			}
		}
		document.write('<td align="center" rowspan="100" width="'+barWidth+'" bgcolor="'+barBGColor+'" valign="'+barVAlign+'"><p align="center"><font face="'+barFontFamily+'" Size="'+barFontSize+'" COLOR="'+barFontColor+'"><B>'+tempBar+'</B></font></p></TD>');
	}
//------------------------------------------------------------------------------ 
/**
 *	Initialise the sliding functionality of the meny
 *
 */	function initSlide() {
		if (NS6){
			ssm=document.getElementById("thessm").style;bssm=document.getElementById("basessm").style;
			bssm.clip="rect(0 "+document.getElementById("thessm").offsetWidth+" "+document.getElementById("thessm").offsetHeight+" 0)";ssm.visibility="visible";
		} else if (IE) {
			ssm=document.all("thessm").style;bssm=document.all("basessm").style;
			bssm.clip="rect(0 "+thessm.offsetWidth+" "+thessm.offsetHeight+" 0)";bssm.visibility = "visible";
		} else if (NS) {bssm=document.layers["basessm1"];
			bssm2=bssm.document.layers["basessm2"];ssm=bssm2.document.layers["thessm"];
			bssm2.clip.left=0;ssm.visibility = "show";
		}
		if (menuIsStatic=="yes"){
			makeStatic();
		}
	}
//------------------------------------------------------------------------------ 
/**
 *	Generate the HTML to build the menu
 *
 */	function buildMenu() {
		if (IE||NS6) {
			document.write('<DIV ID="basessm" style="visibility:hidden;Position : Absolute ;Left : '+XOffset+'px ;Top : '+YOffset+'px ;Z-Index : 20;width:'+(menuWidth+barWidth+10)+'px"><DIV ID="thessm" style="Position : Absolute ;Left : '+(-menuWidth)+'px ;Top : 0 ;Z-Index : 20;" onmouseover="moveOut()" onmouseout="moveBack()">');
		}
		if (NS) {
			document.write('<LAYER name="basessm1" top="'+YOffset+'" LEFT='+XOffset+' visibility="show"><ILAYER name="basessm2"><LAYER visibility="hide" name="thessm" bgcolor="'+menuBGColor+'" left="'+(-menuWidth)+'" onmouseover="moveOut()" onmouseout="moveBack()">');
		}
		if (NS6){
			document.write('<table border="0" cellpadding="0" cellspacing="0" width="'+(menuWidth+barWidth+2)+'px" bgcolor="'+menuBGColor+'"><TR><TD>');
		}
		
		document.write('<table border="0" cellpadding="0" cellspacing="1" width="'+(menuWidth+barWidth+2)+'px" bgcolor="'+menuBGColor+'">');
		
		for(i=0;i<ssmItems.length;i++) {
			if(!ssmItems[i][3]){
				ssmItems[i][3]=menuCols;ssmItems[i][5]=menuWidth-1
			} else if(ssmItems[i][3]!=menuCols){
				ssmItems[i][5]=Math.round(menuWidth*(ssmItems[i][3]/menuCols)-1);
			}
	
			if(ssmItems[i-1]&&ssmItems[i-1][4]!="no"){
				document.write('<TR>')
			}
			
			if(!ssmItems[i][1]){
				document.write('<td bgcolor="'+hdrBGColor+'" HEIGHT="'+hdrHeight+'px" ALIGN="'+hdrAlign+'" VALIGN="'+hdrVAlign+'" WIDTH="'+ssmItems[i][5]+'" COLSPAN="'+ssmItems[i][3]+'">&nbsp;<font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+ssmItems[i][0]+'</b></font></td>')
			} else {
				if(!ssmItems[i][2]){
					ssmItems[i][2]=linkTarget;
				}
				document.write('<TD BGCOLOR="'+linkBGColor+'" onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="'+ssmItems[i][5]+'px" COLSPAN="'+ssmItems[i][3]+'"><ILAYER><LAYER onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="100%" ALIGN="'+linkAlign+'"><FONT face="'+linkFontFamily+'" Size="'+linkFontSize+'"><A HREF="'+ssmItems[i][1]+'" target="'+ssmItems[i][2]+'" CLASS="ssmItems"><DIV ALIGN="'+linkAlign+'">'+"&nbsp;"+ssmItems[i][0]+'</DIV></A></FONT></LAYER></ILAYER></TD>')
			}
			if(ssmItems[i][4]!="no"&&barBuilt==0){
				buildBar();barBuilt=1
			}
			if(ssmItems[i][4]!="no"){
				document.write('</TR>')
			}
		}
		
		document.write('</table>');
		if (NS6){
			document.write('</TD></TR></TABLE>');
		}
		if (IE||NS6) {
			document.write('</DIV></DIV>');
		}
		if (NS) {
			document.write('</LAYER></ILAYER></LAYER>');
		}
		theleft=-menuWidth;lastY=0;setTimeout('initSlide();', 1);
	}
//------------------------------------------------------------------------------