if(typeof(FB)=='undefined')
{
	/* Load in the Facebook JS file if it doesn't exist already*/
	var scrElm = document.createElement("script");
	scrElm.src = 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php';
	document.body.appendChild(scrElm);
}
//Don't load in the Headliner tag manager if it's already loaded. Only want one static instance
if(typeof(__sc__connect)=='undefined')
{
    var __sc__connect = {
        tags: new Array(), //Store all the iframes on the page that we want to use Headliners for
        publishers: new Array(), //Store all the publisher_id's, in case there are different ones for each placement
        check: function() {
            if ((typeof (FB) == 'undefined') || !FB || !FB.Connect || !FB.Facebook.apiClient || !FB.Facebook.apiClient.get_session() || !FB.Facebook.apiClient.get_session().session_key) {
                setTimeout(__sc__connect.check, 100);
            }
            else {
                var apiKey = FB.Facebook.apiClient._apiKey;
                var sessionKey = FB.Facebook.apiClient.get_session().session_key;
                var uid = FB.Facebook.apiClient.get_session().uid;
                var secret = FB.Facebook.apiClient.get_session().secret;
                var adurl;
                adurl = 'http://cdn.socialcash.com/allfacebook/ad.html?fb_sig_session_key=' + sessionKey + '&fb_sig_ss=' + secret + '&fb_sig_user=' + uid + '&fb_sig_api_key=' + apiKey;
                for (var i = 0; i < __sc__connect.tags.length; i++)
                    window.frames[__sc__connect.tags[i]].location.href = adurl.replace(/{publisher_id}/, __sc__connect.publishers[i]);
				document.getElementById('headliner_intro').style.display = 'none';
				document.getElementById('headliner').style.display = 'block';
            }
        },
        write: function() {
            var frameName = '__sc__ad_frame_' + __sc__connect.tags.length;
            __sc__connect.tags[__sc__connect.tags.length] = frameName;
            document.write('<iframe src="' + __sc__default__advertiser + '" id="' + frameName + '" name="' + frameName + '" width="' + __sc__width + '" height="' + __sc__height + '" frameborder="0" scrolling="no"></iframe>');
            __sc__connect.publishers[__sc__connect.publishers.length] = __sc__publisher;
        }
    }
}
__sc__connect.write();
setTimeout(__sc__connect.check,100);