var searchClick = false,
    menuClick = false,
    openMenuBool = false,
    hoverNewsRotator = false; 

$(function($) {

    setInterval (rotateNews, 5000);

    //$('body, html').removeClass('no-js');

    //set height of the container div, than it will set it on window resize
    setHeight();

    var inMotion = false;

    //openMenu();
    //	closeFooter();			

    //click footer toggle button				
    $('.footerControl').click(function() {
        if ($('.footerSize').height() == 3) { openFooter(); closeSearch(); closeMenu(); }
        else closeFooter();
    });

    //hover footer toggle button
    $('.footerControl').hover(function() {
        $(this).stop(true, true).animate({ top: '-25px' }, 200);
    }, function() {
        $(this).stop(true, true).animate({ top: '-23px' }, 200);
    });


    //hover close search button	
    $('.searchBoxControlClose').hover(function() {
        $(this).stop(true, true).animate({ left: '0px' }, 200);
    }, function() {
        $(this).stop(true, true).animate({ left: '-2px' }, 200);
    });

    //hover close menu button 
        $('.menuControlClose').hover(function() {
        $(this).stop(true, true).animate({ right: '0px' }, 200);
    }, function() {
        $(this).stop(true, true).animate({ right: '-2px' }, 200);
    });

    //hover open search button	
    $('.openSearch').hover(function() {
        $(this).stop(true, true).animate({ left: '0px' }, 200);
        return;
    }, function() {
        if (searchClick) return;
        $(this).stop(true, true).animate({ left: '-2px' }, 200);
        return;
    });

    //hover on open menu button
    $('.openMenu').hover(function() {
        $(this).stop(true, true).animate({ right: '0px' }, 200);
        return;
    }, function() {
        if (menuClick) return;
        $(this).stop(true, true).animate({ right: '-2px' }, 200);
        return;
    });

    //click on open search button
    $('.openSearch').click(function() {
        searchClick = true;
        openSearch();
        closeFooter();
        closeMenu();
    });

    //click on close search

    $('.searchBoxControlClose').click(function() {
        closeSearch();
        searchClick = false;
    });

    //click on open menu button

    $('.openMenu').click(function() {
        menuClick = true;
        openMenu();
        closeFooter();
        closeSearch();
    });

    //click on close menu button
    $('.menuControlClose').click(function() {
        closeMenu();
        menuClick = false;
    });

}); // document ready

$(window).resize(function() {
    setHeight();
});



function hideMenus() {
$('.openSearch, .openMenu, #slidecaption').hide();

}

function setHeight() {
    var winHeight = $(window).height();
    if (winHeight > 700)
        $('#siteWrapper, .registrationWrapper').css('height', winHeight);
    else $('#siteWrapper, .registrationWrapper').css('height', '700');
}

function closeFooter() {
    $('.credits').fadeOut(400);
    $('.footerSize').stop(true, true).animate({ height: '3px' }, 400);
    $('.footerControl').addClass('footerControlClosed');
    $('#navigation').stop(true, true).animate({ top: '-40px' }, 200);
}

function openFooter() {
    $('.footerSize').stop(true, true).animate({ height: '170px' }, 400);
    $('.footerControl').removeClass('footerControlClosed');
    $('.credits').fadeIn(600);
    $('#navigation').stop(true, true).animate({ top: '-15px' }, 200);
}

function openSearch() {
    $('.openSearch').stop(true, true).animate({ left: '-38px' }, 400);
    $('#searchBox').stop(true, true).animate({ left: '0px' }, 400);
}
function closeSearch() {
    $('#searchBox').stop(true, true).animate({ left: '-290px' }, 400);
    $('.openSearch').stop(true, true).animate({ left: '-3px' }, 400);
}



function openMenu() {
    openMenuBool = true; 
    $('.openMenu').stop(true, true).animate({ right: '-38px' }, 400);
    $('#mainMenu').stop(true, true).animate({ right: '0px' }, 400);
}
function closeMenu() {
    openMenuBool = false; 
    $('#mainMenu').stop(true, true).animate({ right: '-271px' }, 400);
    $('.openMenu').stop(true, true).animate({ right: '-3px' }, 400);
}

function hideNavigation(){
    $('#navigation').hide();
}




function rotateNews() {
    if (!openMenuBool) return; 
    $('ul.newsRotator').delay(1000).animate({ top: '-82px'}, 500, function(){
        var liHtml = $('li', this ).first().html();
        $('li', this).first().remove();
        $(this).append('<li>' + liHtml + '</li>').css('top',0);
    });

}
