﻿    var mouseX;
    var mouseY;
    var hide = true;
    var hideSub = false;
    var userID;
    var timer = null;
    
    var Menu_profile = 'profile';
    var Menu_BigPhoto = 'bigphoto';
    var Menu_Gallery = 'gallery';
    var Menu_Messages = 'messages';
    var Menu_Friends = 'friends';
    var Menu_Groups = 'groups';
    var Menu_AddFriend = 'add_friend';
    
    var Menu1 = new Array(Menu_BigPhoto, Menu_Messages, Menu_Friends, Menu_Gallery, Menu_Groups, Menu_profile, Menu_AddFriend);
    //var Menu1 = new Array(Menu_BigPhoto, Menu_Messages,  Menu_Gallery,  Menu_profile, Menu_AddFriend);
    
    if(!document.all)
    {
        document.onmousemove = function(e)
        {
            mouseX = e.pageX;
            mouseY = e.pageY;
            return true;
        }
    }
    else
    {
        document.onmousemove = function()
        {
            mouseX = event.clientX + getBodyScrollLeft();
            mouseY = event.clientY + getBodyScrollTop();
            return true;
        }
    }
    function getBodyScrollTop()
    {
      return self.pageYOffset ||
        (document.documentElement && document.documentElement.scrollTop) ||
        (document.body && document.body.scrollTop);
    }
    function getBodyScrollLeft()
    {
      return self.pageXOffset ||
        (document.documentElement && document.documentElement.scrollLeft) ||
        (document.body && document.body.scrollLeft);
    }
    function CreateDiv()
    {
        var div = document.createElement('div');
        div.id = 'div_menu';
        div.style.width = '150px';
        div.style.background = '#eeeeee';
        div.style.display = 'none';
        div.style.zindex = '100';
        div.style.position = 'absolute';
        div.style.border = '1px #1C5180 solid';
        div.style.padding = '5px 5px 5px 5px';
        div.onmouseout = HideSubDiv;
        div.onmouseover = ShowSubDiv;
        document.body.appendChild(div);
        return div;
    }
    function SetDiv(name, id, status, width, height, arr)
    {
        if (status!=1) return;
        if(document.all)
        {
            timer = setTimeout("ShowDiv('" + name + "'," + id + "," + width + "," + height + ",new Array('" + arr.join("','") + "'))",600);
        }else
        {
            timer = setTimeout(ShowDiv,600, name, id, width, height, arr);
        }
    }
    function ShowDiv(name, id, width, height, arr)
    {
        var e = document.getElementById('div_menu');
        if (e == null)
            {e = CreateDiv();}
        if(document.all)
        {
            e.style.top = mouseY + 5;
            e.style.left = mouseX + 5;
        }
        else
        {
            e.style.top = mouseY + 5 + 'px';
            e.style.left = mouseX + 5 + 'px';
        }
        e.innerHTML = '<b>' + name + '</b><br />';
        for (j = 0; j < arr.length && id!=-1; j++)
        {
            if (arr[j] == Menu_profile)
                e.innerHTML += "<img src='/images/up-blue.gif' border='0' width='14' height='14'>&nbsp;<a href='/user/profile.aspx?id=" + id + "'>перейти в профиль</a><br>";
            if (arr[j] == Menu_BigPhoto && (width != 0 || height != 0))
                e.innerHTML += "<img src='/images/find.gif' border='0' width='14' height='14'>&nbsp;<a onclick=\"javascript:document.getElementById('div_menu').style.display = 'none';openWindowWH('/view_photo.aspx?showdescr=false&type=2&id=" + id + "'," + width + "," + height + ")\" href='javascript:void(0);'>увеличить фото</a><br>";
            if (arr[j] == Menu_Gallery && (width != 0 || height != 0))
                e.innerHTML += "<img src='/images/photoalbum.gif' width='14' height='14' border='0'>&nbsp;<a onclick=\"javascript:document.getElementById('div_menu').style.display = 'none';openWindow('/view_photo.aspx?type=3&id=1&user_id=" + id + "')\" href='javascript:void(0);'>галерея</a><br>";
            if (arr[j] == Menu_Messages && CurUserID!=id)
            {
                if (CurUserID > 0)
                    e.innerHTML += "<img src='/images/email-open-blue.gif' width='14' height='14' border='0'>&nbsp;<a style='color:red;' onclick=\"javascript:document.getElementById('div_menu').style.display = 'none';openWindowWH('/user/messages.aspx?id=" + id + "',MesWidth, MesHeight)\" href='javascript:void(0);'>написать сообщение</a><br>";
                else
                    e.innerHTML += "<img src='/images/email-open-blue.gif' width='14' height='14' border='0'>&nbsp;<a style='color:red;' href='/register.aspx'>написать сообщение</a><br>";
            }
            if (arr[j] == Menu_Friends)
                e.innerHTML += "<img src='/images/friends.gif' width='14' height='14' border='0'>&nbsp;<a href='/user/friends.aspx?id="+id+"'>друзья пользователя</a><br>";
            if (arr[j] == Menu_Groups)
                e.innerHTML += "<img src='/images/group.gif' width='14' height='14' border='0'>&nbsp;<a href='/user/groups.aspx?id="+id+"'>группы пользователя</a><br>";
            if (arr[j] == Menu_AddFriend && CurUserID!=id)
            {
                if (CurUserID > 0)
                    e.innerHTML += "<img src='/images/add-user-blue.gif' width='14' height='14' border='0'>&nbsp;<a style='color:red;' href='/user/invite_reg_user.aspx?id="+id+"'>добавить в друзья</a><br>";
                else
                    e.innerHTML += "<img src='/images/add-user-blue.gif' width='14' height='14' border='0'>&nbsp;<a style='color:red;' href='/register.aspx'>добавить в друзья</a><br>";
            }
        }
        var k = 0;
        var l = 1;
        if (width == 0 || height == 0)
            k = 2;
        if (CurUserID==id || id==-1) k+=2;
        l = Math.ceil(name.length/20);
        e.style.height = (arr.length-k+l)*15 + 'px';
        e.style.display = "block";
        hide = true;
    }
    function HideDiv()
    {
        if (timer)
        {
            clearTimeout(timer);
            timer = null;
        }
        if (hide)
        {
            hideSub = false;
            setTimeout(hidediv,500); 
        }
    }
    function ShowSubDiv()
    {
        hideSub = true;
    }
    function HideSubDiv()
    {
        hideSub = false;
        setTimeout(hidediv,500);
    }
    
    function hidediv()
    {
        if (!hideSub)
        {
            var e = document.getElementById('div_menu');
            if (e != null)
            {
                e.style.display = "none";
                hide = false;
            }
        }
    }
    
