// Different eye-candy with Jquery

var timeoutId = 0;
var onHeaderItemDiv = false;
var user_login_error = false;

$(document).ready(function() {
    // feature box sliding
    /*
    $('div.feature_box').hover(function() { // Hover effect
        $(this).find("div.feature_box_text").stop().animate({top: 10, height: 110}, "fast");
    }, function () {
        $(this).find("div.feature_box_text").stop().animate({top: 110, height: 10}, "fast");
    }).each(function () { // Make whole thing a 'link'
        $(this).css({cursor: "pointer"}).click(function () {
            document.location.href = $(this).find("a").attr("href");
        });
    });
    */

    $('div.feature_box').hover(function() { // Hover effect
        $(this).find("div.feature_box_text").stop().animate({top: 0, height: 110}, "fast");
    }, function () {
        $(this).find("div.feature_box_text").stop().animate({top: 110, height: 0}, "fast");
    }).each(function () { // Make whole thing a 'link'
        $(this).css({cursor: "pointer"}).click(function () {
            document.location.href = $(this).find("a").attr("href");
        });
    });


    if (user_login_error) {
        $(this).find('#user_login_div:hidden').slideDown('fast');
    }

    // header menu sliding
    $('#header_items li').click(
        function () {
            if (!onHeaderItemDiv) {
                $('.header_slide').slideUp('fast');
            }
            $(this).find('.header_slide:hidden').slideDown('fast');
        }
    );

    $(".header_slide_content").bind("mouseenter", function(){
        onHeaderItemDiv = true;
    }).bind("mouseleave",function() {
        onHeaderItemDiv = false;
    });

    // site main menu sliding
    $('.header_menu_item').hover(
        function () {
            clearTimeout(timeoutId);
            if ($(this).find('div').is(':visible')) {

            } else {
                $('#header_menu div').slideUp('fast');
                $('#header_menu li').removeClass('active');
                $(this).find('div').slideDown('fast');
                $(this).addClass('active');
            }
        },
        function () {
        }
    );

    $("#header_menu div").bind("mouseenter", function(){
        clearTimeout(timeoutId);
    }).bind("mouseleave",function() {
        $(this).slideUp('fast');
        $('#header_menu li').removeClass('active');
    });

    $("#header_menu").bind("mouseleave",function() {
        timeoutId = setTimeout("hideAllMenus()", 1000);
    });
});

function hideAllMenus () {
    $('#header_menu div').slideUp('fast');
    $('#header_menu li').removeClass('active');
    clearTimeout(timeoutId);
    timeoutId = 0;
}
