/*
 * facebook_functions.js
 * Requires jQuery
 * Requires connection to http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php
 * 
*/

//Initialize facebook connection
jQuery(document).ready(function()
{
	//Makes sure XFBML JS components are loaded
	FB_RequireFeatures(["XFBML"], function(){
	    //make the conenction
	    fbConnect();
	});
});

//This is called when document is ready
function fbConnect(){
	var api_key = "9424487cf5f8544a6c0fe4105bd89ae2"; //Live Key
	//var api_key = "eb2a672881e29ecff91a9ac1e0bf6fc3"; //Dev Key
	var channel_path = "xd_receiver.htm";
	FB.init(api_key, channel_path, {"reloadIfSessionStateChanged": true, "ifUserConnected": update_user_box()});
}

//Function to display post to wall dialog
function post_video_to_wall()
{
	var name = 'Summer break - It\'s the reason you became a student!';
	var link = 'http://www.summerbreak.co.uk';
	var message = 'Celebrate end of exams!';
	var caption = 'Check out Summer Break with {*actor*}';
	var description = 'Organise a trip with Outgoing to Summer Break and we will provide you the most incredible end of exam experience. Much like skipping a lecture or doing the walk of shame, Summer Break is an essential part of your university life!';
	var attachment = { 'name': name, 'href': link, 'caption': caption, 'description': description, 'media': [{ 'type': 'image', 'src': 'http://www.summerbreak.co.uk/img/promomaterial/summerbreak_logo.jpg', 'href': 'http://www.summerbreak.co.uk'}] };
	var action_links = [{'text':'Summer Break!', 'href':'http://www.summerbreak.co.uk'}];
	FB.Connect.streamPublish(message, attachment, action_links);
}

//wrapper to get uid of current logged in user
function get_logged_in_user()
{
	FB.ensureInit (function (){
	   return fb_uid = FB.Connect.get_loggedInUser();
	});
}



function update_user_box() {
/*
var user_box = document.getElementById("cta-social-share");
var comments_box = document.getElementById("facebook_comments_box");
var group_id = {$group.id};

user_box.innerHTML =
"<span>"
+ "<fb:profile-pic uid='loggedinuser' facebook-logo='true'></fb:profile-pic>"
+ "Welcome, <fb:name uid='loggedinuser' useyou='false'></fb:name>"
+ "</span><hr /><br />";

FB.XFBML.Host.parseDomTree();
*/
}