﻿
var animationDuration=500;
var defaultTab;


$(function(){

defaultTab=$('ul.menu > li.over');


$('ul.menu > li').mouseenter(function(){
  
  
  //Open Description
  selectTab($(this));


});




$('li.largeLogo').mouseenter(function(){
     var me=$(this);
     animateOpenText(me);
     
     selectItem(this);
     
 
})

$('UL.LargeMenu').mouseleave(function(){

var items = $('.largeContent');
var numItems=items.length;
$('ul.menu > li').removeClass('over');

items.each(function(index){
    $(this).stop().animate({width:0},animationDuration,function(){
        if(index==numItems-1){
        $('.largeLogo').animate({width: 175},animationDuration,function(){
    
        $('.LargeMenu').addClass('allClosed');
        $(this).width('');
        
        
        
        } );
        
        }
    
    });




});


});



function selectItem(elm){


    var tabId = $(elm).attr('class').split(' ')[1   ];
   selectTab(  $("ul.menu > li#" + tabId));

}





function closeAll(){


  $('DIV.extended').find('.largeContent').width(0);
     $('DIV.extended').children().addClass('allClosed');
     
    if(defaultTab.length>0)
        selectTab(defaultTab);
    else
        $("ul.menu > li").removeClass('over');

}

});







function animateOpenText(elm){
var maxWidth=130;
$('.largeLogo').each(function(){
    if($(this).width()>maxWidth)
        maxWidth=$(this).width();

});

var ratio = parseFloat(maxWidth-130)/45;

var duration = parseInt( animationDuration* ratio);
//var isAllClosed= $('.LargeMenu').hasClass('allClosed');
//if(isAllClosed){
     $('.largeLogo').animate({width: 130},duration,function(){
    
        $('.LargeMenu').removeClass('allClosed');
        $(this).width('');
        
            doOpenAnimation(elm);
        
        } );
 
    
 //   }
//    else
//        doOpenAnimation(elm);






}

function doOpenAnimation(elm){

var animObj=elm;    
if(elm.hasClass('largeLogo'))
    animObj=elm.next();


animObj.stop().animate({width:230},animationDuration);
animObj.siblings('.largeContent').stop().animate({width:0},animationDuration);

}



function animateCloseText(elm){
var animObj=elm;    
if(elm.hasClass('largeLogo'))
    animObj=elm.next();

animObj.stop().animate({width:0},animationDuration, function(){ 

    var isAllClosed=true;
    $('.largeContent').each(function(){
        if($(this).width()>0 && isAllClosed)
            isAllClosed=false;
    
    });
    
    if(isAllClosed)
    $('.largeLogo').animate({width: 175},animationDuration,function(){
    
        $('.LargeMenu').addClass('allClosed');
        $(this).width('');
        
        
        
        } );
        


});

}

function selectTab(tab)
{
    tab.addClass('over');
    tab.siblings().removeClass('over');
}
