// JavaScript Document

function setImage( eL , imgSrc, dontClear )
{
    eL.src = "img/" + imgSrc;
    
    
    if( dontClear == 'undefined')
     dontClear = false;    

    var subItems = new Array( 'm2', 'm3' );
    
    var isMain = ( eL.parentNode.parentNode.id.indexOf( 'sub_' )  == -1  ) ? true : false;
    
    
    if( isMain )
    {
    
         if( eL.parentNode.id == 'm2' )
	 {
	      var subItem = $( "sub_m3" );
	      SetOpcity( subItem, 0 );    
	      subItem.style.display = "none";   
	 }
	 else if( eL.parentNode.id == 'm3' )
	 {
	      var subItem = $( "sub_m2" );
	      SetOpcity( subItem, 0 ); 
	      subItem.style.display = "none";   
	 }
	 else if( eL.parentNode.parentNode.id.indexOf( "sub_" ) == -1 )
	 {	    
	      var subItem = $( "sub_m3" );
	      SetOpcity( subItem, 0 );    
	      subItem.style.display = "none";   
	      
	      var subItem = $( "sub_m2" );
	      SetOpcity( subItem, 0 ); 
	      subItem.style.display = "none";   
	 }
    
    }
    else
    {
        var pEl = eL.parentNode.parentNode;
    
        clearTimeout( window.clSub );
        if( !dontClear )
	{                
            window.clSub  = setTimeout( function(){  
	                                             eL.parentNode.parentNode.style.display = "none"; 
						     closeMain( pEl.id.substring( 4, pEl.id.length ) );
						   }, 500 );
	    
        }
	else
	{   
  	    pEl.style.display = "block";
	    openMain( pEl.id.substring( 4, pEl.id.length ) );
	}
    }
    
}

function openMain( eLID )
{
     eL = $( eLID );
     eLImg = eL.getElementsByTagName( 'img' ).item( 0 );
     eLImg.onmouseover();
}

function closeMain( eLID )
{
     eL = $( eLID );
     eLImg = eL.getElementsByTagName( 'img' ).item( 0 );
     eLImg.onmouseout();
}

function slideSub( blockId )
{
       slideBlock = $( blockId );
       
       blockLinks = slideBlock.getElementsByTagName( 'a' );

       slideBlock.style.display = "block";      
       slideBlock.cOpacity = 0 ;
       
       
       for( var cL = 0; cL < blockLinks.length; cL ++ )
       {
	  blockLinks[ cL ].cWidth = 0;
	  showLink( slideBlock, blockLinks[ cL ] )         ;
       }
       
}

SubItemWidth = 90;
waitLeftTime = 5;
cWidthStep   = 2;
cOpacityStep  = ( cWidthStep / SubItemWidth );


function showLink( parentDiv, LinkItem )
{
    LinkItem.style.width = LinkItem.cWidth + "px";
    SetOpcity( parentDiv, parentDiv.cOpacity);
        
          
    if( LinkItem.cWidth < 90 )
    {
        parentDiv.cOpacity = Number( parentDiv.cOpacity )+ 0.01;
        LinkItem.cWidth = LinkItem.cWidth + cWidthStep;
        window.lfTime = setTimeout( function(){ showLink( parentDiv, LinkItem)}, waitLeftTime)       
    }
    else
    {
      SetOpcity( parentDiv, 1);
    }  
}


