﻿function text_editor(the_element) {
    //$('#menu').hide();
    $('.' + the_element).mouseenter(function () {
        //alert(this.id);
        //$(this).offset({ top: 50, left: 50 });
        //var position = $(this).position();

        var position = $(this).position();
        //$("#message").prepend('left: ' + position.left + ' --- top: ' + position.top + '<br>');

        if (base == "") {
            base = "./"
        }
        var element_state = '';

        if (this.id.indexOf("group") > -1) {

        } else {
            element_state = "edit";
        }
        var menu_options = '<div class="dashboard" style="position:relative;top:20px;left:5px;z-index:5;" id="menu_' + this.id + '"> \
                        <div id="menu_lef_' + this.id + '" class="menu_left"></div> \
                            <div id="menu_center_' + this.id + '" class="menu_center"> \
                                <a class="editor" href="' + base + 'widgets.aspx?state=' + element_state + '&element=' + this.id + '" title="Widgets" onclick="popup = true;">Edit Content</a> \
                            </div> \
                            <div id="menu_right_' + this.id + '" class="menu_right"></div> \
                            <div class="clear"></div> \
                        </div>';
        $(this).prepend(menu_options);

        //<a class="editor" href="' + base + 'widgets/upload/content_upload.aspx" title="Images">Upload</a> \
        //$(this).prepend('<div class="dashboard" style="position:relative;top:-5px;left:-5px;z-index:999;" id="menu_' + this.id + '"><div id="menu_lef_' + this.id + '" class="menu_left"></div><div id="menu_center_' + this.id + '" class="menu_center"><a class="editor" href="./admins/content_editor.aspx?content_id=' + this.id + '" title="Content Editor">Edit Content</a> | <span id="btn_delete_' + this.id + '" class="btn_delete">delete</span></div><div id="menu_right_' + this.id + '" class="menu_right"></div><div class="clear"></div></div>');
        $(".editor").colorbox({ onLoad: function () { window.scrollTo(0, 0); }, width: "100%", height: "100%", iframe: true, onClosed: function () { popup = false; location.reload(true); } });

        $('#menu_' + this.id).hide().fadeIn("slow")
        $(this).addClass('current_view').fadeIn("slow");

        //alert(this.style.left);
        //$('#menu').fadeIn('slow', function () {
        //var offset = $(this).offset({ top: 10, left: 30 });
        //alert(this.left);
        //alert(this.style.left);
        //alert(offset.top);
        //alert(offset.left);
        //Animation complete
        //});

        $('.btn_edit').click(function () {
            //alert('Call Editor');
            //$(this).colorbox({ width: "80%", height: "80%", iframe: true });
            //$.colorbox({ href: "./ck_editor.aspx" });
        });

        $('.btn_delete').click(function () {
            //alert('test');
            $(this).parent().parent().parent().remove().fadeOut('slow', function () {
            });
        });

        /*$('.btn_cancel').click(function () {
        //alert('test');
        $(this).parent().parent().fadeOut('slow', function () {
        });
        });*/
    });

    $('.div_edit').mouseleave(function () {
        $('#menu_' + this.id).remove();
        $(this).removeClass('current_view');
    });

}
