/*****************************************************************************
Copyright (C) 2008  Ušur HAMZADAYI
******************************************************************************/

function menu2_closeid( thisid ) {
  table = document.getElementById(thisid);
  frame = document.getElementById(thisid+'_hideframe');
  if( frame )
     frame.style.display = 'none';
  table.style.display = 'none';
  table["time_id"]=null;
}


function menu2_onmouseover( thisid , subid , type ) {
	
  elementnormal = document.getElementById(thisid+'a');
  elementover = document.getElementById(thisid+'b');
  elementnormal.style.display = 'none';
  if( navigator.appName == "Microsoft Internet Explorer" )
     elementover.style.display = 'block';
  else
     elementover.style.display = 'table';
	
  elementsub = document.getElementById(subid);	
  if( elementsub != null ) {
     if( elementsub["time_id"] != null ) {
		clearTimeout(elementsub["time_id"]); 
		elementsub["time_id"] = null;
	 }
	 
     elementnormal[ "subid" ] = subid;	 
  	 elementsub["parentid"]= thisid+'a';
	
  	 
     if( navigator.appName == "Microsoft Internet Explorer" ) {
        elementsub.style.display = 'block';
	 }
     else {
        elementsub.style.display = 'table';
	 }
	
	 //Vertival ise
	 if( type == 1 ) {
		elementsub.style.top  = (getmenuTopPos( elementover ) ) +  'px'; 
		elementsub.style.left = (getmenuLeftPos( elementover ) + elementover.offsetWidth ) + 'px';	 
	 }
	 else { //Horizontal ise
		elementsub.style.top  = (getmenuTopPos( elementover ) + elementover.offsetHeight - 4 ) +  'px'; 
		elementsub.style.left = (getmenuLeftPos( elementover ) + 5 ) + 'px';	
	 }
	 menurefreshcalculatePos(elementsub);
  }
}

function menu2_onmouseout( thisid , subid ) {
   elementnormal = document.getElementById(thisid+'a');
   elementover = document.getElementById(thisid+'b');
	 
   elementover.style.display = 'none';
   if( navigator.appName == "Microsoft Internet Explorer" )
      elementnormal.style.display = 'block';
   else
      elementnormal.style.display = 'table';

   elementsub = document.getElementById(elementnormal[ "subid" ]);	
   if( elementsub != null && elementnormal.style.display != 'none' ) {
  	  elementsub["time_id"] = setTimeout("menu2_closeid('"+elementsub.id+"')", 200);  
   }
}


function menu2_onmouseoutsub( tableid , thisid , subid ) {
	
  table	= document.getElementById(tableid);
  td = document.getElementById(thisid);
  elementsub = document.getElementById(subid);
  
  if( td != null ) {
	 td.style.backgroundColor='#E0DCC2';
  }
  
  if( table["time_id"] == null ){
	 table["time_id"] = setTimeout("menu2_closeid('"+table.id+"')", 200);  
  }

  tablechild = document.getElementById(table[ "opensub" ]); 
  if( tablechild != null && tablechild["time_id"] == null ) {
     tablechild["time_id"] = setTimeout("menu2_closeid('"+tablechild.id+"')", 200);  
	  
  }

  //parentlere git
  tableparent = document.getElementById(table[ "parentid" ]); 
  while( tableparent != null && tableparent["type"]==1 ){
	  if( tableparent["time_id"] == null ){
         tableparent["time_id"] = setTimeout("menu2_closeid('"+tableparent.id+"')", 200);  
	  }
      tableparent = document.getElementById(tableparent[ "parentid" ]); 
  }
}

function menu2_onmouseoversub( tableid , thisid , subid ) {
	
  table	= document.getElementById(tableid);
  td = document.getElementById(thisid);
  elementsub = document.getElementById(subid);
  
  if( td != null ) {
	 td.style.backgroundColor='#CABB88';
  }


  if( table["time_id"] != null ){
     clearTimeout(table["time_id"]);	  
	 table["time_id"] = null;
  }

  tableparent = document.getElementById(table[ "parentid" ]); 
  while( tableparent != null && tableparent["type"]==1 ){
	  if( tableparent["time_id"] != null ){
         clearTimeout(tableparent["time_id"]);	  
	     tableparent["time_id"] = null;
	  }
      tableparent = document.getElementById(tableparent[ "parentid" ]); 
  }


  if( elementsub != null ) {
     table[ "subid" ] = subid;	 
	 table[ "type" ] = 1;	 
	 table[ "opensub" ] = subid;	 
  	 elementsub["parentid"]= tableid;

     if( elementsub["time_id"] != null ){
         clearTimeout(elementsub["time_id"]);	  
	     elementsub["time_id"] = null;
     }

     if( navigator.appName == "Microsoft Internet Explorer" )
        elementsub.style.display = 'block';
     else
        elementsub.style.display = 'table';
		
     elementsub.style.top  = (getmenuTopPos( td ) ) +  'px';
     elementsub.style.left = (getmenuLeftPos( td ) + td.offsetWidth ) + 'px';	
	 
	 menurefreshcalculatePos(elementsub);
	 
  }
  else {
	 if( table[ "opensub" ] != null ) {
		elementsub = document.getElementById(table[ "opensub" ]); 
		if( elementsub != null && elementsub.style.display != 'none' ){
		   elementsub["time_id"] = setTimeout("menu2_closeid('"+elementsub.id+"')", 200);  
		}
	 }
  }
}


