// JavaScript Document

$(document).ready(function () {



    // tabbed content items
    $('.content_item').each(function (intIndex) {
        var content_elem = $(this);
        if (content_elem.find('.content_tabs').length == 1) {

            var tabs = content_elem.find('.content_tabs').children('li');
            var bodies = content_elem.children('.content_body');

            $.each(bodies, function (i) {

                var thisBody = $(this);

                if (i == 0) {
                    $(tabs[i]).addClass('open');
                }
                else {
                    $(tabs[i]).addClass('close');
                    $(this).hide();
                }

                $(tabs[i]).click(function () {
                    if ($(this).hasClass('close')) {
                        jQuery.each(tabs, function (i) {
                            if ($(this).hasClass('open')) {
                                $(this).removeClass('open');
                                $(this).addClass('close');
                            }
                        });
                        $(this).removeClass('close');
                        $(this).addClass('open');

                        jQuery.each(bodies, function () {
                            $(this).hide();
                        });

                        thisBody.show();
                    }
                });

            });

        }
    });




    // View menu
    $('ul.view_menu').find('li.close,li.open').click(function (event) {
        if ($(this).hasClass('close')) {

            // toggle classes
            $(this).siblings('li.open').addClass('close');
            $(this).siblings('li.open').removeClass('open');
            $(this).removeClass('close');
            $(this).addClass('open');

            // show views

            // To hell with it, this is hardcoded for today
            if ($(this).text() == "Simple") {
                $('div.simple_view').show();
                $('div.code_view').hide();
            }
            else if ($(this).text() == "Code") {
                $('div.simple_view').hide();
                $('div.code_view').show();
            }

            var thisContentBar = $(this).parents('.content_bar');
            var headBarHeight = thisContentBar.find('.head').height() - 1;
            var optionFormHeight = thisContentBar.find('.options_form').height() + 15;
            thisContentBar.animate({ height: headBarHeight + optionFormHeight + 'px' }, 200);

        }
    });



    // Content panel bar
    $('.content_bar').css({ "height": ($(this).find('.head').height() - 1) + 'px' });
    $('.content_bar').find('.option_link').find('a').click(function (event) {
        var thisContentBar = $(this).parents('.content_bar');
        var headBarHeight = thisContentBar.find('.head').height() - 1;
        var optionFormHeight = thisContentBar.find('.options_form').height() + 15;

        if (thisContentBar.height() == headBarHeight) {
            thisContentBar.animate({ height: headBarHeight + optionFormHeight + 'px' }, 600);
        }
        else {
            thisContentBar.animate({ height: headBarHeight + 'px' }, 600);
        }

    });


    $(document).ready(function () {
        register_popop('.list_item_profile', '');
    });

});

