﻿
$('.emailFriend').click(function () {
    GB_show('Email A Friend', '/contact/email-a-friend~form.aspx?gb=true&amp;page=' + encodeURI(window.location.pathname + window.location.search), 640, 520);
    return false;
});
$(function () {
    FB.Event.subscribe('edge.create', function (response) {
        pageTracker._trackPageview("/social/facebook/like" + encodeURI(window.location.pathname + window.location.search));
    });

    $('.scsmFacebook').click(scsmFacebook_Click);

});



function scsmFacebook_Click(e) {
    // do facebook share
    var iMaxDescLength = 250;
    var sDomain = window.location.protocol + "//" + window.location.host;
    var imgPicture = $('.contentBlock img:first');
    var sPictureUrl = imgPicture.length > 0 ? sDomain + imgPicture.attr('src').replace('/images/thumb?img=', '').replace('/images/mojothumb.aspx?img=', '') : null;
    if (sPictureUrl != null)
        sPictureUrl = sPictureUrl.substring(0, sPictureUrl.indexOf('&'))
    var sDesc = $('.contentBlock p:first').text();
    FB.ui(
        {
            method: 'feed'
            , display: 'popup'
            , link: window.location.href
            , name: $('h1').text()
            , caption: sDomain
            , description: sDesc.length > iMaxDescLength ? sDesc.substring(0, iMaxDescLength) + '...' : sDesc
            , picture: sPictureUrl
        },
        function (response) {
            if (response && response.post_id) {
                // send info to analytics
                pageTracker._trackPageview("/social-media/facebook-post/" + encodeURIComponent($('h1').text()));
            }
        }
    );

    return false;
}
