var UserFacebook =  Class.create({    initialize: function(params){        this.id = params.id;        this.name = params.name;        this.first_name = params.first_name;        this.last_name = params.last_name;        this.link = params.link;        this.birthday = params.birthday;        this.hometown = params.hometown;        this.gender = params.gender;        this.birthday = params.birthday;        this.hometown = params.hometown;        this.gender = params.gender;        this.email = params.email;        this.hometown = params.hometown;        this.gender = params.gender;    }})var FacebookFriends = Class.create({    initialize: function(params){        var user = 0;        this.allUserFriends = new Hash()        for( user in params.facebookFriends){            this.allUserFriends.set(user,new UserFacebook(params.facebookFriends[user]))        }    }})var ApiFacebook = Class.create({    //fallo meglio    _HashForNotification : new Hash({        "general" : new Hash({                message : '',                //method : 'feed',                name : '',                link: 'http://dev.casasegafredo.it/',                picture : "",                caption : '',                description : '',                href :  '',                actionLink : [{"text": 'Vai a Casa Segafredo',"href": 'http://www.casasegafredo.it/'}],                userMsgPrompt :'Condividi'            })    }),    _HashForNotificationFeed : new Hash({        "general" : new Hash({                message : '',                method : 'feed',                name : '',                link: 'http://dev.casasegafredo.it/',                picture : "",                caption : '',                description : '',                href :  'http://dev.casasegafredo.it/',                actionLink : [{"text": 'Vai a Casa Segafredo',"href": 'http://www.casasegafredo.it/'}],                userMsgPrompt :'Condividi'            })    }),    initialize: function(params) {        this.userId = params.userId        this.userName = params.userName    },    setHashForMsg: function (msg){        this._HashForNotification.get("general").set("message",bodyForNotification)    },    update: function(config){        this.publishBtn = config.publishBtn;        this.publishToOtherBtn = config.publishToOtherBtn;    },    afterLog: function(){/*        FB.login(function(response) {          if (response.session) {            if (response.perms) {                //alert("welocome on casasegafredo")            } else {                //alert("you must grant the permission to application for to continue")// user is logged in, but did not grant any permissions            }          } else {            // user is not logged in          }        },{perms:'read_stream,publish_stream,offline_access'});*/    },    sessionChanged: function(){            //window.location.reload();    },    fqlQuery: function(params){        //var query = params.query;        var query = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) AND is_app_user = 1'        FB.api('/me', function(query, response) {                var result = FB.Data.query(query, response.id);                result.wait(function(rows) {                    return rows;                })            });            return null;    },    //SELECT notification_id, sender_id, title_html, body_html, href FROM notification WHERE recipient_id={0}  AND is_unread = 1 AND is_hidden = 0 AND created_time > Wed Mar 09 2011 11:46:12 GMT+0100 (CET)    fqlQuery2: function(params){        //var query = params.query;        var query = "SELECT notification_id, sender_id, title_html, body_html, href FROM notification WHERE recipient_id="+params.user_id+"  AND is_unread = 1 AND is_hidden = 0";        //var query = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) AND is_app_user = 1'        FB.api('/me', function(query, response) {                var result = FB.Data.query(query, response.id);                result.wait(function(rows) {                    return rows;                })            });            return null;    },    doubleNotification: function(params){        if(params.serverObject){            if(params.serverObject.FBnotification){                var size = params.serverObject.FBnotification.size();                for(var i = 0; i < size; i++){                    if(params.serverObject.FBnotification[i].ok){                        this.publishStreamToOther(params.serverObject.FBnotification[i],params.clientObject)                        //this.publishStreamToMe(params.serverObject.FBnotification[i],params.clientObject)                    }                }            }        }    },    publishStreamToOther: function(request,data){        request = request.serverObject.FBnotification        var objectExtern = null        var objectIntern = null        var objectIntern2 = null        var string = ''        if(request){            var size = request.size();            for(var i = 0; i < size; i++){                if(typeof  request[i] == "object" ){                    for(objectIntern in request[i])                        if(typeof request[i][objectIntern] == "object" )                            for(objectIntern2 in request[i][objectIntern]){                                this._HashForNotificationFeed.get("general").set(objectIntern2,request[i][objectIntern][objectIntern2]);                                string = '/'+request[i][objectIntern][objectIntern2]+'/feed';                            }                }                FB.api(string,                    'post',{                    message : this._HashForNotificationFeed.get("general").get('message'),                    method : 'feed',                    name : this._HashForNotificationFeed.get("general").get('title'),                    link: this._HashForNotificationFeed.get("general").get('link'),                    picture : "",                    caption : "clicca per accettarlo!",                    description : this._HashForNotificationFeed.get("general").get('description'),                    href :  this._HashForNotificationFeed.get("general").get('href'),                    actionLink : [{"text": 'Vai a Casa Segafredo',"href": 'http://www.casasegafredo.it/'}],                    userMsgPrompt :'Condividi'                    },                    function(response) {                            if (response && response.post_id) {                            } else {                            }                        }                );            }        }    },    publishStreamToMe: function(request,data){        /*        var objectExtern = null        var objectIntern = null        for(objectExtern in request){            if(typeof  request[objectExtern] == "object" ){                for(objectIntern in request[objectExtern])                    this._HashForNotification.get("general").set(objectIntern,request[objectExtern][objectIntern]);            }        }        var string = '/me/feed';        /*var user_id_receiver = request.user_id_receiver_facebook;        var user_name_receiver = data.get(user_id_receiver);        var kind_activity = request.kind_activity;        var bodyForNotification = "@["+this.userId+":1:"+this.userName+"]" + this._HashForNotification.get(kind_activity).get('body') + "@["+user_id_receiver+":1:"+user_name_receiver+"]"*//*        this._HashForNotification.get("general").set("message",bodyForNotification);        FB.api(string,            'post',            this._HashForNotification.get("general")._object,            function(response) {/*              if (response && response.post_id) {                alert('qui ci potrebbe andare un bel feedback tutto nostro');            } else {                alert('qui ci potrebbe andare un bel feedback tutto nostro');            }*/            /*}        );*/    },    publishStream: function(request){        var objectExtern = null        var objectIntern = null        for(objectExtern in request){            if(typeof  request[objectExtern] == "object" ){                for(objectIntern in request[objectExtern])                    this._HashForNotification.get("general").set(objectIntern,request[objectExtern][objectIntern]);            }            FB.ui({                method: 'stream.publish',                message: this._HashForNotification.get("general").get('message'),                attachment: {                    name: this._HashForNotification.get("general").get('title'),                    caption: this._HashForNotification.get("general").get('caption'),                    picture:  this._HashForNotification.get("general").get('picture'),                    message: this._HashForNotification.get("general").get('message'),                    description: this._HashForNotification.get("general").get('description'),                    media: {                        0:{                            type: 'image',                            src: this._HashForNotification.get("general").get('picture'),                            href: "http://dev.casasegafredo.it/"                        }                    }                },                action_links: this._HashForNotification.get("general").get('actionLink'),                user_message_prompt: 'Pubblica'            },            function(response) {/*                if (response && response.post_id) {                    alert('qui ci potrebbe andare un bel feedback tutto nostro');                } else {                    alert('qui ci potrebbe andare un bel feedback tutto nostro');                }*/            });        }    }})
