//Local Variable with Flash Content id. default = flashcontent

var as_swf_name = "XDeployApplication";
var isLogged = false;


//Initialize Facebook

function fbInit(pAsSwfName,pApi_key,pReceiver){

	as_swf_name = pAsSwfName;

	FB.init(pApi_key,pReceiver);

}

function showPermissionAllowDialog()
{
	FB.Connect.showPermissionDialog("publish_stream", permissionHandler,true);
}

 function permissionHandler(result)
{
	//if user has accepted posting to his wall
	if (!(result === ""))
	{
		//when comment is posted on fb, postComment is called
		flashCallBack("onPermission",true);
	}
	//if user has NOT accepted posting to his wall just post it to local db
	else
	{
		flashCallBack("onPermission",false);
	}
}

function postCommentOnFB()
{
	FB.Connect.streamPublish('Moj komentar na Najbolji outfit u gradu:  ' + document.getElementById('txtDesc').value, null, null, null,'',postComment);
}


//JavaScript Connect methods

function login(){

	FB.Connect.requireSession( onLoginHandler );

}

//Event Handlers

function onLoginHandler(){

	flashCallBack("onLogIn");
}


//Method to dispatch an Event to Flash

function flashCallBack ( func ) {

	if( arguments.length > 1 ){

		document[as_swf_name][func]( Array.prototype.slice.call(arguments).slice(1)[0]);

	}else{

		document[as_swf_name][func](isLogged);

	}

}
