﻿var _divWidth,_ulWidth,liDiff=0,UlDiff=0,_liWidth,_itemCount,_ulHeight=0,_divHeight=0,_topNavHeight,_bottomNavHeight,liHeight,_toTop,_interval,_autoInterval,_maxTop,_pos;
    function whatsNew(container,bunch)
    {
    namespaceNewLib={
    _div:$(container),
    _conentContainer:$('#content_container',container),
    _ul:$('ul',container),
    _li:$('ul li',container),
    _link:$('ul li a',container),
    _topNav:$('#top_nav',container),
    _bottomNav:$('#bottom_nav',container),
    _topNavBtn:$('#top_nav #move_top',container),
    _bottomNavBtn:$('#move_bottom',container),
    _bunch:bunch
    };
    whatsNew_Initializer();
    }
    function whatsNew_Initializer()
    {
    _pos=true;
     _divWidth=$(namespaceNewLib._div).outerWidth(true);
     _ulWidth=$(namespaceNewLib._ul).outerWidth(true);
    if(_ulWidth>_divWidth)
    {
     UlDiff=_ulWidth-_divWidth;
    _ulWidth=_divWidth-UlDiff;
    }
     _liWidth=$(namespaceNewLib._li).outerWidth(true);
    if(_liWidth>_ulWidth)
    {
     liDiff=_liWidth-_ulWidth;
    _liWidth=_ulWidth-liDiff;
    }
    
    $(namespaceNewLib._ul).width(_ulWidth);
    $(namespaceNewLib._li).width(_liWidth);
    
     _itemCount=$(namespaceNewLib._li).length;
    
    
     _topNavHeight=$(namespaceNewLib._topNav).height();
     _bottomNavHeight=$(namespaceNewLib._bottomNav).height();
    
    _divHeight=_topNavHeight+_bottomNavHeight;
    
    $(namespaceNewLib._li).each(function(index){
     liHeight=$(this).outerHeight(true);
    _ulHeight=_ulHeight+liHeight;
    if(index<namespaceNewLib._bunch)
    {
    _divHeight=_divHeight+liHeight;
     if(liDiff>0)
    {
    _divHeight=_divHeight+liDiff;
    }
    }
    $(this).height(liHeight);
    });
    if(UlDiff>0)
    {
    _divHeight=_divHeight-UlDiff;
    }
    $(namespaceNewLib._ul).height(_ulHeight);
    $(namespaceNewLib._conentContainer).height(_divHeight-(_bottomNavHeight+_topNavHeight));
    $(namespaceNewLib._div).height(_divHeight);
     _maxTop=$(namespaceNewLib._ul).height();
    _maxTop=_maxTop-(_bottomNavHeight+_topNavHeight);
    _autoInterval=setInterval('auto_animation()',100);
    
    $(namespaceNewLib._topNavBtn).hover(function(){
    clearInterval(_autoInterval);
    _interval=setInterval('slideUp_animation()',50);
    },
    function(){
    clearInterval(_interval);
    _autoInterval=setInterval('auto_animation()',100);
    });
    
    $(namespaceNewLib._bottomNavBtn).hover(function(){
     clearInterval(_autoInterval);
    _interval=setInterval('slideDown_animation()',50);
    },
    function(){
    clearInterval(_interval);
     _autoInterval=setInterval('auto_animation()',100);
    });
    
    $(namespaceNewLib._li).hover(function(){
    clearInterval(_autoInterval);
    },
    function(){
    _autoInterval=setInterval('auto_animation()',100);
    });
    }
    
    function auto_animation()
    {
    if(_pos==true)
    {
     slideUp_animation();
    }
    else
    {
    slideDown_animation();
    }
    }
    
    function slideUp_animation()
    {
    var _currTop=$(namespaceNewLib._ul).css('top');
    _currTop=_currTop.replace('px','');
    _currTop=parseInt(_currTop);
    _toTop=_currTop-2;
    if(_currTop>=eval(_maxTop*-1))
    {
    $(namespaceNewLib._ul).css('top',_toTop);
    }
    else
    {
    _pos=false;
    }
    }
    function slideDown_animation()
    {
    var _currTop=$(namespaceNewLib._ul).css('top');
    _currTop=_currTop.replace('px','');
    _currTop=parseInt(_currTop);
    _toTop=_currTop+2;
    if(_currTop<=0)
    {
    $(namespaceNewLib._ul).css('top',_toTop);
    }
    else
    {
    _pos=true;
    }
    }
