﻿$.viewportHeight = function(wnd) { var h = 0; if (typeof (wnd.innerHeight) == "number") { h = wnd.innerHeight; } else { if (wnd.document.documentElement && wnd.document.documentElement.clientHeight) { h = wnd.document.documentElement.clientHeight; } else { if (wnd.document.body && wnd.document.body.clientHeight) { h = wnd.document.body.clientHeight; } } } return h; }

function LoadContent(aKey, type, containerSelector, templatePath) {
    LoadContent(aKey, type, containerSelector, templatePath, null);
}

function LoadContent(aKey, type, containerSelector, templatePath, callback) {
    var serviceType = "";
    switch (type) {
        case "Space":
        case "Box":
            serviceType = type;
    }
    if (serviceType != "") {
        $.ajax({
            type: "POST",
            url: "/ws/jit.asmx/" + serviceType,
            data: '{"key":"' + aKey + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                ApplyTemplate(msg, containerSelector, templatePath);
                // Spaces hack
                if (msg.d.GeneralLocationImagePath == '')
                    $("#mapSection").hide();
                if (callback != null)
                    callback();
            }
        });
    }

}

function ApplyTemplate(msg, containerSelector, templatePath) {
    // This method loads the HTML template and
    //  prepares the container div to accept data.
    $(containerSelector).setTemplateURL(templatePath, null, { filter_data: false });
    // This method applies the JSON array to the 
    //  container's template and renders it.
    $(containerSelector).processTemplate(msg);
}

function SetButtonHighlight(lnk) {
    $(".thinLink").removeClass("on");
    $(lnk).addClass("on");
}

// o.i. talk-testimonials?
function ConfigurePrevNext(pk, nk) {
    if (pk == '') {
        $('.prevLink').addClass("disabled");
    } else {
        $('.prevLink').attr({ "id": pk + "_np" })
    }
    if (nk == '') {
        $('.nextLink').addClass("disabled");
    } else {
        $('.nextLink').attr({ "id": nk + "_np" })
    }
}

function InitCarousels() {
    $("#btnViewRoomPlan").click(function() {
        if ($("#selRooms").val() != "") {
            var t = $("#selRooms option:selected").attr("title");
            $(this).title = t;
            href = $("#selRooms option:selected").val();
            $(this).attr("href", href);
        } else {
            return false;
        }
    });
    $(".scrollerImages").jCarouselLite({
        easing: "easeinout",
        speed: 450,
        visible: 1,
        circular: true,
        btnNext: ".next",
        btnPrev: ".prev",
        btnGo: ["#img0", "#img1", "#img2", "#img3", "#img4", "#img5", "#img6", "#img7", "#img8", "#img9", "#img10", "#img11", "#img12", "#img13", "#img14", "#img15", "#img16", "#img17"],
        afterEnd: jakers
    });
}

function InitBoxCarousels() {
    $("#btnViewRoomPlan").click(function() {
        if ($("#selRooms").val() != "") {
            var t = $("#selRooms option:selected").attr("title");
            $(this).title = t;
            href = $("#selRooms option:selected").val();
            $(this).attr("href", href);
        } else {
            return false;
        }
        
    });
    $("#mapSection a").click(function() {
        var href = $(this).attr("href");
        if (href != "") {
            $.slimbox(href, $(this).attr("title"));
        }
        return false;
    });
    $(".scrollerImages").jCarouselLite({
        easing: "easeinout",
        speed: 450,
        visible: 1,
        circular: true,
        btnNext: ".next",
        btnPrev: ".prev",
        btnGo: ["#img0", "#img1", "#img2", "#img3", "#img4", "#img5", "#img6", "#img7", "#img8", "#img9", "#img10", "#img11", "#img12", "#img13", "#img14", "#img15", "#img16", "#img17"],
        afterEnd: jakers
    });
}

function jakers(arrVisible) {
    var $kids = $(arrVisible[0]).children();
    var title = $kids[0].title;
    $("#carouselCaption").html(title);
}
