﻿/// <reference path="jquery.js" />
/// <reference path="jquery-ui.js" />

$(function () {

    /// TABS

    $(".interface-tabs-container").each(function () {


        $.address.change(function (event) {
            showTab(event.value.substr(1));
        })

        function showTab(id) {
            if (tabs[id]) {
                for (var i in tabs) {
                    tabs[i].obj.css("display", "none");
                    tabs[i].li.removeClass("current");
                }

                tabs[id].obj.css("display", "block")
                tabs[id].li.addClass("current")
            }
        }

        var container = $(this)

        var tabs = new Object();

        var tabsUl = $("<ul/>").addClass("interface-tabs")

        container.find("a.interface-tab-prefix").each(function () {

            $('<li class="prefix"/>').appendTo(tabsUl).append($(this))

        })

        $(this).prepend(tabsUl);

        var firstTab;

        container.find(".interface-tab-section").each(function (index) {

            var li = $("<li/>")

            var a = $('<a href="#"/>')

            li.append(a);

            var title = $(this).find("h2").css("display", "none").html();
            var id = $(this).attr("id");
            id = id.substring(0, id.length - 8)

            tabs[id] = { id: id, title: title, obj: $(this), li: li }

            a.html(title)

            tabsUl.append(li);

            a.click(function () {

                $.address.value(id);
                return false;
            })

            if (index == 0) { firstTab = id }
            if ($(this).is(".current")) { firstTab = id }
            /*
            $(".tab-link.link-" + id).click(function() {

            showTab(id)
            return false;
            })
            */
        })

        showTab(firstTab);

    })


    $("a.not-developed ,.not-developed a").click(function () {
        var message = $(this).closest(".not-developed").attr("message");

        if (message == null || message == "") {
            message = "Sorry. This feature is coming soon.";
        }
        else {
            message = "This feature is coming soon. " + message;
        }

        $.alert(message, null, { width : 400 });

        return false;
    })

    $("a.not-developed_beta ,.not-developed_beta a").click(function () {
        var message = $(this).closest(".not-developed_beta").attr("message");

        if (message == null || message == "") {
            message = "Sorry. This feature is coming soon.";
        }
        else {
            message = "This feature is currently in beta testing. " + message;
        }

        $.alert(message, null, { width: 400 });

        return false;
    })

    $(".page-loading").removeClass("page-loading");
})
