﻿// Function called on page load to do client side initialisation for the Navigation control
function webDesignNavigationControl_onLoad(panelNavigationClientID, linkButtonUpdateOrderClientID, hiddenFieldPageOrderClientID) {
    // Highlight tab on mouse hover
    $('.webDesign.navigationControl .navigation .navItem:not(.selected)').mouseenter(function () { $(this).addClass('selected'); });
    $('.webDesign.navigationControl .navigation .navItem:not(.selected)').mouseleave(function () { $(this).removeClass('selected'); });

    // Make the navigation tabs sortable using jQuery UI
    $('#sortableNavigationTabs').sortable({
        containment: '#sortableNavigationTabs',
        revert: '50',
        /*axis: 'x',*/
        update: function (event, ui) {
            // Order updated, get the curent order of the pages (as comma seperated list of page IDs)
            var pageOrder = '';
            $('#sortableNavigationTabs input:hidden[id$="_HiddenFieldPageID"]').each(function (index) {
                if (pageOrder.length > 0)
                    pageOrder += ',';
                pageOrder += $(this).attr('value');
            });
            // Make a callback to the server to save the new page order (passed in hidden field)
            $('#sortableNavigationTabs input:hidden[id$="_HiddenFieldPageOrder"]').attr('value', pageOrder);
            __doPostBack($('#sortableNavigationTabs a[id$="_LinkButtonUpdateOrder"]').attr('id').replace(/_/g, '$'), '');
        },
        start: function (event, ui) {
            // Hide other controls when sorting starts
            $(this).find('div.buttons').css('display', 'none'); // Hide page edit/delete buttons on tab
            $('a.navItemContainer.new').css('display', 'none'); // Hide new page tab
            $('a.coloursIcon').css('display', 'none'); // Hide navigation colours button
            $('a.structureIcon').css('display', 'none'); // Hide navigation structure button
        }
    });
}

$(function () {
    // Highlight tab on mouse hover
    $('.webDesign.navigationControl .navigation .navItem:not(.selected)').mouseenter(function () { $(this).addClass('selected'); });
    $('.webDesign.navigationControl .navigation .navItem:not(.selected)').mouseleave(function () { $(this).removeClass('selected'); });
});
