
// -------- configurable variables --------

var APPID = '153733064660828'; // 149190558439512
var WALL_MESSAGE = 'Look what I found!'; // message appended after user'name
var WALL_NAME = 'Win a FREE subscription worth up to $100 *';	// 'Up to 95% off for Magazines delivered to your door in Australia!'; // NAME parameter
var WALL_CAPTION = '* Subscriptions to Australia only'; // caption above the desc of the post
var WALL_DESC = "Magsource isn't an online store - it's a tool to help you find magazines from around the world at the cheapest price that deliver right to your door in Australia!"; // description of the post
var WALL_LOGO = 'http://www.magsource.com.au/images/magazines.jpg'; // url of logo to display on right-side of post
var WALL_ACTIONLINK_TEXT = 'Check it now!'; // action link besides default 'comment' and 'like' links in footer of post.
var WALL_LINK = 'http://www.magsource.com.au'; // link to website.
var DEST_LINK = 'http://www.facebook.com/pages/Magsource/154010034629120'; // final link after user liked the site.
var LIKE_LINK = 'http://www.facebook.com/pages/Magsource/154010034629120';  // fan page link to like

// ------------------------------------------

var publish = {
    method: 'stream.publish',
    message: WALL_MESSAGE,
    attachment: {
        name: WALL_NAME,
        caption: WALL_CAPTION,
        description: (WALL_DESC),
        media: [{
            'type': 'image',
            'src': WALL_LOGO,
            'href': WALL_LINK
        }],
        href: WALL_LINK
    },
    action_links: [{
        text: WALL_ACTIONLINK_TEXT,
        href: WALL_LINK
    }],
    user_prompt_message: 'Share to WIN!'
};

function share() 
{
    FB.ui(publish, function (a) {
        if (a && a.post_id) {
			document.getElementById('share').innerHTML = '';	
			$('#share').fadeOut('slow', function () {
				document.getElementById('like').innerHTML = '<center><fb:like href="'+LIKE_LINK+'" layout="button_count"></fb:like></center>';
				FB.XFBML.parse(); 
				$('#like').fadeIn('slow')
			})
        } else {
            alert('You MUST share this page to WIN, please click share then publish.')
        }
    })
}



window.fbAsyncInit = function () 
{
    FB.init({
        appId: APPID,	
        status: true,
        cookie: true,
        xfbml: true
    });
    FB.Event.subscribe('edge.create', function (href, widget) {
		setTimeout(function() { window.location = DEST_LINK; }, 2000);
    })
};

(function () {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e)
}());


