/*
 * jQuery Bugs system controler
 * Version 0.1 (21 april 2009)
 * @requires jQuery v1.2.3 or later
*/
jQuery.bugs = {
    path:       '',
    phpsessid:  '',
    width:      '',
    height:     '',
    user:       '',
    application:'',
    page:       2,

    open:function(path,width,height,application,user,phpsessid,page)
    {
        if(path.substring(path.length,1) != '/')
        {
            path += '/';
        }
        this.path       = path;
        this.width      = width;
        this.height     = height;
        this.phpsessid  = phpsessid;
        this.user       = user;
        this.application= application;
        if(page != undefined)
        {
            this.page = page;
        }

        
        $.get(	path+'bug/edit',
			  	{
                    bugApplication  : application,
                    bugUser         : user,
                    page            : this.page,
                    PHPSESSID       : phpsessid
                    },
				this.recievedPanel
			);        
    },

    changePage:function(page)
    {
       $.page.open($.page.path,$.page.width,$.page.height,$.page.application,$.page.user,$.page.phpsessid,page);
    },

    recievedPanel:function(data)
    {
        $.blockUI({
                        message:    data,
                        css: {
                            top:        '50px',
                            position:   'absolute',
                            width:      $.bugs.width,
                            height:     $.bugs.height,
                            cursor:     'pointer'
                        },
                        allowBodyStretch: true
                    });
        $('#saveBug').click($.bugs.save);
        $('[id^="bug_"]').click($.bugs.remove);
    },

    save:function()
    {
          $.get(    $.bugs.path+'bug/savebug/phpsessid/'+$.bugs.phpsessid,
                    $('#editBugForm').serialize(),
                    $.bugs.saved
             );
    },

    saved:function(data)
    {
        $.blockUI({
                        message:        data,
                        css: {
                            top:        '50px',
                            width:      $.bugs.width,
                            height:     $.bugs.height,
                            cursor:     'pointer'
                        }
                    });
        $('#bugClose').click($.bugs.close);
    },

    remove:function()
    {
        bugID = this.id.replace('bug_','');
        alert(bugID);
    },

    close:function()
    {
        $.unblockUI();
    }
};