
$(function () {

    // After document is ready, reload saved services
    $(document).ready(function () {
        Tikal.Utils.CalculateCurrentWindowHeight();
        Tikal.Utils.LocalStore.reloadSavedServices();
        Tikal.Utils.LocalStore.reloadMorePreloadedOptions();
        Tikal.Utils.Tabs.reloadTabs();
        Tikal.Utils.Tabs.loadPredefinedURLs();
        Tikal.Options.initOptionsDialog();
        SyntaxHighlighter.all();
    });

    // Deprecated
    $(".searchExplore").bind({
        'click': (function () {
            //$(".searchDropDown").slideToggle('fast', function () { });
        })
    });

    // Open a dialog for adding services
    $("#plus").bind({
        'click': (function () {
            // Not a very nice coding :-( TODO: Rebuild this
            Tikal.Options.showDialog('hpMainContentSocail');
            // Older version
            //$('#dialog-form').dialog('open');
            //Tikal.ComboBox.setCombobox("serviceURLSelect");
        })
    });

    $(".desc_content").bind({
        'mouseover': function () {
            $(this).find('.right_content').addClass('selected');
            Tikal.Utils.PostActions.addPostACommentAction(this);
        },
        'mouseleave': function () {
            $(this).find('.right_content').removeClass('selected');
            Tikal.Utils.PostActions.removePostACommentAction(this);
        }
    });

    $(".possibleInternalLink").bind({
        'click': (function (event) {
            // If the tab already exists cancel the original action and direct the
            // link to open under tab
            var url = this.href;

            if (Tikal.Utils.Links.ifTabAlreadyExistsOpenIt(url)) {
                return (false);
            } else {
                if (Tikal.Utils.Links.tryAddingANewTab(url)) {
                    return (false);
                } else {
                    $('.hpMainContentSocail').fadeIn(500);
                }
            }
        })
    });

    $(".dashboard").bind({
        'click': (function event() {
            Tikal.Utils.Tabs.showDashboard();
        })
    });

    $(window).bind({
        'resize': (function () {
            Tikal.Utils.iFrame.onResizeWindow(true);
        })
    });
});

