if (!blogdowntown) 
    var blogdowntown = {}

blogdowntown.Facebook = Class.create();
blogdowntown.Facebook.prototype = {
    DefaultOptions : {
        api_key : "eafefed421596f98b07b686ef4a8ea56",
        xd_path : "/connect/xd_receiver.htm",
        template_comments : "40497776906"
	},
	
    initialize : function(options) {
    	this.options = Object.extend(
			Object.extend({},this.DefaultOptions), options || {}
		);
		
		document.observe("dom:loaded", function() {
		    // Load feature loader asynchronously 

            var head = document.getElementsByTagName("head")[0], 
                script = document.createElement("script"), 
                done = false; 

            script.src = 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'; 

            script.onload = script.onreadystatechange = function(){ 
                if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { 
                    done = true;
                    FB.init(this.options.api_key,this.options.xd_path);
                } 
            }.bind(this); 

            head.appendChild(script); 
		}.bind(this))
	    	    	    
	    // attach a function that will check session state
	    //FB.Facebook.get_sessionState().waitUntilReady( this._checkSessionState.bind(this) )
    },
    
    logout : function() {
        FB.Connect.logoutAndRedirect("/logout")
        
        false
    },
    
    _checkSessionState : function() {
        // are we connected?
        FB.Connect.ifUserConnected( this._userIsConnected.bind(this) , this._userIsNotConnected.bind(this) )
    },
    
    _userIsConnected : function(uid) {
        //alert('user is connected')
    },
    
    _userIsNotConnected : function() {
        //alert('user is not connected')
    },
    
    returnUserIdent : function(el) {
        // call the user fbauth function
        new Ajax.Updater(el,'/user/fbauth',{ onComplete: function(){ 
            FB.XFBML.Host.parseDomTree()
            FB.Connect._singleton._feedStatusRefetch() 
        }})
    },
    
    popCommentFeedForm : function(data) {
        FB.Connect.showFeedDialog(this.options.template_comments, data, null, null, null, FB.RequireConnect.requireConnect)
        FB.XFBML.Host.parseDomTree()
    },
    
    shareStory : function() {
        FB.Connect.showShareDialog(window.location,function() {})
    }

}