var Template,pm_send;

j$(function($){
    var pattern = /#{(\w+)}/g;
    $.fn.template_render = function(context){
        var replacement = function(match,scope){return context[scope] || '';};
        this.each(function(i,v){ $(this).html($(this).html().replace(pattern,replacement));});
        return this;
    };
    Template = function(template,context,callback){
        var replacement = function(match,scope){return context[scope] || '';};
        if (callback) return callback(template.replace(pattern,replacement));
        else return template.replace(pattern,replacement);
    };

    $(document).bind('open_login',function(e){
        var login = $('#sb_login_form')
        if (login.length) { 
            login.slideDown(function(){$('#login_username').focus()});
        } else {
            location.reload();
        }
        
    });

    pm_send = function(username,reply_to){
        $('#pm_send_form').remove();
        var data = (username) ?  {fix_to:1,pm_to:username} : {};
        if (reply_to){
            $.extend(data,{reply_to:reply_to});
        }
        $.ajax({
            url : '/dynamic/pm_send/',
            data : data,
            dataType : 'html',
            success : function(data){
                $('body').append(data);
            }
        })
    }
        
    $.getJSONHeader = function(xhr){
        var jsonheader = xhr.getResponseHeader('X-JSON') || xhr.getResponseHeader('JSON');
        if (jsonheader){
            return $.parseJSON(jsonheader)
        }
        return false;
    }
})//(j$);




