﻿/* Environment Detection */
var fbAppID;
var fbAPIKey;
var fbAppURL;
var trackPath = "/promotions/wordalicious-game/";
var isFacebook = false;

if (location.host.toLowerCase().indexOf("ryanpromos.com") != -1){
    siteURL = 'http://breyers-ryan.ryanpromos.com/promotions/wordalicious-game/';
	fbAppURL = 'http://apps.facebook.com/wordaliciousdev/';
	fbAppID = '133328876697898';
	fbAPIKey = 'db9471e7860e9cd23f91649e7fadf689';
} else if (location.host.toLowerCase().indexOf("stage.breyers.com") != -1){
    siteURL = 'http://stage.breyers.com/promotions/wordalicious-game/';
	fbAppURL = 'http://apps.facebook.com/wordaliciousstage/';
	fbAppID = '141304149218778';
	fbAPIKey = '806a31954718d8115f7264d81938739b';
} else {
    siteURL = 'http://www.breyers.com/promotions/wordalicious-game/';
	fbAppURL = 'http://apps.facebook.com/wordalicious/';
	fbAppID = '138288442863887';
	fbAPIKey = 'a822f1396addbeb69af8b81fe17563f8';
}

function fbStreamPublish(_name, _caption, _description, _href, _imageSrc, _actionText, _actionHref, _userPrompt, _message, shareType){
	if (_href == null){
	    if (isFacebook){
    		_href = fbAppURL;
    	} else {
    	    _href = siteURL;
    	}
	}
	if (_actionHref == null){
		_actionHref = _href;
	}
	if (_imageSrc == null){
		_imageSrc = "http://www.breyers.com/images/recipe_photo_default.jpg";
	}
	var publish = {
		method: 'stream.publish',
		message: _message,
		attachment: {
			name: _name,
			caption: _caption,
			description: _description,
			href: _href,
			media: [{ 
				type: 'image',
				src: _imageSrc,
				href: _href
			}] 
		},
		action_links: [
			{ text: _actionText, href: _actionHref }
		],
		user_prompt_message: _userPrompt
	};
	
	FB.ui(publish, function(response) {
		if (response && (response.post_id != null)) {
			gameTrack("share_" + shareType);
		} else {
		}
		if (shareType == "band_setup"){
			gameStopsConcert();
		}
	});
}

function fbShareDefault(){
	fbStreamPublish("Breyers Wordalicious Word Game", "{*actor*} is playing now!", "Play Wordalicious! It's so much fun, check it out!", null, null, "Play Now", null, "", "", "default");
}

function fbShareScore(finalScore){
	fbStreamPublish("Breyers Wordalicious Word Game", "My Wordalicious score is " + finalScore + ".", "Play this fun game and see if you can beat my score! It's a lot more challenging than it looks!", null, null, "Play Now", null, "", "", "score");
}

function gameTrack(eventTag){
    if (isFacebook){
        eventTag = "facebook/" + eventTag;
    }
    pageTracker._trackPageview(trackPath + eventTag);
}

