﻿var menu_slide_time = 25;
var menu_slide_speed = 10;
var sub_menu_slide_speed = 10;
var menu_animation_speed = 5;
var menu_hide_speed = 500;

var menu_block_height;
var menu_block=null;
var menu_interval=null;
var menu_time_out = null;

var menu_block2_width;
var menu_block2=null;
var menu_interval2=null;
var menu_time_out2 = null;


function StopAnimation1()
{
    if(menu_interval != null)
    {
        clearInterval(menu_interval);
        menu_interval = null;
    }
}

function StopAnimation2()
{
    if(menu_interval2 != null)
    {
        clearInterval(menu_interval2);
        menu_interval2 = null;
    }
}


function DoSlide()
{
    if(menu_block==null) return;
    var k = 1.2-( (menu_block_height + parseInt(menu_block.style.top) )/menu_block_height  );
    var current_speed = menu_slide_speed * (k*k+k);
    menu_block.style.top = parseInt(menu_block.style.top) + current_speed + "px";
    if( parseInt(menu_block.style.top) >= 0)
    {
        menu_block.style.top = "0px";
        StopAnimation1(menu_interval);
    }
}

function DoSlide2()
{
    if(menu_block2==null) return;
    menu_block2.style.left = parseInt(menu_block2.style.left) + sub_menu_slide_speed + "px";

    if( parseInt(menu_block2.style.left) >= 0)
    {
        menu_block2.style.left = "0px";
        StopAnimation2(menu_interval2);
    }
}

function OpenSub1(e, elem )
{
    if(menu_time_out!=null)
    {
        clearTimeout(menu_time_out);
        menu_time_out = null;
    }
    var container = elem.getElementsByTagName('div')[0].getElementsByTagName('div')[0];
    var new_menu_block = elem.getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('div')[0];
    
    if(menu_block != new_menu_block ) 
    {
        DoCloseSub1();
        menu_block = new_menu_block;
    }else 
    {   
        // This is the same //
        return;
    }
          
    if( menu_interval==null)
    {
        menu_block_height = parseInt( menu_block.offsetHeight );
        menu_slide_speed = menu_block_height / menu_slide_time;
        menu_block.style.top = "-"+menu_block_height+"px";
        container.style.visibility="visible";
        // launch animation //+
        menu_interval = setInterval("DoSlide();",menu_animation_speed);
    }
}



function OpenSub2(e, elem )
{
    if(menu_time_out2!=null)
    {
        clearTimeout(menu_time_out2);
        menu_time_out2 = null;
    }
    var container = elem.getElementsByTagName('div')[0].getElementsByTagName('div')[0];
    var new_menu_block = elem.getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('div')[0];
    
    if(menu_block2 != new_menu_block ) 
    {
        DoCloseSub2();
        menu_block2 = new_menu_block;
    }else 
    {   
        // This is the same //
        return;
    }
          
    if( menu_interval2==null)
    {
        menu_block2_width = parseInt( menu_block2.offsetWidth );
        menu_block2.style.left = "-"+menu_block2_width+"px";
        container.style.visibility="visible";
        // launch animation //
        menu_interval2 = setInterval("DoSlide2();",menu_animation_speed);
    }
}


function CancelEvent(e,evObj)
{
  if( !e ) 
      {
         if( window.event ) 
         {
            //Internet Explorer
            e = window.event;
         } else {
                    //total failure, we have no way of referencing the event
                    return;
                }
        }
  
  if( window.event ) 
  {
        e.cancelBubble = true;// IE //
  }
  if(e.stopPropagation) 
  {
        e.stopPropagation() ; // DOM //
  }
}


function CloseSub1(e, elem )
{
    menu_time_out = setTimeout("DoCloseSub1()",menu_hide_speed);
    
}

function DoCloseSub1()
{
    if(menu_block != null)
    {
        StopAnimation1(); // If it animates  - stop it //
        menu_block.parentNode.style.visibility="hidden";
        menu_block = null;
       
    }
}

function CloseSub2(e, elem )
{
    menu_time_out2 = setTimeout("DoCloseSub2()",menu_hide_speed);
    
}

function DoCloseSub2()
{
    if(menu_block2 != null)
    {
        StopAnimation2(); // If it animates  - stop it //
        menu_block2.parentNode.style.visibility="hidden";
        menu_block2 = null;
       
    }
}



