var lastCuts = '';
function updateLatestCuts(req) {
    if (lastCuts == req.responseText)
        return;
    if (!req.responseText.match(/<!-- latest cuts -->/)) {
        clearInterval(latestCutsInt);
        return;
    }

    var lc = document.getElementById('latest-cuts');
    var uls = lc.getElementsByTagName('ul');
    var ul = uls[0];
    var firstUpdate = false;
    if (lastCuts == '')
        firstUpdate = true;
    ul.innerHTML = lastCuts = req.responseText;
    if (!firstUpdate)
        gradient(lc, 227, 237, 236, 115, 177, 176);
}

function gradient(element, r1, g1, b1, r2, g2, b2) {
    var increments = 7;
    var rInc = Math.round((r1 - r2) / increments);
    var gInc = Math.round((g1 - g2) / increments);
    var bInc = Math.round((b1 - b2) / increments);
    r2 = r1 - rInc * increments;
    g2 = g1 - gInc * increments;
    b2 = b1 - bInc * increments;
    var r = r1;
    var g = g1;
    var b = b1;
    var to = true;
    var gradInt = setInterval(function () {
        if (to) {
            r -= rInc;
            b -= bInc;
            g -= gInc;
        }
        else {
            r += rInc;
            b += bInc;
            g += gInc;
        }
        element.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
        if (r == r2)
            to = false;
        if (to == false && r == r1)
            clearInterval(gradInt);
    }, 50);
}

function asyncReq(handler, url, post_data) {
    var req;
    if (window.XMLHttpRequest)
        req = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                req = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (e) {
            }
        }
    }

    if (!req) {
//        alert('Your browser does not support XMLHttpRequest');

        return;
    }

    req.onreadystatechange = function (e) {
        if (req.readyState == 4) {
            if (req.status == 200)
                handler(req);
//            else
//                alert('A ' + req.status + " error occured while retrieving the XML data:\n" + req.statusText);
        }
    };
    req.open(post_data ? "POST" : "GET", url, true);
    if (post_data)
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    req.send(post_data);
}
