var rateSuccess = function(data, textStatus)
{
    if (textStatus != 'success')
    {
        alert('Error ' + textStatus + ' -- ' + data);
    }
    
    if (data == 'OK')
    {
        $("#rate_error").hide();
        $("#rate_sending").hide();
        $("#rate_success").show();
    }
    else
    {
        $('#rate_error').html(data);
        $("#rate_error").show();
        //Effect.Pulsate('rate_error');
        $("#rate_sending").hide();
    }
}

function vr (v,i)
{
    $("#rate_it").hide();
    $("#rate_error").hide();
    $("#rate_sending").show();
    
    $.post("/creations/vote/" + i + "/ajax", { rating: v }, rateSuccess);
}

function sr (v)
{
    for (i = 1; i <= 6; i++)
    {
        if (i <= v)
        {
            $("#rating" + i).attr("src", "http://images.wallaceandgromit.com/creations/star_over.png");
        }
        else
        {
            $("#rating" + i).attr("src", "http://images.wallaceandgromit.com/creations/star_off.png");
        }
    }
}

function prepItems()
{
    /*if (!document.getElementsByTagName) return false;
    if (!document.getElementById) return false;
    if (!document.getElementById("creations_area")) return false;
    var gallery = document.getElementById("creations_area");
    var links = gallery.getElementsByTagName("div");
    for (var i=0; i < links.length; i++)
    {
        if (links[i].className == 'creation_item')
        {
            links[i].onmouseover = function() {
                highlight(this, 1);
                return false;
            }

            links[i].onmouseout = function() {
                highlight(this, 0);
                return false;
            }
        
        }
    }*/
}

function highlight(element, state)
{
    if (state == 1)
    {
        element.style.background = "url(http://images.wallaceandgromit.com/creations/item_bg_on1.jpg) top left no-repeat";
    }
    else
    {
        element.style.background = "url(http://images.wallaceandgromit.com/creations/item_bg_off1.jpg) top left no-repeat";
    }
}
