
var h = document.getElementsByTagName('html')[0];
h.style.padding = 0;
h.style.margin = 0;
h.style.textAlign = 'center';

var b = document.getElementsByTagName('body')[0];
b.style.padding = 0;
b.style.margin = 0;
b.style.textAlign = 'center';


function getViewerProfile()
{
	
	var os = opensocial.Container.get();
    var dataRequest = os.newDataRequest();
	    
    var PROFILEReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER, {});

    dataRequest.add(PROFILEReq);

    dataRequest.send(onGetViewerProfile);

return 1;

}
function onGetViewerProfile(response)
{
	
	var fData;
	
    if( response.hadError() )
    {
        fData = "There is an error in the response.";
        
    } else {
    	
    	fData = response.get(opensocial.DataRequest.PersonId.OWNER).getData();
//    	var OWNER_ID = response.get(opensocial.DataRequest.PersonId.OWNER).getId();
//    	var OWNER_NAME = response.get(opensocial.DataRequest.PersonId.OWNER).getDisplayName();
    	    
    }
    
    var flashObj = document.getElementById('mentos_flash');
    

    flashObj.onGetViewerProfile( fData );
    
}

function getFriends( limit, page )
{
	
	var os = opensocial.Container.get();
    var dataRequest = os.newDataRequest();
	
    var friendsParams = {
    }
    ;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS ] = [opensocial.Person.Field.ID, opensocial.Person.Field.NAME, opensocial.Person.Field.GENDER, opensocial.Person.Field.THUMBNAIL_URL];
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.FILTER ] = opensocial.DataRequest.FilterType.ALL;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.FIRST] = page;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.MAX ] = limit;

    var FRIENDSReq = os.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, friendsParams);

    dataRequest.add(FRIENDSReq);

    dataRequest.send(onGetFriends);

return 1;

}
function onGetFriends(response)
{
	
	var fData;
	
    if( response.hadError() )
    {
        fData = "There is an error in the response.";
        
    } else {
    	
    	var VIEWRE_FRIENDS_COL = response.get(opensocial.DataRequest.Group.VIEWER_FRIENDS).getData();

    	fData = [ VIEWRE_FRIENDS_COL.getTotalSize() ];
    	
	    var VIEWER_FRIENDS = VIEWRE_FRIENDS_COL.asArray();
	    for(var i=0; i < VIEWER_FRIENDS.length; i++)
	    {
		    var f = {};
		    f["id"] = VIEWER_FRIENDS[i].getField(opensocial.Person.Field.ID);
		    f["name"] = VIEWER_FRIENDS[i].getField(opensocial.Person.Field.NAME);
		    f["photo"] = VIEWER_FRIENDS[i].getField(opensocial.Person.Field.THUMBNAIL_URL);
			f["gender"] = VIEWER_FRIENDS[i].getField(opensocial.Person.Field.GENDER);
			        
	        fData.push( f );
	    }
    
    }
    
    var flashObj = document.getElementById('mentos_flash');
    

    flashObj.onGetFriends( fData );
    
}


function postActivity(user1, user2, user3) {
var params = {};
params[opensocial.Activity.Field.TITLE_ID] = "UserPlayed";
params[opensocial.Activity.Field.TEMPLATE_PARAMS] = {"user1":user1,"user2":user2,"user3":user3};

var activity = opensocial.newActivity(params);
opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH, done);

return params;
}

function sendChallenge(challengerId, challengeIds, message) {
		// create the list of buttons 
		var firstButton = MyOpenSpace.newNotificationButton(MyOpenSpace.NotificationButton.UrlTypes.CANVAS, 
			'Take the challenge', // dynamic button text
			{c:challengeIds}); // app parameters to pass to the canvas page
 		var buttons = [firstButton];
 
		// create the notification parameters
		var param = {};
		param[MyOpenSpace.Notification.Field.BODY] = message; 
		param[MyOpenSpace.Notification.Field.BUTTONS] = buttons;
		var notification = MyOpenSpace.newNotification(param);
 		 
	    // raise the notification
		MyOpenSpace.requestCreateNotification(challengerId, notification, done); 		
	}


function done(r) {

}
function invite( uids ) {
 var reason = opensocial.newMessage("Play Mentos Cube Peck Poke Pash!");
 reason.setField(opensocial.Message.Field.TITLE, "Play Mentos Cube Peck Poke Pash!");
    opensocial.requestShareApp(uids, reason, done);
}

	var params = {
		quality: "high",
		scale: "noscale",
		wmode: "transparent",
		allowscriptaccess: "always",
		allownetworking: "all",
		bgcolor: "#FFFFFF"
	};
	var flashvars = {};
	var attributes = {
		id: "mentos_flash",
		name: "mentos_flash"
	};
	swfobject.embedSWF("http://cache01-widget01.myspacecdn.com/1/l_5b8507c9537906c762cee1cbe4fac56c.swf", "mentos_flash", "760", "565", "10", "", flashvars, params, attributes);
