// REQUIRES CLASS.BALLOONS.JS!!

var Ziptools = Balloons;

// override the showBalloon method for the ziptools
Ziptools['showBalloon'] = function(e){
    var url = Event.element(e).getAttribute('action');
    Ziptools.X = Event.pointerX(e);
    Ziptools.Y = Event.pointerY(e);
    Ziptools.clientX = e.clientX;
    Ziptools.clientY = e.clientY;
    Ziptools.clientWidth = document.body.clientWidth;
    Ziptools.clientHeight = document.body.clientHeight;

    var cb = Ziptools.inflateBalloon;
    if (url.indexOf('save') > 0)
    {
        cb = Ziptools.toggleCheckBox;
    }

    new Ajax.Request(
                url + '?' + document.location.pathname,
                {
                    method: 'get',
                    onComplete: cb
                });

    Event.stop(e);
};

// add a new method
Ziptools['toggleCheckBox'] = function(originalRequest){
    var response = eval('(' + originalRequest.responseText + ')');

    Ziptools.inflateBalloon( {responseText: response.message} );

    if (! response.error)
    {
        if ($('savedbox').src.indexOf('hover') < 0)
        {
            $('savedbox').src = '/images/consumer_v4/icons/checkbox_1_hover.gif';
        }
        else
        {
            $('savedbox').src = '/images/consumer_v4/icons/checkbox_1.gif';
        }
    }
};
