$(document).ready(
    function()
    {
        // Check if this is a content page
        if (window.location.href.indexOf('/p/') != -1 || window.location.href.substr(window.location.href.length -1) == '/') {
            $('.selected').removeClass('selected');
            $('a[rel=info]').parent().addClass('selected');
            
            $('#menu a[href=#][rel!=]').unbind();
            
            $('#menu a[href=#]').each(
                function()
                {
                    $(this).attr('href', rootUrl + 'svwportfolio/#' + $(this).attr('rel'));
                }
            );
            
            $('.item').show();
            $('#menu .sub a').parent().removeClass('active');
            $('#menu .sub [rel=selected]').parent().addClass('active');

            
        }
        
        $('ul.sub.pl').sortable(
            {
                items: 'li[rel!=nosort]',
                axis: 'y',
                delay: 200,
                update: function(event, ui) {
                    $.post(rootUrl + 'content/cms/order-pages', $('ul.sub').sortable('serialize'))
                }
            }
        );
        
        if (identified) {
            // Event to change title fields of the current page while editing
            $('input[name=title]').keyup(
                function()
                {
                    $('.input_title').html($(this).val());
                }
            );
            
            // Event to capture click of a content item
            $('.delete_button').click(
                function()
                {
                    id = $(this).attr('id').substr(8);
                    
                    if (confirm('Weet u zeker dat u de pagina deze wilt verwijderen? Dit kan niet ongedaan worden gemaakt!')) {
                        window.location = rootUrl + 'content/cms/delete-page/id/' + id;
                    }
                }
            );
            
            // Drop / drag settings for submenus
            $('ul.submenu').sortable(
                {
                    cancel:     '.cancel',
                    stop:       function(event, ui) {
                                    // Repaint the list
                                    $('li', this).removeClass('first');
                                    $('li:first', this).addClass('first');
                                    
                                    // Sent the sorting results to the server
                                    $.post(rootUrl + 'content/cms/order-pages/group/' + $('#contentItemGroupId').val(), $(this).sortable('serialize'));
                                }
                }
            );
            
            // Drop / drag settings for contentphotos
            $('ul.contentphotos').sortable(
                {
                    cancel:     '.cancel',
                    stop:       function(event, ui) {
                                    // Sent the sorting results to the server
                                    $.post(rootUrl + 'content/cms/order-photos/id/' + $('#contentItemId').val(), $(this).sortable('serialize'));
                                }
                }
            );
            
                        
       
        }
    }
);