/*

function prepareMenu( MenuID )
{
    
    mainMenu = document.getElementById( MenuID );
    
    if( mainMenu )
    {
         clearSubItems( mainMenu );
         
         var MenuLinks = mainMenu.getElementsByTagName( 'a' );
         if( MenuLinks )
         {
              for( var cM = 0; cM < MenuLinks.length; cM++)
              {     
	            MenuLinks[ cM ].onmouseover  = function() 
		                                   { 
						       swapImageIn( this ) 
						       if( pId = this.parentNode.id )
						       {
						            if( pId.indexOf("sub_") != -1 )
							    {
							       rowOver( this, mainMenu );
							    }						       
						       }
						       
						     
						   };        
                    MenuLinks[ cM ].onclick = function() { rowOver( this, mainMenu ) };
                    MenuLinks[ cM ].onmouseout  = function() { waitOut( this, mainMenu ) };        
		    
		    var ImgMenu = MenuLinks[ cM ].getElementsByTagName( "img" )[0];
		    MenuLinks[ cM ].old = ImgMenu.src;
              }          
         }         
    }  
}

function waitOut( MenuLink, mainMenu )
{
   swapImageOut( MenuLink );
 
   window.clTime = setTimeout( function(){ rowOut( MenuLink, mainMenu )}, 500 );  
}

function rowOut( MenuLink, mainMenu )
{

     if( MenuLink.id )
     {
          var SubDiv = document.getElementById( 'sub_' + MenuLink.id );
	  
	  if( SubDiv )
	  {
	      SubDiv.style.display = 'none';
	  }     
     
     }

   return;
}

function rowOver( MenuLink, mainMenu )
{
    var SubItemsDiv = document.getElementById( 'sub_' + MenuLink.id);
    
    
    //swapImageIn( MenuLink );        
    
    var MenuSubItems = mainMenu.getElementsByTagName( 'div' );    
           
    if( MenuSubItems )
    {      
       for( var cM = 0; cM < MenuSubItems.length; cM++)
       {
            MenuSubItems[ cM ].style.display = 'none';   
       }      
    }
    
        
    if( SubItemsDiv )
    {        
       SubItemsDiv.style.display = '';
     
       clearSubItems( MenuLink );
       
       MenuLink.onmouseout  = function() { waitOut( this, mainMenu ) }; 
                    
       var SubItems = SubItemsDiv.getElementsByTagName( 'a' );
        
        if( SubItems )
        {
            SubItemsDiv.cOpacity = 0;    
	    SubItemsDiv.style.left = MenuLink.offsetLeft;
	    clearTimeout( window.lfTime );
                
            for( var cS =0; cS < SubItems.length; cS++)
            {                         
                 SubItems[ cS ].cWidth   = 0;
                 showLink( SubItemsDiv, SubItems[ cS ] );
            }         
        }              
    }
    else 
    {
             if(mainID = MenuLink.parentNode.id.substring(4, MenuLink.parentNode.id.length ) )
             {
                  MenuLink.parentNode.style.display = '';

                 var mainLink = document.getElementById( mainID );
                 if( mainLink )		 
                 {    
		    clearTimeout( window.clTime );
		    swapImageIn( mainLink )
		    MenuLink.parentNode.display = '';
		    MenuLink.onmouseout  = function()
		    {
		        swapImageOut( mainLink );
			swapImageOut( MenuLink );
			waitOut( MenuLink, mainMenu );
//			clearSubItems( mainMenu );
		    }                  
                 }
             }
     }  
}

function SetOpacity( Item, Value )
{

      Item.style.opacity = Value;
      Item.style.filter  = 'alpha(opacity='+(Value*100)+')';  
}

function showLink( parentDiv, LinkItem )
{
    LinkItem.style.width = LinkItem.cWidth;
    SetOpacity( parentDiv, parentDiv.cOpacity);
        
          
    if( LinkItem.cWidth < SubItemWidth)
    {
        parentDiv.cOpacity = Number( parentDiv.cOpacity )+ 0.01;
        LinkItem.cWidth = LinkItem.cWidth + cWidthStep;
        window.lfTime = setTimeout( function(){ showLink( parentDiv, LinkItem)}, waitLeftTime)       
    }
    else
    {
      SetOpacity( parentDiv, 1);
    }  
}

function clearSubItems( mainMenu )
{
    var MenuSubItems = mainMenu.getElementsByTagName( 'div' );    
           
    clearTimeout( window.clTime );
    
    if( MenuSubItems )
    {      
       for( var cM = 0; cM < MenuSubItems.length; cM++)
       {
            MenuSubItems[ cM ].style.display = 'none';   
       }      
    }
}

function swapImageIn( CurrentLink )
{

        var imgElement = CurrentLink.getElementsByTagName( "img" )[0];

//        imgElement.src = CurrentLink.getAttribute('class');
	imgElement.src = CurrentLink.className;
}

function swapImageOut( CurrentLink )
{

        var imgElement = CurrentLink.getElementsByTagName( "img" )[0];

        imgElement.src = CurrentLink.old;
}
*/