function openWindow(sPage)
{
    var width=650
    var height=670;
    
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	
	var sFeatures= "top="+top+", left="+left+", width="+width+", height="+height+", "
		+ "toolbar=no, menubar=no, location=no, directories=no, resizable=yes, scrollbars=yes";
	var oNewWindow = window.open(sPage, "", sFeatures, true);
}
function openWindowHelp(sPage)
{
    var width=400
    var height=300;
    
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	
	var sFeatures= "top="+top+", left="+left+", width="+width+", height="+height+", "
		+ "toolbar=no, menubar=no, location=no, directories=no, resizable=yes, scrollbars=yes";
	var oNewWindow = window.open(sPage, "", sFeatures, true);
}
function openWindowWH(sPage, width, height)
{    
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	
	var sFeatures= "top="+top+", left="+left+", width="+width+", height="+height+", "
		+ "toolbar=no, menubar=no, location=no, directories=no, resizable=yes, scrollbars=no";
	var oNewWindow = window.open(sPage, "", sFeatures, true);
	
	//return false;
}
function openWindowWH_(img, width, height)
{    
	var NewWindow
    var left = (screen.width-width)/2;
    var top = (screen.height-height)/2;

    var sFeatures = "top="+top+", left="+left+", width="+width+", height="+height+", "
            + "toolbar=no, menubar=no, location=no, directories=no, resizable=no, scrollbars=no";
    NewWindow = open("", "myWin", sFeatures, true);
    NewWindow.document.open();
    NewWindow.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"+
    "<html xmlns='http://www.w3.org/1999/xhtml'>"+
    "<head>"+
        "<title>ФОТО</title>"+
    "</head>"+
    "<body style='margin: 0px; padding: 0px'>"+
    "<img src='"+img+"' width='"+width+" 'height='"+height+"' alt='' />"+
    "</body>"+
    "</html>");
    NewWindow.document.close();           
}