	//common
	function thisMovie(movieName) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	}
	
	
	
	
	//login form	
	function requireFBSession() {
		FB.Connect.requireSession(function() {
			if (FB.Facebook.apiClient.get_session() != null) {
				FB.Connect.showPermissionDialog("publish_stream, photo_upload, user_photos", function() {
					islogin();
				});
			}
		}, function() { invoke_cancel_function(); });		
	}
		
	function islogin(){
		thisMovie("gswf").userlogined();
	}
	
	function invoke_cancel_function(){
		thisMovie("gswf").usercancellogin();
	}







	//post to wall
	function posttowall(){
		track("share>facebook>posttowall");
		FB.Connect.requireSession(function() {
			if (FB.Facebook.apiClient.get_session() != null) {				
				FB.Connect.showPermissionDialog("publish_stream", function() {
					sendpost();					
				});
			}
		}, function() { cancelpost(); });
	}
	
	function sendpost(e_id, img){
		track("share>facebook>sendpost");
		var message = '';
		var attachment = {
			'name': 'Share Your Joyous Moment with OXY!',
			'href': global_url+'get_details.php?e_id='+e_id, 'caption': '{*actor*} has just submitted a joyous photo to win RM 3000 cash.',
			'description': 'Interested? You too can submit your own photo today!',
			"media": [{ "type": "image", "src": img, "href": global_url+"get_details.php?e_id="+e_id}]
		};
		var action_links = [{ 'text': 'Play Now!', 'href': global_url+'get_details.php?e_id='+e_id}];
		
		FB.Connect.streamPublish(message, attachment, action_links, null, "Share Your Joyous Moment with OXY!", afterpost, false, null);
	}
	
	function afterpost(){
		;//thisMovie("gswf").userposted();
	}
	
	function cancelpost(){
		;
	}
	






	
	//Invite friend form
	var aPosition;
	var windowWidth = 0;
	var windowHeight = 0;
	
	function inviteFriends(e_id){
		track("share>facebook>invite_friends");
		var dinvite = document.getElementById("dinvite");
		aPosition = getScrollXY();
		
		if (self.innerHeight) {	 
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {  
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {  
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		dinvite.style.display = '';
		dinvite.style.top = '100px';
		dinvite.style.left = aPosition[0] + ((parseInt(windowWidth)/2)-(parseInt(dinvite.style.width))/2)+'px';
		
		document.getElementById("floading").style.display = "";			
		//document.getElementById("sinvite").src = 'invite.php'+document.location.search;
		document.getElementById("sinvite").src = 'invite.php?e_id='+e_id;
	}
	
	function closeInviteFriends(){
		document.getElementById("dinvite").style.display = 'none';
		document.getElementById("sinvite").src = '';
	}
	
	function closeloading(){
		document.getElementById("floading").style.display = "none";
	}
		
	function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}

