$(document).ready(function(){
    Cufon.replace('div.nav ul li a',{
        forceHitArea:true,
        hover:'true'
    });
//    Cufon.replace('ul.secondLevel li a',{
//        forceHitArea:true,
//        hover:'true'
//    });
//    Cufon.replace('ul.thirdLevel li a',{
//        forceHitArea:true,
//        hover:'true'
//    });

    //nav
    $('.nav ul li').each(function(){
        var ul = $(this).children('ul');
        var ulHeight = 0;

        if($(this).parent('ul.firstLevel').length == 0)
        {
            if(ul.length)
            {
                ul.children('li').each(function(){
                    ulHeight += $(this).height();
                });

                $(this).css({
                    height:ulHeight+18
                });
                
            }
        }
    });
    $('.secondLevel').hide();
    $('.nav ul li').hover(function(){
        var ul = $(this).children('ul');

        ul.show();

    },function(){
        if($(this).parent('ul.firstLevel').length)
            $(this).children('ul').hide();
    });

    //slideshow
    $('.slideshow').each(function(){
        var ul = $(this).children('ul');
        var li = ul.children('li');

        if(li.length > 1)
        {
            li.each(function(){
                if($(this).prev('li').length)
                    $(this).hide();
                else
                    $(this).addClass('active');
            });
        }
    });
    setInterval(showSlideshow,5000);
});

function showSlideshow()
{
    var ul = $('.slideshow').children('ul');
    var li = ul.children('li');
    var current = ul.children('li.active');

    if(current.length)
    {
        var next = current.next('li');
        var first = ul.children('li:first');
        if(next.length)
        {
            current.fadeOut('slow', function(){
                $(this).removeClass('active');
                next.fadeIn('slow').addClass('active');
            });
        }
        else if(first.length)
        {
            current.fadeOut('slow', function(){
                $(this).removeClass('active');
                first.fadeIn('slow').addClass('active');
            });
        }
    }
}
function openDir( form ) {
    var newIndex = form.fieldname.selectedIndex;
    if ( newIndex == 0 ) {
        alert( "Please select a location!" );
    } else {
        cururl = form.fieldname.options[ newIndex ].value;
        window.location.assign( cururl );
    }
} 
