var showUserName;

(function()
{
    var UA = navigator.userAgent;
    is_gecko = /gecko/i.test(UA);
    is_opera = /opera/i.test(UA);
    is_mac = /mac_powerpc/i.test(UA);
    is_ie = /msie/i.test(UA) && !is_opera && !is_gecko && !is_mac;
    is_ie5 = is_ie && /msie 5\.[^5]/i.test(UA);
    is_nn4 = document.layers ? true : false;
})();

function Community()
{
}

Community.i18n = function(text, arg1, arg2)
{
    if (typeof Community.I18N != "undefined" && typeof Community.I18N[text] != "undefined")
        text = Community.I18N[text];

    if (arg1)
    {
        text = text.replace(/(\(1\))/g, arg1);

        if (arg2)
            text = text.replace(/(\(2\))/g, arg2);
    }

    return text;
};


Community.CE = function(type, parent, props, style)
{
    var el = null,i;

    if (document.createElementNS)
        el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
    else
        el = document.createElement(type);

    if (parent)
        parent.appendChild(el);

    if (props)
        for (i in props)
            el[i] = props[i];

    if (style)
        for (i in style)
            el.style[i] = style[i];

    return el;
};


function SMenuFriend()
{
}

SMenuFriend.div = null;
SMenuFriend.timer = null;
SMenuFriend.showDiv = 0;
SMenuFriend.overDiv = 0;

SMenuFriend.userId = null;
SMenuFriend.userName = null;
SMenuFriend.photoId = null;


SMenuFriend.generate = function(parent)
{
    if (!parent)
        return;

    if (SMenuFriend.div)
        return;

    var C = Community;
    SMenuFriend.div = C.CE("div", parent, {id:"shortcutMenuFriend"}, {});
    SMenuFriend.div.onmouseover = function()
    {
        SMenuFriend.overDiv = 1;
    }

    SMenuFriend.div.onmouseout = function()
    {
        SMenuFriend.overDiv = 0;
        setTimeout('closeSMenuFriend()', 500);
    }

    SMenuFriend.userName = C.CE("h4", SMenuFriend.div, {});

    var body = C.CE("ul", SMenuFriend.div, {}, {});

    function gen_menu(body, icon, label, clickHandler)
    {
        var a = C.CE("a", C.CE("li", body, {className:"shortcutMenuItem-" + icon}), {href:"#",innerHTML:C.i18n(label)});
        a.onclick = clickHandler;
    }


    gen_menu(body, "view", "Profil ansehen", function()
    {
        var url = "/profile/" + showUserName;

        window.location = url;
        return false;
    });
	

    gen_menu(body, "message", "Nachricht schreiben", function()
    {
        var url = "/gl/js/php/rte.php?rte=3&id="+ SMenuFriend.userId +"&btr=Hi!&bName="+ showUserName;

		getRTE(url);
        return false;
    });
	
    gen_menu(body, "gb", "G&auml;stebuch", function()
    {
        window.location = "/profile/" + showUserName + "/userGuestbook";
        return false;
    });

	gen_menu(body, "gl", "Fotogallery", function()
	{
       window.location = "/profile/"+ showUserName + "/userGallery";
       return false;
    });


    gen_menu(body, "video", "Freunde", function()
    {
        window.location = "/profile/" + showUserName + "/userFreunde";
        return false;
    });
	
}



SMenuFriend.popupDiv = function(e, userId, userName, photoId)
{
    if (!e)
        e = window.event;

    var x = e.clientX;
    var y = e.clientY;

    SMenuFriend.timer = setTimeout("showSMenuFriend(" + x + "," + y + ",'" + userId + "','" + userName + "','" + photoId + "')", 600);
	showUserName = userName;
}

var showSMenuFriend = function(x, y,  userId, userName, photoId)
{
    SMenuFriend.generate(document.body);
    var div = SMenuFriend.div;

    SMenuFriend.userId = userId;
    SMenuFriend.photoId = photoId;
    SMenuFriend.userName.innerHTML = "<font style=\"font-size:11px;\">&nbsp;" + userName + "<br>----------------------------</font>";

    if (document.documentElement.clientWidth && document.documentElement.clientWidth - x < 200)
        x -= 200;
    else
        x += 5;

    if (document.documentElement.clientHeight && document.documentElement.clientHeight - y < 240)
        y -= 240;

    if (document.documentElement.scrollLeft)
        x += document.documentElement.scrollLeft;
    else if (document.body.scrollLeft)  // for safari
        x += document.body.scrollLeft;

    if (document.documentElement.scrollTop)
        y += document.documentElement.scrollTop;
    else if (document.body.scrollTop)  // for safari
        y += document.body.scrollTop;

    if (is_nn4)
    {
        div.left = x;
        div.top = y;
    }
    else if (is_ie)
    {
        div.style.pixelLeft = x;
        div.style.pixelTop = y;
    }
    else
    {
        div.style.left = x + "px";
        div.style.top = y + "px";
    }
	div.style.filter = "alpha(opacity=90)";
	div.style.opacity = "0.9";

    div.style.visibility = "visible";
    SMenuFriend.showDiv = 1;
}

SMenuFriend.hideDiv = function()
{
    if (SMenuFriend.timer)
    {
        clearTimeout(SMenuFriend.timer);
        SMenuFriend.timer = null;
    }

    if (SMenuFriend.showDiv == "1")
    {
        SMenuFriend.overDiv = 0;
        setTimeout('closeSMenuFriend()', 500);
    }
}

var closeSMenuFriend = function()
{
    if (SMenuFriend.overDiv == "0")
    {
        SMenuFriend.div.style.visibility = "hidden";
        SMenuFriend.showDiv = 0;
    }
}



