// JavaScript Document
document.write("<div id=\"fb-root\"></div>");
//
var session=0;
var fans=false;
var fansfbml=false;
var loginfbml=true;

FB.init({ 
		appId:'073ea8bee65721a61d2740e53d3c9116', 
		cookie:true, 
    	status:true, 
		xfbml:true
		});

FB.Event.subscribe('auth.login', function(response) {
	session=response.id;
	loginfbml=false;
});
FB.getLoginStatus(function(response) {
  if (response.session) {
	session=response.uid;
	loginfbml=false;
  } else {
	loginfbml=true;
  }
});


function isFan(){
	var fan  = 0;
	FB.api('/me', function(response) {
    	var flashObject = document.getElementById('extStLp');
		var query = FB.Data.query('select uid from page_fan where page_id="158218484239038" and uid={0}', response.id);
        query.wait(function(rows) {
		if(rows[0] == null){
			fans=false;
			if(!fansfbml){
				showFans();
				if (flashObject != null) {
					flashObject.loginResultMalo();					
				}
			}else{
				if (flashObject != null) {
					flashObject.loginResultFan();					
				}
			}
		}else if(rows[0].uid){
			fans=true;			
			if (flashObject != null) {
				flashObject.loginResultOk();
				swfCerrar();
			}
		}
      	});
     });
}

function login(){
	$('#login').hide('normal');	
	var fan  = 0;
	FB.api('/me', function(response) {
		var flashObject = document.getElementById('extStLp');
    	var query = FB.Data.query('select uid from page_fan where page_id="158218484239038" and uid={0}', response.id);
        query.wait(function(rows) {
		if(rows[0] == null){
			showFans();
			if (flashObject != null) {
				flashObject.loginResultMalo();
			}else{
				alert("NO CONECTA");	
			}
		}else{
			fans=true;			
			if (flashObject != null) {
				flashObject.loginResultOk();
			}else{
				alert("NO CONECTA");	
			}
		}
      	});
     });
}

function publicWall(ax){
	FB.ui({
		  method: 'feed',
		  name: 'Vive como un RockStar con Rocklets',
		  link: 'http://www.rocklets.net',
		  picture: 'http://www.rocklets.net/img/75x75-02.jpg',
		  caption: 'Participa por un viaje para ti y tu mejor amigo(a) a los Latin Grammy`s en las Vegas, USA.',
		  description: 'Entra a www.rocklets.net',
		  message: ax
	   },
	   
	   function(response) {
		 if (response && response.post_id) {		  
		   //location.href="login.php?fbk=" + ax +"&scc="+ $('#sccj').val();
		 } else {
		   //location.href="login.php?fbk=" + ax +"&scc="+ $('#sccj').val();
		 }
	   }
	 );
}

function test(){
	FB.ui({
	  method: "stream.publish",
	  display: "iframe",
	  user_message_prompt: "Publish This!",
	  message: "I am so smart!  S M R T!",
	  attachment: {
		 name: "Joe has a gift!",
		 caption: "Joe has tested his skills and did extremely well",
		 description: "Here is a list of Joe's skills:",
		 href: "http://example.com/",
		 media:[{"type":"image","src":"http://example.com/imgs/skills.png","href":"http://example.com/"}],
		 properties:{
		   "1)":{"text":"Reading","href":"http://example.com/skill.php?reading"},
		   "2)":{"text":"Math","href":"http://example.com/skill.php?math"},
		   "3)":{"text":"Farmville","href":"http://example.com/skill.php?farmville"}
		 }
	  },
	  action_links: [{ text: 'Test yourself', href: 'http://example.com/test.php' }]
	 },
	 function(response) {
	   if (response && response.post_id) {
		 //alert('Post was published.');
	   } else {
		 //alert('Post was not published.');
	   }
	 }
	);
	
	}

