String.prototype.replace = function(pattern, replacement) {
    return this.split(pattern).join(replacement);
}

var dragPosition = 0;
var canClick = false;


function startClick() {
    canClick = false;
    dragPosition = $('g-projects-container').style.left;
}

function endClick() {
    if ($('g-projects-container').style.left == dragPosition) {
        canClick = true;
    }
}

function rotate(dx) {
    x = $('g-projects-container').style.left;
    x = x.replace('px', '');
    x = new Number(x);
    x += gSize*dx;
    if (x > 0) x = 0;
    if (x < -maxlimit) x = -maxlimit;
    $('g-projects-container').morph('left:'+x+'px;');
    return false;
}

function gClick(id) {
    if (canClick) {
        $('ajaxcontent').innerHTML = $('loadingid').innerHTML;
        new Ajax.Request('/gallery/ajax.html', {
            method:'get',
            parameters: {id: id},
            onSuccess: function(transport) {
                $('ajaxcontent').innerHTML = transport.responseText;
                Effect.ScrollTo('ajaxcontent');
            }
        });

        return false;
    }
    return canClick;
}

function rotateAjax(currentID, dx) {
    if (dx > 0) {
        next = false;
        for(i = 0; i < ajaxIDs.length; i++) {
            if (next == true) {
                canClick = true;
                gClick(ajaxIDs[i]);
                return false;
            }
            if (ajaxIDs[i] == currentID) next = true;
        }
    } else if (dx < 0) {
        prev = false;
        for(i = ajaxIDs.length-1; i >= 0; i--) {
            if (prev == true) {
                canClick = true;
                gClick(ajaxIDs[i]);
                return false;
            }
            if (ajaxIDs[i] == currentID) prev = true;
        }
    }
    return false;
}
