﻿var BL_LIGHTBOX_CONFIG = {
    overlayBgColor: '#000',
    overlayOpacity: 0.9,
    imageLoading: '../images/lightbox-ico-loading.gif',
    imageBtnClose: '../images/lightbox-btn-close.gif',
    imageBtnPrev: '../images/lightbox-btn-prev.gif',
    imageBtnNext: '../images/lightbox-btn-next.gif',
    imageBlank: '../images/lightbox-blank.gif',
    containerResizeSpeed: 350
};

BLPublic = {};
BLPublic.applyTileExpansion = function () {

    var collapsing = false;
    var expanding = false;
    var colCount = 4;
    var rows = 2;
    var initialPos_left = 0;
    var initialPos_top = 0;
    var initialSize_width = 0;
    var initialSize_height = 0;
    var animation_duration = 333;

    $("#hover").bind('click', function () {
        if (collapsing) { return; }
        if (expanding) { return; }
        collapsing = true;

        $('#hover').animate({
            opacity: 0.0,
            left: initialPos_left + "px",
            top: initialPos_top + "px",
            width: initialSize_width + "px",
            height: initialSize_height + "px"
        }, animation_duration, function () {
            collapsing = false;
            $('#hover').hide();
        });
    });

    $('.col').each(function (index) {
        $(this).bind('click', function () {

            if (expanding) { return; }
            expanding = true;

            $("#hover").html($(this).html());

            var colMod = index % colCount;
            var x_offset = 0;
            var y_offset = 0;

            if ((colMod == 2) || (colMod == 3)) {
                x_offset = ($(this).innerWidth() + 10) * -1;
            }

            var row = Math.floor(index / colCount);
            if (row == (rows - 1)) {
                y_offset = ($(this).innerHeight() + 10) * -1;
            }

            var element = $("#hover").get(0);
            initialPos_left = $(this).offset().left;
            initialPos_top = $(this).offset().top;
            initialSize_width = $(this).innerWidth();
            initialSize_height = $(this).innerHeight();

            element.style.left = initialPos_left + "px",
            element.style.top = initialPos_top + "px",
            element.style.width = initialSize_width + "px";
            element.style.height = initialSize_height + "px";

            var colorClass = "";
            var classes = this.className.split(" ");
            for (var i = 0; i < classes.length; i++) {
                var aClass = classes[i];
                if (aClass.indexOf("bg-color") != -1) {
                    colorClass = aClass;
                    break;
                }
            }
            $('#hover').removeClass("bg-color-green");
            $('#hover').removeClass("bg-color-orange");
            $('#hover').removeClass("bg-color-gray");
            $('#hover').removeClass("bg-color-cyan");
            $('#hover').addClass(colorClass);
            $('#hover').show();

            $('#hover').animate({
                opacity: 0.95,
                left: initialPos_left + x_offset + "px",
                top: initialPos_top + y_offset + "px",
                width: ((initialSize_width * 2) + 10) + "px",
                height: ((initialSize_height * 2) + 10) + "px"
            }, animation_duration, function () {
                expanding = false;
            });
        });
    });
};