function UMenu_2_InitSub( menuid , verthorz , array , subid , iWidth , imagePath ) {

  var maindiv = document.getElementById(menuid);
  var child_a = null;
  array.push( "" );
  var lIndex = (array.length-1);
  var subPanels = '<iframe id="'+subid+'_hideframe" style="filter:alpha(opacity=0);-moz-opacity:0;opacity:0; position:absolute;display:none;" frameBorder="0" scrolling="no"></iframe>';
  subPanels += '<table width="'+iWidth+'" id="'+subid+'" style="border:#505050 1px solid;BACKGROUND:#E0DCC2;display:none;position:absolute;" cellpadding="1" cellspacing="0" border="0">';
  
  thissubid = '';
  for(var i =0;i < maindiv.childNodes.length;i++){
      if( maindiv.childNodes[i].nodeName != 'DIV' && maindiv.childNodes[i].nodeName != 'A' ) 
         continue;
		 
      if( maindiv.childNodes[i].nodeName == 'DIV' ) {		 
	     UMenu_2_InitSub( maindiv.childNodes[i].id , verthorz , array , thissubid , iWidth , imagePath );  
	  }
	  else {
         child_a = maindiv.childNodes[i];
		 thisid = subid + i; 
		 thissubid = subid + i + 'sub'; 
		 
		 bSubVarmi = false;
         for(var v =i+1 ;v < maindiv.childNodes.length;v++){
            if( maindiv.childNodes[v].nodeName != 'DIV' && maindiv.childNodes[v].nodeName != 'A' ) 
               continue;
			if( maindiv.childNodes[v].nodeName == 'A' )   
			   break;
			if( maindiv.childNodes[v].nodeName == 'DIV' ) {   
			   bSubVarmi = true;
			   break;
			}
		 }
		 
         subPanels += '<tr>';	  
           subPanels += '<td height="22" style="border-bottom:#505050 1px solid;cursor:pointer;" onclick="menu_onItemClick(\''+child_a.href+'\', \''+child_a.target+'\');" onmouseover="menu2_onmouseoversub( \''+subid+'\' , \''+thisid+'\' , \''+thissubid+'\' );" onmouseout="menu2_onmouseoutsub( \''+subid+'\' , \''+thisid+'\' , \''+thissubid+'\' );" width="100%" id="'+thisid+'">'; 	
		     if( bSubVarmi )
  	            subPanels += '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#303030;text-align:left;padding-left:5px;padding-right:12px;width:auto;WHITE-SPACE:nowrap;BACKGROUND:url('+imagePath+'arrowright.gif) no-repeat center right;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'bullet.gif">&nbsp;&nbsp;'+child_a.firstChild.nodeValue+'</div>';
		     else		
			    subPanels += '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#303030;text-align:left;padding-left:5px;padding-right:12px;width:auto;WHITE-SPACE:nowrap;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'bullet.gif">&nbsp;&nbsp;'+child_a.firstChild.nodeValue+'</div>'; 
		   subPanels += '</td>'; 	
	     subPanels += '</tr>';	  
	  }
		 
  }
  subPanels += '</table>';
  if( lIndex >= 0 )
     array[lIndex] = subPanels ;
  
}


