$(function() {
	$( "button, .button", ".ui_form" ).button();
});

$(function() {
	$("#resizable").resizable({
		maxHeight: 250,
		maxWidth: 380,
		minHeight: 150,
		minWidth: 185
	});
});

// Used in right hand nav to prevent indexing links in spindle
function gotoUrl(url) {
    location.href = url;
}

$(document).ready(function() {

    // Loop through galleria imagse, and store alt tags for alter use

    loginMouseLeaveTimeout = null;
    loginMouseEnterTimeout = null;

    $('#nav-login-link').mouseenter(function() {
        clearTimeout(loginMouseEnterTimeout);
        $('#nav-login-link').addClass('active');
        $('#nav-login-dropdown').show();
    });
    $('#nav-login-link').mouseleave(function() {
        loginMouseLeaveTimeout = setTimeout(function () {
            $('#nav-login-link').removeClass('active');
            $('#nav-login-dropdown').hide();
        }, 100);
    });
    $('#nav-login-dropdown').mouseenter(function () {
        clearTimeout(loginMouseLeaveTimeout);
    });
    $('#nav-login-dropdown').mouseleave(function () {
        loginMouseEnterTimeout = setTimeout(function () {
            $('#nav-login-dropdown').hide();
            $('#nav-login-link').removeClass('active');
        }, 100);
    });

    // Fix for chrome bug with Jquery mouseleave on input
    $('div.ddlogin input').mouseenter(function() {
        $('.ddlogin').css('display', 'block')
    });

    followMouseLeaveTimeout = null;
    followMouseEnterTimeout = null;

    $('#nav-follow-link').mouseenter(function() {
        clearTimeout(followMouseEnterTimeout);
        $('#nav-follow-link').addClass('active');
        $('#nav-follow-dropdown').show();
    });
    $('#nav-follow-link').mouseleave(function() {
        followMouseLeaveTimeout = setTimeout(function () {
            $('#nav-follow-link').removeClass('active');
            $('#nav-follow-dropdown').hide();
        }, 100);
    });
    $('#nav-follow-dropdown').mouseenter(function () {
        clearTimeout(followMouseLeaveTimeout);
    });
    $('#nav-follow-dropdown').mouseleave(function () {
        followMouseEnterTimeout = setTimeout(function () {
            $('#nav-follow-dropdown').hide();
            $('#nav-follow-link').removeClass('active');
        }, 100);
    });







    var timeoutMouseLeave = new Array();
    var timeoutMouseEnter = new Array();

    $('.top-rollover').mouseenter(function() {
        $('.top-rollover').removeClass('active');
        $('.hover-nav').css('height', 0).css('opacity', 0).hide().stop();


        var id = $(this).attr('id');
        if (typeof timeoutMouseLeave[id] != "undefined") {
            clearTimeout(timeoutMouseLeave[id]);
        }

        var innerHeight = $('#'+id+'-nav').find('.hover-inner').css('height');
        $('#'+id+'-nav').stop().animate({
            height: innerHeight,
            opacity: 1.0
        }, 200);

        $(this).addClass('active');
    });
    $('.top-rollover').mouseleave(function() {
        var id = $(this).attr('id');
        $('#'+id).removeClass('active');
        timeoutMouseLeave[id] = setTimeout(function () {
            $('#'+id+'-nav').fadeOut('fast', function () {
                $(this).css('height', 0);
                $(this).css('optacity', 0);
            });
        }, 300);
    });


    $('.hover-nav').mouseenter(function() {
        var id = $(this).text();
        id = jQuery.trim(id);
        $('#'+id).addClass('active');
        if (typeof timeoutMouseLeave[id] != "undefined") {
            clearTimeout(timeoutMouseLeave[id]);
        }
    });
    $('.hover-nav').mouseleave(function() {
        var id = $(this).text();
        id = jQuery.trim(id);
        var hoverNav = this;
        timeoutMouseEnter[id] = setTimeout(function () {
            $(hoverNav).fadeOut('fast', function () {
                $(this).css('height', 0);
                $(this).css('optacity', 0);
                $(this).hide();
                $('#'+id).removeClass('active');
            });
        }, 500);
    });
});
