﻿


        function ConnectToFacebook_forAudio(songName) {
            FB.login(function (response) {
                if (response.session) {
                    if (response.perms) {
                        // user is logged in and granted some permissions.
                        // perms is a comma separated list of granted permissions

                        //now that user has granted permissions post the song to their feed ...
                        var name = songName + ' By Johnny Hollow';
                        var message = 'check out this track by Johnny Hollow ...';
                        var song = 'http://www.johnnyhollow.com/adminAudio/' + songName;
                        var picture = 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg';
                        var link = 'http://www.johnnyhollow.com';

                        FB.api('/me/feed', 'post', { name: name, message: message, link: link, picture: picture, source: song }, function (response) {
                            if (!response || response.error) {
                                //ConnectToFacebook(songName);
                            } else {
                                //alert('Post ID: ' + response);
                            }
                        });
                    } else {
                        // user is logged in, but did not grant any permissions
                    }
                } else {
                    // user is not logged in
                }
            }, { perms: 'publish_stream' });
        }



        function ConnectToFacebook_forVIDEO(postTitle, video) {
            FB.login(function (response) {
                if (response.session) {
                    if (response.perms) {
                        // user is logged in and granted some permissions.
                        // perms is a comma separated list of granted permissions

                        //now that user has granted permissions post the song to their feed ...
                        var message = 'check out this video posted on JohnnyHollow.com ...';
                        var name = postTitle;
                        var source = video;
                        var picture = 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg';
                        var link = 'http://www.johnnyhollow.com';

                        FB.api('/me/feed', 'post', { name: name, message: message, link: link, source: source, picture: picture }, function (response) {
                            if (!response || response.error) {
                                ConnectToFacebook_forVIDEO(postTitle, video);
                            } else {
                                //alert('Post ID: ' + response);
                            }
                        });
                    } else {
                        // user is logged in, but did not grant any permissions
                    }
                } else {
                    // user is not logged in
                }
            }, { perms: 'publish_stream' });
        }




        function shareVideoOnFacebook(postTitle, video) {
        /*
            var atch = {
                href: 'http://www.johnnyhollow.com',
                name: postTitle,
                media: [{ type: 'flash', swfsrc: video, imgsrc: 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg'}]
            };

            FB.ui(
                {
                    method: 'stream.publish',
                    message: 'Check out the video ' + postTitle + ' posted on JohnnyHollow.com',
                    attachment: atch,
                    href: 'http://www.johnnyhollow.com'
                },
                function (response) {
                    if (response && response.post_id) {
                        //success action
                    } else {
                        //failure action
                    }

                }
            );
            */


                FB.login(function (response) {
                    if (response.session) {
                        if (response.perms) {
                            // user is logged in and granted some permissions.
                            // perms is a comma separated list of granted permissions
                            // PublishToUsersWall();

                            FB.ui(
                            {
                                method: 'stream.share',
                                message: 'Check out this music video by Johnny Hollow ...',
                                u: video,
                                t: postTitle
                            });

                        } else {
                            // user is logged in, but did not grant any permissions
                        }
                    } else {
                        // user is not logged in
                    }
                }, { perms: 'publish_stream' });












        }




        function ConnectToFacebook_forPOST(postTitle, post) {
            FB.login(function (response) {
                if (response.session) {
                    if (response.perms) {
                        // user is logged in and granted some permissions.
                        // perms is a comma separated list of granted permissions

                        //now that user has granted permissions post the song to their feed ...
                        var message = 'just read this post on JohnnyHollow.com ...';
                        var name = postTitle;
                        var caption = post;
                        var picture = 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg';
                        var link = 'http://www.johnnyhollow.com';

                        FB.api('/me/feed', 'post', { name: name, message: message, link: link, caption: caption, picture: picture }, function (response) {
                            if (!response || response.error) {
                                //ConnectToFacebook_forPOST(postTitle, post);
                            } else {
                                //alert('Post ID: ' + response);
                            }
                        });
                    } else {
                        // user is logged in, but did not grant any permissions
                    }
                } else {
                    // user is not logged in
                }
            }, { perms: 'publish_stream' });
        }

        
        function shareSpeakUpPostOnFacebook(post) {

                var atch = {
                    href: 'http://www.johnnyhollow.com',
                    description: post,
                    media: [{ type: 'image', src: 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg', href: 'http://www.johnnyhollow.com'}]
                };

                FB.ui(
                {
                    method: 'stream.publish',
                    message: 'just read this post on JohnnyHollow.com ...',
                    attachment: atch,
                    href: 'http://www.johnnyhollow.com'
                },
                function (response) {
                    if (response && response.post_id) {
                        //success action

                    } else {
                        //failure action
                    }

                }
            );
        }


        /* THIS WILL DECODE THE URL ENCODED STRINGS */
        function decode(input) {
            var encodedStr = input;
            var decodedStr = decodeURIComponent(encodedStr.replace(/\+/g, " "));
            return decodedStr;
        } 




        function sharePostOnFacebook(postTitle, post, imagePath) {

            FB.ui(
            {
                    method: 'stream.publish',
                    message: 'Just read this post On Johnny Hollows website ...',
                    attachment: {
                        name: postTitle,
                        description: decode(post),
                        media: [{ type: 'image',
                            src: 'http://www.johnnyhollow.com/imagesProduction/johnnyhollowIcon.jpg',
                                href: 'http://www.johnnyhollow.com'
                            }],
                        href: 'http://www.johnnyhollow.com'
                    }
                },

            function (response) {
                if (response && response.post_id) {
                    //success action

                } else {
                    //failure action
                }

            });
        }

        function shareAdminImageOnFacebook(imageCaption, imagePath) {

            FB.ui(
            {
                method: 'stream.publish',
                message: 'This photo is from johnnyhollow.com ...',
                attachment: {
                    name: imageCaption,
                    description: ('This image is from johnnyhollow.com'),
                    media: [{ type: 'image',
                        src: 'http://www.johnnyhollow.com/adminImages/' + imagePath,
                        href: 'http://www.johnnyhollow.com'
                    }],
                    href: 'http://www.johnnyhollow.com'
                }
            },

            function (response) {
                if (response && response.post_id) {
                    //success action

                } else {
                    //failure action
                }

            });
        }


        function shareUserImageOnFacebook(imageCaption, imagePath) {

            FB.ui(
            {
                method: 'stream.publish',
                message: 'This photo is from johnnyhollow.com ...',
                attachment: {
                    name: imageCaption,
                    description: ('This image is from johnnyhollow.com'),
                    media: [{ type: 'image',
                        src: 'http://www.johnnyhollow.com/adminImages/' + imagePath,
                        href: 'http://www.johnnyhollow.com'
                    }],
                    href: 'http://www.johnnyhollow.com'
                }
            },

            function (response) {
                if (response && response.post_id) {
                    //success action

                } else {
                    //failure action
                }

            });
        }