function UMenu_2_Init( menuid , verthorz , headerText , iWidthParent , iWitdhSub , imagePath ) {
  
  var maindiv = document.getElementById(menuid);
  if( maindiv == null )
     return;


  if( iWidthParent <= 0 )
     iWidthParent = '100%';

  var child_a = null;
  
  var newmenuid = menuid + '_parent';
  var subid = ''; 
  var arrayPanels = new Array();
  
  
  if(  verthorz == 'horz') {
	
	 document.write( '<table width="100%" id="'+newmenuid+'" cellpadding="0" cellspacing="0" border="0"><tr>' );
	 document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'leftbar.png"></td>' );
	 if( headerText != "" ) {
	    document.write( '<td style="padding-left:4px;padding-right:4px;padding-top:0px;FONT-FAMILY:tahoma,sans-serif,arial,helvetica;FONT-WEIGHT:normal;FONT-SIZE:12px;color:#BBFFFF;WHITE-SPACE:nowrap;BACKGROUND:url('+imagePath+'bar.png) repeat-x;">'+headerText+'</td>' );	  
		document.write( '<td width="1" ><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'seperator.png"></td>' );
	 }
	 
	 var bflag = false;
     for(var i =0;i < maindiv.childNodes.length;i++ ){
			  
           if( maindiv.childNodes[i].nodeName != 'DIV' && maindiv.childNodes[i].nodeName != 'A' ) 
              continue;
		 
		   if( maindiv.childNodes[i].nodeName == 'DIV' ) {
		  	  UMenu_2_InitSub( maindiv.childNodes[i].id , verthorz , arrayPanels , subid , iWitdhSub , imagePath );  
		   }
		   else { //A ise
		      
  		      child_a = maindiv.childNodes[i];
			  thisid = menuid + i;
			  subid = menuid + i + 'sub';
			  
		      if( bflag ) {
  	 	         document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'seperator.png"></td>' );
		      }
			  
   		      document.write( '<td style="BACKGROUND:url('+imagePath+'bar.png) repeat-x;">' );	  
			  
              //normal  
		      document.write( '<table onclick="menu_onItemClick(\''+child_a.href+'\', \''+child_a.target+'\');" onmouseover="menu2_onmouseover( \''+thisid+'\' , \''+subid+'\' );" onmouseout="menu2_onmouseout( \''+thisid+'\' );" id="'+thisid+'a" width="'+iWidthParent+'" cellpadding="0" cellspacing="0" border="0"><tr>' );
	          document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'leftpane.png"></td>' );
		         document.write( '<td style="width:100%;BACKGROUND:url('+imagePath+'pane.png) repeat-x;">' ); 	
  		         document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;display:block;WHITE-SPACE:nowrap;text-align:center;padding-right:12px;padding-bottom:0px;width:auto;">'+child_a.firstChild.nodeValue+'</div>' ); 	
		         document.write( '</td>' ); 	
              document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'rightpane.png"></td>' );
		      document.write( '</tr></table>' );

			  //over
		      document.write( '<table onclick="menu_onItemClick(\''+child_a.href+'\', \''+child_a.target+'\');" style="cursor:pointer;display:none;" onmouseover="menu2_onmouseover( \''+thisid+'\' , \''+subid+'\' );" onmouseout="menu2_onmouseout( \''+thisid+'\' );" id="'+thisid+'b" width="'+iWidthParent+'" cellpadding="0" cellspacing="0" border="0"><tr>' );
	          document.write( '<td width="1" style="cursor:pointer;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'leftpaneover.png"></td>' );
		         document.write( '<td style="cursor:pointer;width:100%;BACKGROUND:url('+imagePath+'paneover.png) repeat-x;">' ); 	
  		         document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;cursor:pointer;display:block;WHITE-SPACE:nowrap;text-align:center;padding-right:12px;padding-bottom:0px;width:auto;">'+child_a.firstChild.nodeValue+'</div>' ); 	
		         document.write( '</td>' ); 	
              document.write( '<td width="1" style="cursor:pointer;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'rightpaneover.png"></td>' );
		      document.write( '</tr></table>' );
			  
  		      document.write( '</td>' );
		      bflag = true;
		   
		  }
	  }
	  document.write( '<td width="100%" style="BACKGROUND:url('+imagePath+'bar.png) repeat-x;"></td>' );	  
	  document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'rightbar.png"></td>' );
	  document.write( '</tr></table>' );
  }
  else { //vertical
	 
	 
	 if( headerText != "" ) {
	    document.write( '<table width="'+iWidthParent+'" cellpadding="0" cellspacing="0" border="0">' ); 
	    document.write( '<tr>'); 
		document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertheaderleftbar.png"></td>' );
	    document.write( '<td style="text-align:center;padding-left:4px;padding-right:4px;padding-bottom:0px;FONT-FAMILY: tahoma,arial, helvetica, sans-serif;FONT-WEIGHT:normal;FONT-SIZE:13px;color:#BBFFFF;WHITE-SPACE:nowrap;BACKGROUND:url('+imagePath+'vertheaderbar.png) repeat-x;">'+headerText+'</td>' );	  
		document.write( '<td width="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertheaderrightbar.png"></td>' );
		document.write( '</tr></table>' );
	 }
	  

	 document.write( '<table width="'+iWidthParent+'" cellpadding="0" cellspacing="0" border="0">' ); 
     for(var i =0;i < maindiv.childNodes.length;i++ ){
			
           if( maindiv.childNodes[i].nodeName != 'DIV' && maindiv.childNodes[i].nodeName != 'A' ) 
              continue;
		 
		   if( maindiv.childNodes[i].nodeName == 'DIV' ) {
		  	  UMenu_2_InitSub( maindiv.childNodes[i].id , verthorz , arrayPanels , subid , iWitdhSub , imagePath );  
		   }
		   else { //A ise
		      
  		      child_a = maindiv.childNodes[i];
			  thisid = menuid + i;
			  subid = menuid + i + 'sub';
			  
        	  bSubVarmi = false;
              for(var v =i+1 ;v < maindiv.childNodes.length;v++){
                 if( maindiv.childNodes[v].nodeName != 'DIV' && maindiv.childNodes[v].nodeName != 'A' ) 
                    continue;
			     if( maindiv.childNodes[v].nodeName == 'A' )   
			        break;
			     if( maindiv.childNodes[v].nodeName == 'DIV' ) {   
			        bSubVarmi = true;
			        break;
			     }
		      }
			  
			  
   		      document.write( '<tr><td>' );	  
			  
              //normal  
		      document.write( '<table style="padding: 0px;margin: 0px;" onclick="menu_onItemClick(\''+child_a.href+'\', \''+child_a.target+'\');" onmouseover="menu2_onmouseover( \''+thisid+'\' , \''+subid+'\' , 1 );" onmouseout="menu2_onmouseout( \''+thisid+'\' );" id="'+thisid+'a" width="100%" cellpadding="0" cellspacing="0" border="0"><tr>' );
	          document.write( '<td width="1" height="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertleftpane.png"></td>' );
	          document.write( '<td height="1" style="width:100%;BACKGROUND:url('+imagePath+'vertpane.png) repeat-x;">' ); 	
			  if( bSubVarmi )	 
  		         document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;display:block;WHITE-SPACE:nowrap;text-align:left;padding-right:12px;padding-bottom:0px;width:auto;BACKGROUND:url('+imagePath+'arrowrightwhite.gif) no-repeat center right;">'+child_a.firstChild.nodeValue+'</div>' ); 	
              else
  		         document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;display:block;WHITE-SPACE:nowrap;text-align:left;padding-right:12px;padding-bottom:0px;width:auto;">'+child_a.firstChild.nodeValue+'</div>' ); 	
		      document.write( '</td>' ); 	
              document.write( '<td width="1" height="1"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertrightpane.png"></td>' );
		      document.write( '</tr></table>' );

			  //over
		      document.write( '<table onclick="menu_onItemClick(\''+child_a.href+'\', \''+child_a.target+'\');" style="cursor:pointer;display:none;" onmouseover="menu2_onmouseover( \''+thisid+'\' , \''+subid+'\' , 1 );" onmouseout="menu2_onmouseout( \''+thisid+'\' );" id="'+thisid+'b" width="100%" cellpadding="0" cellspacing="0" border="0"><tr>' );
	          document.write( '<td width="1" style="cursor:pointer;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertleftpaneover.png"></td>' );
		      document.write( '<td style="cursor:pointer;width:100%;BACKGROUND:url('+imagePath+'vertpaneover.png) repeat-x;">' ); 	
			  if( bSubVarmi )	 
  		         document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;cursor:pointer;display:block;WHITE-SPACE:nowrap;text-align:left;padding-right:12px;padding-bottom:0px;width:auto; BACKGROUND:url('+imagePath+'arrowrightwhite.gif) no-repeat center right;">'+child_a.firstChild.nodeValue+'</div>' ); 	
              else
			     document.write( '<div style="FONT-FAMILY: arial, helvetica, sans-serif;FONT-WEIGHT:bold;FONT-SIZE:11px;color:#ffffff;cursor:pointer;display:block;WHITE-SPACE:nowrap;text-align:left;padding-right:12px;padding-bottom:0px;width:auto;">'+child_a.firstChild.nodeValue+'</div>' ); 	 
		      document.write( '</td>' ); 	
              document.write( '<td width="1" style="cursor:pointer;"><img vspace="0" hspace="0" align="absmiddle" border="0" src="'+imagePath+'vertrightpaneover.png"></td>' );
		      document.write( '</tr></table>' );
			  
  		      document.write( '</td></tr>' );
	
		   
		  }
	  }
	  document.write( '</table>' );
  }


  for (key in arrayPanels) {
     document.write(arrayPanels[key]);  
  }


}