/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$.controller = function(controller_name)
{
    this.controller_name = controller_name;

    /*
     * Performs a GET request on the specified controller
     */
    this.action = function(action_name, send_data, callback)
    {
        if (!send_data) send_data = {};

        for (x in send_data)
        {
            /*
             * Only want to stringify arrays, not strings or numbers
             */

            if (typeof send_data[x] == 'Array'||typeof send_data[x] == 'object')
            {
                send_data[x] = JSON.stringify(send_data[x]);
            }
        }

        if (!callback) callback = function(data) {};

        var ctl = this.controller_name + '_controller';

        if (ctl && action_name)
        {
            jQuery.get('/data/select.data.php?class=' + ctl + '&method=' + action_name, send_data, callback, 'json');
        }
    }

    return this;
}

