﻿/**********************************************************
HOME PAGE
**********************************************************/
var isInBox;var lastIcon;

$(document).ready(function() {
    $("#login-password").keydown(function(event) {
        if (event.keyCode == '13') {
            loginAuth();
            event.preventDefault();
        }
    });
    $('ul#home-images').innerfade({
        speed: 1000,
        timeout: 5000,
        type: 'sequence',
        containerheight: '240px'
    });
    $("#login").dialog({ width: '320', height: '224', resizable: false, modal: true, autoOpen: false });

    $("#homepage-banner a").mouseenter(function() {
        var imgNum = $("img", this).attr("src");
        if (imgNum != null) {
            if (lastIcon != null && lastIcon != $("img", this))
                lastIcon.hide();
            $("img", this).fadeIn(200);
            imgNum = imgNum.replace("home-icon-", "home-popup-");
            imgNum = imgNum.replace(".png", ".jpg");
        } else {
            imgNum = "app_themes/web/images/casestudy-heading.jpg";
        }
        var position = $(this).position();
        var top = position.top - 160;
        var left = position.left + ($(this).width() / 2) - 112;
        $("#home-popup").css("top", top + "px");
        $("#home-popup").css("left", left + "px");
        $("#home-popup-content").css("background-image", "url(" + imgNum + ")");
        $("#home-popup-content h4").html($(this).attr('header'));
        $("#home-popup-content p").html($(this).attr('body'));
        $("#home-popup-content a").attr('href', $(this).attr('link'));
        $("#home-popup").fadeIn(200);
        isInBox = true;
    });

    $("#homepage-banner a").mouseleave(function() {
        lastIcon = $("img", this);
        isInBox = false;
        var t = setTimeout("leaveBox()", 200); ;
    });

    $("#home-popup").mouseenter(function() {
        $(this).show();
        $("#homepage-banner a img:visible").show();
        isInBox = true;
    });

    $("#home-popup").mouseleave(function() {
        isInBox = false;
        var t = setTimeout("leaveBox()", 200);
    });
});

function leaveBox(obj) {
    if (!isInBox) {
        $("#homepage-banner a img:visible").fadeOut(200);
        $("#home-popup").fadeOut(200);
        isInBox = false;
    }
}
