var mouseX = 0;
var mouseY = 0;

function getBasicInfo(url, obj)
{
    //Frist, show the loading sign
    new Effect.Appear('bi_loading', {duration:0.1});
    new Ajax.Updater('bi_content', url, {method:'get'});

    var elm = getElement('bi_content');
    var offset = Position.realOffset(elm);
    prep('basic_info', mouseX + offset[0], mouseY+offset[1]);

    new Effect.Appear('basic_info', {duration:1.5});
    new Effect.Appear('bi_close_text', {duration:0.1});

    //now, hide the loading sign
    new Effect.Fade('bi_loading', {transition: Effect.Transitions.linear, duration:0.1});
}



function showStats(url)
{
    //Frist, show the loading sign
    new Effect.Appear('details_loading', {duration:0.1});
    new Ajax.Updater('details_content', url, {method:'get'});

    var elm = getElement('details_content');
    var offset = Position.realOffset(elm);
    prep('details', mouseX + offset[0], mouseY+offset[1]);

    new Effect.Appear('details', {duration:1.5});
    new Effect.Appear('details_close_text', {duration:0.1});

    //now, hide the loading sign
    new Effect.Fade('details_loading', {transition: Effect.Transitions.linear, duration:0.1});
}


function prep(elemName, left, top)
{
    setStyle(elemName, 'position', 'absolute');
    setStyle(elemName, 'top', top + 'px');
    setStyle(elemName, 'left', left + 'px');
    setStyle(elemName, 'border', 'thin solid #999999');
    setStyle(elemName, 'width', '500px');
    setStyle(elemName, 'backgroundColor', '#EEEEEE');
    setStyle(elemName, 'padding', '15px 15px 15px 15px');
    setStyle(elemName, 'overflow', 'auto');

    setStyle('bi_content', 'position', 'relative');
    setStyle('bi_content', 'top', 15 + 'px');
    setStyle('bi_content', 'left', 0 + 'px');
    setStyle('bi_content', 'width', '450px');
    setStyle('bi_content', 'backgroundColor', '#EEEEEE');
    setStyle('bi_content', 'overflow', 'auto');
    setStyle(elemName, 'padding', '0px 0px 0px 15px');
}





function hide_details(obj)
{
    new Effect.Fade('details', {transition: Effect.Transitions.linear, duration:0.5});

    //And remove the content of 'bi_content'
    removeBIContent('details_content');

    //return false;
}


function hide_function(obj)
{
    new Effect.Fade('basic_info', {transition: Effect.Transitions.linear, duration:0.5});

    //And remove the content of 'bi_content'
    //removeBIContent('details_content');

    //return false;
}



function setStyle(objName, style, value)
{
    getElement(objName).style[style] = value;
}

function getElement(id)
{
    //return document.getElementById(id);
  var item = false;
  if (document.getElementById)
    item = document.getElementById(id);
  else if (document.all)
    item = document.all[id];
  else if (document.layers)
    item = document.layers[id];

  return item;
}



function eventHandlerFunction(e)
{
    var elem = Event.element(e);
    var mouseX = Event.pointerX(e);
    var mouseY = Event.pointerY(e);

    //Then show the content
    prep('basic_info', mouseX, mouseY);
    //new Effect.Opacity('basic_info', {duration:1.5, transition: Effect.Transitions.linear, from:0.1, to: 1.0, fps:35});
    new Effect.Appear('basic_info', {duration:1.5});



    Event.stop(e);
}



function mouseClickEventHandler(e)
{
    mouseX = e.clientX;
    mouseY = e.clientY;
}


function isEmptyContent(elemName)
{
    var elem = getElement(elemName);
    return (elem.childNodes.length==0);
}


function removeBIContent(elemname)
{
    var elem = getElement(elemname);
    if (elem)
    {
        //try
        //{
            var times = elem.childNodes.length;
            var temp = null;
            for (var i = 0; i < times; i++)
            {
                temp = elem.childNodes[i];
                if (temp)
                    elem.removeChild(temp);
            }
        //}
        //catch(e)
        //{
            //alert('Some error occured when trying to delete the old content of the display window!');
        //}
    }
}



function getProjectList(url, container)
{
    new Ajax.Updater('proj_list', url, {method:'get'});
    //new Ajax.Updater('markup', url, {method:'get'});
}






