
var CP = new charp();

function charp()
{
        var box = document.createElement("div");
                box.className = "bodyline mainmenu";
                box.style.position = "absolute";
                box.style.left = "-1000px";
                box.style.width = "auto";
                box.style.height = "auto";
                box.style.padding = "10px";
                document.body.appendChild(box);
                
        var BOARDS_DEFINED = true                
        this.open_box = function(e, forum_name, username)
        {
                var posx = 0;
                var posy = 0;
                if (!e) var e = window.event;
                if (e.pageX || e.pageY)         {
                        posx = e.pageX;
                        posy = e.pageY;
                }
                else if (e.clientX || e.clientY)         {
                        posx = e.clientX + document.body.scrollLeft
                                + document.documentElement.scrollLeft;
                        posy = e.clientY + document.body.scrollTop
                                + document.documentElement.scrollTop;
                }
                // the above lines in this function with thanks to quirksmode.org

                if (BOARDS_DEFINED && is_valid_forum(forum_name))
                {
                        box.innerHTML = 'CharP Shortcuts<hr>'
                                +'<a href="./cp/" target="top">Open CharP Home</a><br>'
                                +'<a href="./cp/#browse/server/'+forum_name+'" target="top">Browse CPs for this server</a><P>'
                                +'Browse '+username+'\'s CPs for:<P><ul>'
                                +'<li><a href="./cp/#browse/user/'+username+'/'+forum_name+'" target="top">This server</a></li>'
                                +'<li><a href="./cp/#browse/user/'+username+'" target="top">All Silverhearts</a></li>'
                                +'</ul>';
                }
                else
                {
                        if (!BOARDS_DEFINED)
                                box.innerHTML = 'Internal Error<hr>Could not load CharP config.';
                        else    box.innerHTML = 'CharP Shortcuts<hr><a href="./cp/" target="top">Open CharP Home</a>';
                }
                box.style.left = (posx+10)+"px";
                box.style.top = (posy+10)+"px";

                document.body.addEventListener('click', CP.hide_box, true);
                return false;
        }
        
        this.hide_box = function()
        {
                document.body.removeEventListener('click', CP.hide_box, true);
                box.style.left = "-1000px";
        }
        
        /*
         * private function
         */
        is_valid_forum = function(forum)
        {
                var names = "Arrrrrrrrh!BloodRainFFGatotsuJam SessionKidouKunaiLightwingOld RepublicOrboPhoenixSentinelSpursTeltreonTendoX-Factor";                

                return (names.indexOf(forum) > -1);
        }
}

