/**
 * 
 */
var flashObject = null;
var app_id = null;
var api = null;
var uid = null;
var justconnecting = true;

function getMovie(){
	if(flashObject == null){
		flashObject = document.getElementById('flashcontent');
	}
	return flashObject;
}

function setFB(){
	//mandar parametro de secci√≥n
	FB.getLoginStatus(function(response) {
		if (response.authResponse) {
	    	obtenerDatos(true, "completo");
	    } else {
	    	getLogin();
	    }
	});
}

function getLogin(){
	FB.login(function(response) {
		if (response.authResponse) {
			FB.api('/me', function(response) {
				obtenerDatos(true, "silogin");
			});
		} else {
			obtenerDatos(false, "nologin");
		}
	}, {scope:'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos,read_stream,user_status'});
}

function obtenerDatos(valor, accion){
	getMovie().getFB(valor, accion);
}

function popup(page, height, width)
{
  var url = page;
  var h = height;
  var w = width;
  var left=(screen.width)?(screen.width - width)/2:100;
  var top=(screen.height)?(screen.height - height)/2:100;
  
  var popup = window.open(url,'popUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + w + ',height=' + h + ',left='+left+',top='+top);
  var timer = setInterval(function() {   
	  if(popup.closed && popup != null) {  
	        clearInterval(timer);  
	        document.getElementById('flashcontent').animar();
	    }  
	}, 1000)
	popup.focus();
}

function shareFB(url){
    var surl = "http://www.facebook.com/sharer.php?u="+encodeURIComponent(url);
    popup(surl, 300, 600);
}

function shareTwitter(url){
	var texto = url;
    var surl = "http://twitter.com/share?url="+url+"&text=Visita http://www.doritos.com.co, cumple el desafío APRETADITOS y podrás ganar un viaje para 6 personas";
    popup(surl, 300, 600);
}

function isReady(){
	return true;
}
