$(document).ready(function() {
	window.fbAsyncInit = function() {
		FB.init({appId: '226355539491', status: true, cookie: true, xfbml: true});
	};
	(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/sv_SE/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());
});

/*
//$(document).ready(function() {
window.onload = function(){
	$("#fb-connect-loader").hide();
	$("#fb-login").show();
	if($("#fb-eid").length > 0){
		//console.log("1");
		var eid = $("#fb-eid").attr("class").replace(/eid-/g,'');
		FB_RequireFeatures(["Connect"],function(){
			//console.log("2");
			FB.init("b5ad865dd78e7860d5cc12677fd915ba", "/xd_receiver.htm", {
				"doNotUseCachedConnectState":true,
				permsToRequestOnConnect:"rsvp_event"
			});
			FB.ensureInit ( function () { 
				 FB.XFBML.Host.autoParseDomTree = false;
				//console.log("3");
				FB.Facebook.get_sessionState().waitUntilReady(function(){
					//console.log("4: "+FB.Facebook.apiClient.get_session().uid);
					setprofile();
				});
			});				
		});	
	}
	
	function setprofile(){
		//console.log("5: "+FB.Facebook.apiClient.get_session().uid);;
		fb_logged_in_data = "";
		//console.log("6: SELECT uid, name, pic_square FROM user WHERE uid="+FB.Facebook.apiClient.get_session().uid);
		
		FB.Facebook.apiClient.fql_query("SELECT uid, name, pic_square FROM user WHERE uid="+FB.Facebook.apiClient.get_session().uid, function(selfuser) {
			//console.log(FB.Facebook.apiClient.get_session().uid)
			fb_logged_in_data +="<div id=\"fb-logout\"><span class\"fblogout\"><a href=\"#\" onclick=\"FB.Connect.logout(function() { document.location.reload(1) }); return false;\">Logga ut</a></span></div>";
			fb_logged_in_data +='<img src="'+selfuser[0].pic_square+'"/>';
			fb_logged_in_data +="<span>Inloggad som "+selfuser[0].name+"</span>";
			$("#fb-login").html(fb_logged_in_data);
			$("#fb-login").addClass("fblogo");
			//console.log("6");
			fbownrsvp();		
		});
	}

	function fbownrsvp () {
		var boxes = new Array();
		FB.Facebook.apiClient.fql_query("SELECT rsvp_status FROM event_member WHERE eid="+eid+" AND uid="+FB.Facebook.apiClient.get_session().uid+"", function(ownrsvprows) {
			if(ownrsvprows.length){					
				if(ownrsvprows[0].rsvp_status=="unsure"){
					currstatus = "unsure";
					boxes.attending = "unchecked";							
					boxes.unsure = "checked";
					boxes.declined = "unchecked";
				}else if(ownrsvprows[0].rsvp_status=="attending"){
					currstatus = "attending";
					boxes.attending = "checked";							
					boxes.unsure = "unchecked";
					boxes.declined = "unchecked";
				}else{
					currstatus = "declined";
					boxes.attending = "unchecked";							
					boxes.unsure = "unchecked";
					boxes.declined = "checked";
				}
			}else{
				currstatus = "declined";
				boxes.attending = "unchecked";							
				boxes.unsure = "unchecked";
				boxes.declined = "checked";						
			}
			rsvpstatus = "<ul>";
			rsvpstatus += "<li><img id=\"attending\" src=\"/wp-content/themes/debaser/img/"+boxes.attending+".png\"> Kommer</li>";
			rsvpstatus += "<li><img id=\"unsure\" src=\"/wp-content/themes/debaser/img/"+boxes.unsure+".png\"> Kommer kanske</li>";
			rsvpstatus += "<li><img id=\"declined\" src=\"/wp-content/themes/debaser/img/"+boxes.declined+".png\"> Kommer inte</li>";
			rsvpstatus += "</ul>";
			
			$("#fb-attending-status").html(rsvpstatus);
			fbgetrsvp();
		});
		
	    
		$("#fb-attending-status ul li img").live("click", function(event){
		//	console.log("yehello");
			$("#fb-attending-status ul li img").attr('src','/wp-content/themes/debaser/img/unchecked.png');
			var clicked = this.id;
			$("#"+clicked).attr('src','/wp-content/themes/debaser/img/checked.png');
			FB.Facebook.apiClient.callMethod('events_rsvp',{eid:eid,rsvp_status:clicked},function(data){
				//$("#"+clicked).attr('src','/wp-content/themes/debaser/img/checked.png');
			});	
		});
	}
	
	function fbgetrsvp () {
		var eventfriends = new Array();
		var eventattendees = new Array();		
		$("#fb-eid-loader").fadeIn(100);
		FB.Facebook.apiClient.fql_query("SELECT uid FROM event_member WHERE eid="+eid+" AND rsvp_status='attending' AND uid IN (SELECT uid2 FROM friend WHERE uid1="+FB.Facebook.apiClient.get_session().uid+")", function(friendrows) {
			if(friendrows){
				for(i=0;i<friendrows.length;i++){
					eventfriends.push(friendrows[i].uid);	
				}
				showrsvpfriends(eventfriends);
			}
			updatersvpcount("eventfriends",eventfriends);
		});
	
		FB.Facebook.apiClient.fql_query("SELECT uid FROM event_member WHERE eid="+eid+" AND rsvp_status='attending'", function(attendingrows) {
			if(attendingrows){
				for(i=0;i<attendingrows.length;i++){
					eventattendees.push(attendingrows[i].uid);	
				}
			}
		//	debaserfb.showrsvprandom(attendingrows);
			updatersvpcount("eventattendees",eventattendees);
		});		
	}

	function updatersvpcount (field,data) {
		if(data.length>0){
			count = data.length;
		}else{
			count = "0";							
		}
		$("#"+field).html(count);
	}
	
	function showrsvpfriends (data){
		var datastring = data.join(",");
		shuffle = function(o){ //v1.0
			for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
			return o;
		};

		FB.Facebook.apiClient.fql_query("SELECT uid, name, pic_square FROM user WHERE uid IN ("+datastring+")", function(frienddatarows) {			
			var temparray = Array();		
			for(i=0;i<5;i++){
				temparray[i] = Array();		
				temparray[i].pic_square = "";
				temparray[i].uid = 0;
				temparray[i].name = "";
			}
			frienddatarows = shuffle(frienddatarows);
			//console.log(frienddatarows);
			if(frienddatarows){
				var eventfriendslist = "\n<table>\n";
				for(i=0;i<temparray.length;i++){
					if(i==0||i==5){
						eventfriendslist += "	<tr>\n";
					}
					if(frienddatarows[i]){
						currobj = frienddatarows[i];
						eventfriendslist += "	<td class=\"fbfriend\">\n";
						eventfriendslist += "		<a rel=\"fbuser-link\" href=\"http://www.facebook.com/profile.php?id="+currobj.uid+"\">\n";
						eventfriendslist += "			<img src=\""+currobj.pic_square+"\">\n";
						eventfriendslist += "		</a>\n";
						eventfriendslist += "		<br/>\n";
						eventfriendslist += "		<a rel=\"fbuser-link\" href=\"http://www.facebook.com/profile.php?id="+currobj.uid+"\">\n";
						eventfriendslist += "			"+currobj.name+"\n";
						eventfriendslist += "		</a>\n";
						eventfriendslist += "	</td>\n";
					}else{
						eventfriendslist += "	<td class=\"fbfriend\">\n";
						eventfriendslist += "	</td>\n";
					}
					if(i==5||i==10){
						eventfriendslist += "	</tr>\n";
					}
				}
				eventfriendslist += "</table>\n";				
				$("#eventfriendslist").html(eventfriendslist);
			}
			$("#fb-eid-loader").fadeOut("100");
			$("#fb-eid-data").fadeIn("300");
		});
	}

}
*/