$(document).ready(function () {

    if (typeof $.fn.modal == "function") {
        $.extend($.modal.defaults, {
            appendTo: 'form[name=aspnetForm]',
            closeClass: "simplemodal-close",
            overlayClose: true
        });
    }

    //auto-adjust height of the .pad element in teasers. add "autoheight" on row.
    var ie6 = ($.browser.msie && $.browser.version < 7);
    var whatHeight = (ie6) ? 'height' : 'min-height';
    var $rows = $("#main div.autoheight").each(function () {
        if (ie6) {
            $('b.cbr, b.cbl', this).css('bottom', '0');
        }
        var highest = 0;
        $("div.pad, div.inner", this).each(function () {
            var h = $(this).height();
            if (h >= highest) highest = h;
        }).css(whatHeight, highest + 'px'); //.height(highest);

    });
});

$(document).ready(function () {

    lightboxCloseBtn = $("#fancybox-close");
    if (lightboxCloseBtn.length) {
        lightboxCloseBtn.text("Luk");
    }
    $(".lightbox").fancybox({
        'overlayOpacity': 0.8,
        'overlayColor': '#292929'
    });
    $(".lightbox-elastic").fancybox({
        'overlayShow': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'titlePosition': 'over'
    });
    $(".lightbox-nooverlay").fancybox({
        'opacity': true,
        'overlayShow': false
    });
    $(".lightbox-gallery").fancybox({
        'overlayOpacity': 0.8,
        'overlayColor': '#292929',
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    $(".lightbox-iframe").fancybox({
        'width': '75%',
        'height': '75%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'overlayOpacity': 0.8,
        'overlayColor': '#292929'
    });
    $(".lightbox-flash").each(function () {
        $el = {
            width: $(this).data("width"),
            height: $(this).data("height")
        };

        if ($el.width == undefined) {
            $el.width = 500;
        }
        if ($el.height == undefined) {
            $el.height = 500;
        }

        $(this).fancybox({
            'width': $el.width,
            'height': $el.height,
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'overlayOpacity': 0.8,
            'overlayColor': '#292929'
        });
    });
});

$fancybox = {
    alert: function (msg) {
        jQuery.fancybox({
            'centerOnScroll': true,
            'padding': 0,
            'content': msg
        });
    },
    confirm: function (msg, callback) {
        var returnVal;
        jQuery.fancybox({
            'modal': true,
            'centerOnScroll': true,
            'padding': 0,
            content: "<div style=\"margin:1px;width:240px;\">" + msg + "<div style=\"text-align:right;margin-top:10px;\"><input id=\"fancyConfirm_cancel\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Cancel\"><input id=\"fancyConfirm_ok\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Ok\"></div></div>",
            onComplete: function () {
                jQuery("#fancyConfirm_cancel").click(function () {
                    returnVal = false;
                    jQuery.fancybox.close();
                })
                jQuery("#fancyConfirm_ok").click(function () {
                    returnVal = true;
                    jQuery.fancybox.close();
                })
            },
            onClosed: function () {
                if (typeof callback == 'function') {
                    window.setTimeout(function () {
                        callback.call(this, returnVal);
                    }, 500);
                }
            }
        });
    }
};
