// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function reply(comment_id)
{
    if (comment_id == 'reply_topic') {
        $('reply_topic').appendChild($('new_comment'))
        $('comment_parent_id').value = ''
    } else {
        if (!(elem = $('comment_' + comment_id).select('ul')[0])) {
            $("comment_" + comment_id).appendChild($('new_comment'))
        } else {
            $('comment_' + comment_id).insertBefore($('new_comment'), elem)
        }
        $('comment_parent_id').value = comment_id
    }
}

function sendReq(where, params) {
    new Ajax.Request(where,
        {
        asynchronous:true,
        evalScripts:true,
        parameters:'authenticity_token='+encodeURIComponent(form_authenticity_token)+'&_method=put'+params
        }
    );
}

function changeDir(item_id)
{
    direction = $('item_' + item_id).className == 'lft' ? '1' : '0'
    sendReq('/portfolio/' + portfolioId + '/items/' + item_id, '&item[direction]='+direction)
}

function elemUp(item_id)
{
    sendReq('/portfolio/' + portfolioId + '/items/' + item_id + "/up", '')
}

function elemDown(item_id)
{
    sendReq('/portfolio/' + portfolioId + '/items/' + item_id + "/down", '')
}

function setType(item_id, type)
{
    sendReq('/portfolio/' + portfolioId + '/items/' + item_id, '&item[arrow_type]='+type)
}

function setCoord(elem, event)
{
    item_id = elem.element.id.substr(5, elem.element.id.length)
    sendReq('/portfolio/' + portfolioId + '/items/' + item_id, '&item[top]='+elem.element.style.top+'&item[left]='+elem.element.style.left)
}

function setHeight(elem, event)
{
    sendReq('/portfolio/' + portfolioId, '&portfolio[height]='+elem.element.style.height)
}