	var base_url="";

	var post_data="";

	var myFriends="";

	var recipients;

	var myFriendsName="";

	var myFriendsThumb="";

	var dataReqObj;

	var myrecipients=new Array();

	var friendID;

 	var friends={};

	var total_friends=0;

	var totalGroups=3;

	var vF=new Array(10);





	for(i=0;i<totalGroups;i++)

	{

	vF[i]="vF"+i;

	}

	

	var myfriendID;



 	var allfriends = '';

 	var html='';

	var globalContent="";

	var kk=0;

	var urlpage="";

	var os_token = MyOpenSpace.MySpaceContainer.OSToken;

	var osContainer = opensocial.Container.get();

	// gets all supported post to targets

	var supported = osContainer.getMySpaceEnvironment().getSupportedPostToTargets();

    var target = 'COMMENTS';

	var profileDetails;

	var params = {};

	var viewer_id;

	var owner_id;



		//setting the canvas height to 1800
		//container.adjustHeight(1800);

var appID=opensocial.getEnvironment().currentApplication.getId();

document.getElementById('tryagainlink').href='http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId='+appID;



	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;

	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT; 

	params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;

	

/*----------------------------------------------------------------- Invite Friends code start */

        // Functions to read, create and delete cookie



        function createCookie(name,value,days) {

	if (days) {

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	}

	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";

         }



        function readCookie(name) {

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	return null;

        }



        function eraseCookie(name) {

	      createCookie(name,"",-1);

        }

        // Functions to read, create and delete cookie end



         // Calling this function when user click on invite button 

         function setflag()

         {	

	      createCookie('invitecookie','testcookie',7);	

          }



         // Disable popup box

          function setflag2()

          {	

	        document.getElementById('invitemsg').style.display = "none";	

        	

           }



          function remind() 

         {

	       //this function shows division of msg box to tell user that invite your friends	

	

                //document.getElementById('invitemsg').style.display='block';



          }	

                function invitefriendinit(){

                // read cookie to check if cookie is set or not 

                var x = readCookie('invitecookie');

                if (x) {
					//if invitecookie flag set dont show msgbox 
                }
                else
                {
					// cookie not set so, display msgbox to invite friends to add this application.. 
					//first check if user standing on chat application so, show msg firsttime after 2 minutes..
					//setTimeout('remind()', 2*60*1000);
                }         
			   //cookie checking complete

            }





//Make Post Request to store referral details into the database..

function makePOSTRequest(fid) {

  var params = {};

  var postdata = {

    viewerid : viewer_id,

    referred_id : fid

  };

  params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;

  params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);

  var url =  base_url + 'myspace_referal.php';

document.getElementById('itest').innerHTML = 'making request';

  gadgets.io.makeRequest(url, response2, params);

};



function response2(obj) {

document.getElementById('itest').innerHTML = 'response called';

if(obj == null)

{

   document.getElementById('itest').innerHTML = 'response is null';

}

else

{

     document.getElementById('itest').innerHTML = obj.text+' testing data';
	 //document.write(obj.text);

}

};



//Make Post Request end..



/*------------------------------------------------------------------------------Invite Friends code end */



         function init()

	{

		
		var os = opensocial.Container.get()
		var req = os.newDataRequest();

	    profileDetails = [MyOpenSpace.Person.Field.ID, MyOpenSpace.Person.Field.THUMBNAIL_URL, MyOpenSpace.Person.Field.PROFILE_URL]; 

		start=1;

		end=40;

		for(i=0;i<totalGroups;i++)

		{

			group(req,start,end,vF[i]);	

			start+=40;	

			end+=40;	

		}

		

		req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

		req.add(req.newFetchPersonRequest('OWNER'), 'owner');

		req.send(viewerResponse);



                invitefriendinit(); // initializing the function to invite friends..

	}



       





	function group(os,start,end,gname) 

	{

		var allFriends = {};

		allFriends[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = profileDetails;

		allFriends[opensocial.DataRequest.PeopleRequestFields.FIRST] = start;   

		allFriends[opensocial.DataRequest.PeopleRequestFields.MAX] = end;
		
		var params = {};
		params[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
		params[opensocial.IdSpec.Field.NETWORK_DISTANCE] = 1;
		var idspec = opensocial.newIdSpec(params);
		//profileDetails = [MyOpenSpace.Person.Field.ID, MyOpenSpace.Person.Field.THUMBNAIL_URL, MyOpenSpace.Person.Field.PROFILE_URL]; 
		
		//os.add(os.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, allFriends), gname);
		os.add(os.newFetchPeopleRequest(idspec, allFriends), gname);

	}

	



	function viewerResponse(data) 

	{

		

		var viewer = data.get('viewer').getData();

		var owner = data.get('owner').getData();

		if(viewer)

		{

			document.getElementById('preload_bg').style.display='block';

			document.getElementById('preloading').style.display='block';

			
			/*
			for(i=0;i<totalGroups;i++)

			{

				vF[i] = data.get(vF[i]).getData();

			}
			*/
			

			var viewerName = viewer.getField(opensocial.Person.Field.NAME);

			var viewerdob = '';//viewer.getField(opensocial.Person.Field.DATE_OF_BIRTH);

			var viewergender = '';//viewerData.getField(opensocial.Person.Field.GENDER);

			

			var viewerPhoto = viewer.getField(opensocial.Person.Field.THUMBNAIL_URL);

			var viewerurl = viewer.getField(opensocial.Person.Field.PROFILE_URL);

			

			viewer_id=viewer.getField(opensocial.Person.Field.ID);

			owner_id= owner.getField(opensocial.Person.Field.ID);

			

			//allfriendsComaseparated();//+"&allfriends="+allfriends

			
			var viewer_id_only = viewer_id.split(":");
			post_data="index.php?viewer_id="+viewer_id_only[1]+"&viewername="+viewerName+"&photo="+viewerPhoto+"&url="+viewerurl+"&allfriends="+allfriends+"&owner_id="+owner_id+"&sessionKey=" + randomNum;	

				

			

			var server_url=base_url+post_data;

			document.getElementById('content').style.display='none';

			document.getElementById('frame').src= server_url;

			document.getElementById('preload_bg').style.display='none';

			document.getElementById('preloading').style.display='none';

			//populatePage('test_load_new_page.php',"?viewer_id="+viewer_id+"&viewername="+viewerName+"&photo="+viewerPhoto+"&url="+viewerurl+"&allfriends="+allfriends+"&owner_id="+owner_id,'');

			//gadgets.io.makeRequest(server_url, pageloadCallback, params);

		}

		else

		{

			document.getElementById('content').style.display='none';

			var server_url=base_url+"index.php?id="+viewer_id;

			document.getElementById('frame').src= server_url;

			document.getElementById('preload_bg').style.display='none';

			document.getElementById('preloading').style.display='none';

			//var server_url=base_url+'addapp.php';

			//gadgets.io.makeRequest(server_url, pageloadCallback, params);

		}

	}

	

	function allfriendsComaseparated()

	{

		for(i=0;i<totalGroups;i++)

		{

			comaseperatepopulate(vF[i]);

		}

	}

	

	function comaseperatepopulate(vF)

	{

		vF.each(function(vF) 

				{

					allfriends = allfriends + vF.getField(opensocial.Person.Field.ID) + ',';

				} 

			);

	}



	

	function populatePage(pagename,querystring,app_friend)

	{

		document.getElementById('preload_bg').style.display='block';

		document.getElementById('preloading').style.display='block';

		if(app_friend == 1)

		{

			if(querystring == 'undefined' || querystring == '')

				querystring = '?allfriends='+allfriends;

			else	

				querystring = querystring + '&allfriends='+allfriends;

		}

		if(querystring != 'undefined' && querystring != '')

			var server_url=base_url+pagename+querystring+'&viewerID='+viewer_id;

		else

			var server_url=base_url+pagename+'?viewerID='+viewer_id;

		gadgets.io.makeRequest(server_url, pageResponse, params);

	}



	function pageResponse(response,url,error)

	{

		if(error)

		{

			var server_url=base_url+"index.php?id="+viewer_id;

			document.getElementById('frame').src= server_url;

			document.getElementById('preload_bg').style.display='none';

			document.getElementById('preloading').style.display='none';

			document.getElementById('content').style.display='none';

			//var server_url=base_url+'addapp.php';

			//gadgets.io.makeRequest(server_url, pageloadCallback, params);

		}

		else

		{

			document.getElementById('frame').src= '';

			document.getElementById('content').style.display='block';

			

			document.getElementById('content').innerHTML = response.text;

			

			document.getElementById('preload_bg').style.display='none';

			document.getElementById('preloading').style.display='none';

			gadgets.window.adjustHeight();

		}

	}

function pageloadCallback(response,url,error) 

{              

 	if(error)

	{

		var server_url=base_url+"index.php?id="+viewer_id;

		document.getElementById('frame').src= server_url;

		document.getElementById('preload_bg').style.display='none';

		document.getElementById('preloading').style.display='none';

	}

	else

	{

	document.getElementById('frame').src= '';

	document.getElementById('content').style.display='block';

	document.getElementById('content').innerHTML = response.text;

	document.getElementById('preload_bg').style.display='none';

	document.getElementById('preloading').style.display='none';

	}

}

function sendFriendsComments()

{

	target = 'COMMENTS';

	document.getElementById('preload_bg').style.display='block';

	document.getElementById('preloading').style.display='block';

	post_data="invite_myspace.php?viewerID="+viewer_id;	

	var server_url=base_url+post_data;

	gadgets.io.makeRequest(server_url, pageloadCallback2, params);

	

}



function sendBulletin()

{

	target = 'BULLETINS';

	document.getElementById('preload_bg').style.display='block';

	document.getElementById('preloading').style.display='block';

	post_data="invite_myspace.php?viewerID="+viewer_id;	

	var server_url=base_url+post_data;

	gadgets.io.makeRequest(server_url, pageloadCallback2, params);

	

}





function sendMessage()

{

	target = 'SEND_MESSAGE';

	document.getElementById('preload_bg').style.display='block';

	document.getElementById('preloading').style.display='block';

	post_data="invite_myspace.php?viewerID="+viewer_id;	

	var server_url=base_url+post_data;

	gadgets.io.makeRequest(server_url, pageloadCallback2, params);

}





function populatefriends()

{

	target = 'SHARE_APP';

	document.getElementById('preload_bg').style.display='block';

	document.getElementById('preloading').style.display='block';

	post_data="invite_myspace.php?viewerID="+viewer_id;	

	var server_url=base_url+post_data;

	gadgets.io.makeRequest(server_url, pageloadCallback2, params);

	document.getElementById('invitemsg').style.display='none';

}

function pageloadCallback2(response,url,error) 

{

 		document.getElementById('frame').src= '';

		document.getElementById('content').style.display = 'block';

		document.getElementById('content').innerHTML = response.text;

		html = '';

		for(i=0;i<totalGroups;i++)

		{

			makeHTML(vF[i]);

		}

		document.getElementById('friends').innerHTML = html;

		document.getElementById('preload_bg').style.display = 'none';

		document.getElementById('preloading').style.display = 'none';

  }







function makeHTML(vF)

{

		var i=0;

		vF.each(function(vF) 

		{

		var friendID = vF.getField(opensocial.Person.Field.ID);

		friends[i] =friendID; 

		var friendThumb = vF.getField(opensocial.Person.Field.THUMBNAIL_URL);

		var profile = vF.getField(opensocial.Person.Field.PROFILE_URL);		

		var friendName = vF.getDisplayName();

				html+='<input class="inputcheckbox" name="checkbox_'+friendID+'" value="'+friendID+'" type="checkbox">';

				html+='<li userid="'+friendID+'"><a onClick="selectnode(this.parentNode); return false;" href="#">';

				html+='<span style="background-image: url('+friendThumb+');" class="square">';

		

			html+='<span></span></span><strong>'+friendName+'</strong></a></li>'; 

			total_friends++;

		i++;

		}

		

    );

}



function array_merge(arr) 

{

	var merged = arr;

	for (var i = 1; i < arguments.length; i++)

	{

		merged = merged.concat(arguments[i]);

	}

	return merged;

}



function invokePostTo(content)

{

   var j=0;

   kk=0;

   myrecipients = [];

   globalContent=content;

 			for (var i = 0; i < document.inviteform2.elements.length; i++) 

			{

				var e = document.inviteform2.elements[i];

				if ((e.disabled == false) && (e.name != 'allbox') && (e.type == 'checkbox')) 

				{

					if(e.checked == true)

					{

						for(x=0;x<totalGroups;x++)

						{

							if(vF[x].getById(e.value)!=null){

								myrecipients[j]=vF[x].getById(e.value);

								break;

								}

						}	

						j++;

					}

				}

			}

			if(myrecipients.length >= kk && myrecipients[kk]!="" && myrecipients.length!=0){

				sendComments(globalContent,myrecipients[kk]);

			}		

			else

			{

					alert("Please Select friend(s) first");

			}



}	  

function sendComments(content,recipients)

{

      var target_is_supported = false;

      for (var i = 0; i < supported.length; i++) 

	  {

            if (supported[ i ] == target)

			{

			   target_is_supported = true;

                  break;

            }

      }

	if (target_is_supported)

	{

	   var message = opensocial.newMessage(content);

		message.setField(opensocial.Message.Field.TITLE, 'From Exmafia');

		message.setField(opensocial.Message.Field.TYPE, target);

		osContainer.postTo(os_token, message, recipients, ptCallback);

	}

} 





function ptCallback(someVal)

{

    /*

	if (someVal == MyOpenSpace.PostTo.Result.ERROR) 

	{

      alert('callback gave error')

    }

    else */

	if (someVal == MyOpenSpace.PostTo.Result.CANCELLED) 

	{

		kk++;

		if(myrecipients.length!=kk){

			if(myrecipients.length>=kk && myrecipients[kk]!="")

			{

			sendComments(globalContent,myrecipients[kk]);

			}

		} 

	}

    else if (someVal == MyOpenSpace.PostTo.Result.SUCCESS)

	{

                   //calling makePOSTRequest with friend id to store invites details into our database..

                   //makePOSTRequest(myrecipients[kk].getField(opensocial.Person.Field.ID));

                   



	//alert(myrecipients[kk].getField(opensocial.Person.Field.ID));

		deselectnode(myrecipients[kk].getField(opensocial.Person.Field.ID));

		kk++;

		if(myrecipients.length!=kk)

		{

			if(myrecipients.length>=kk && myrecipients[kk]!="")

			{

			sendComments(globalContent,myrecipients[kk]);

			}

		}

                 

                  //Set Invite Cookie...... 

                  setCookie();   
				  //makePOSTRequest();



         

         } 

	else 

	{

		kk++;

		if(myrecipients.length!=kk)

		{

			if(myrecipients.length>=kk && myrecipients[kk]!="")

			{

			sendComments(globalContent,myrecipients[kk]);

			}

		}

               //Set Invite Cookie...... 

              setflag();   



      }               

}

 







//================================================================================================= 



//===================  INVITE FRIENDS CODE  =======================================================

//=================================================================================================

function selectnode(parnode)

{

 

	var a='checkbox_'+parnode.getAttribute('userid');

	eval('document.inviteform2.'+a+'.checked=!document.inviteform2.'+a+'.checked;');

	eval('if(document.inviteform2.'+a+'.checked){	parnode.className = "selected";}	else {parnode.className = "";	}	');

	document.getElementById('max_limit_notice').style.color='#000000';

	eval('	if(document.inviteform2.'+a+'.checked){	document.getElementById(\'numselect\').value=parseInt(document.getElementById(\'numselect\').value)+1;}	else {document.getElementById(\'numselect\').value=parseInt(document.getElementById(\'numselect\').value)-1;	}	');

	eval('document.getElementById(\'max_limit_notice\').innerHTML=\'Selected (\'+ document.getElementById(\'numselect\').value+\')\'');

}



//==================================================================================================

	function togglechecked()

	{

	  for (var i = 0; i < document.inviteform2.elements.length; i++)

	  {

		var e = document.inviteform2.elements[i];

		if ((e.disabled == false) && (e.name != 'allbox') && (e.type == 'checkbox'))

		{

		e.checked = document.inviteform2.allbox.checked;

		}

	  }

	}



	function toggleselect()

	{

		document.inviteform2.allbox.checked = !document.inviteform2.allbox.checked;

		togglechecked();

	}

	

 function deselectnode(fid)

 {

	//document.getElementById('friends').firstChild.style.display='block';

	var i;

	var ullia = document.getElementById('friends');

	var anodes = ullia.getElementsByTagName('li');

	for(i=0;i<anodes.length;i++){

		if(anodes[i].className=='selected' && (anodes[i].getAttribute('userid')==fid))

		{

 			anodes[i].className='';

		}

 	}

 	var anodes = ullia.getElementsByTagName('input');

	for(i=0;i<anodes.length;i++)

	{

 		if(anodes[i].className=='inputcheckbox' && (anodes[i].getAttribute('userid')==fid))

		{

 			anodes[i].checked=false;

		}

	}

	document.getElementById('max_limit_notice').style.color='#000000';

	document.getElementById('numselect').value=parseInt(document.getElementById('numselect').value)-1;

	document.getElementById('max_limit_notice').innerHTML='Selected ('+ document.getElementById('numselect').value+')';	

 }

	

	

 function unselectnode()

 {

	//document.getElementById('friends').firstChild.style.display='block';

	var i;

	var ullia = document.getElementById('friends');

	var anodes = ullia.getElementsByTagName('li');

	for(i=0;i<anodes.length;i++){

		if(anodes[i].className=='selected')

		{

 			anodes[i].className='';

		}

 	}

 	var anodes = ullia.getElementsByTagName('input');



	for(i=0;i<anodes.length;i++){

 		if(anodes[i].className=='inputcheckbox')

		{

 			anodes[i].checked=false;

		}

	}

	document.getElementById('max_limit_notice').style.color='#000000';

  	document.getElementById('numselect').value=0;

  	document.getElementById('max_limit_notice').innerHTML='Selected (0)';

}

//==================================================================================================



function selectallnode()

{

	var i;

	var ullia = document.getElementById('friends');

	var anodes = ullia.getElementsByTagName('li');



	for(i=0;i<anodes.length;i++)

	{

 		anodes[i].className='selected';

	}



	var anodes = ullia.getElementsByTagName('input');

 	for(i=0;i<anodes.length;i++){

 		if(anodes[i].className=='inputcheckbox')

		{

 			anodes[i].checked=true;

		}

  	}

	document.getElementById('max_limit_notice').style.color='#000000';

  	document.getElementById('numselect').value=anodes.length;

  	document.getElementById('max_limit_notice').innerHTML='Selected ('+anodes.length+')';

}	

//==================================================================================================

function URLEncode(normalurl)

{

	// The Javascript escape and unescape functions do not correspond

	// with what browsers actually do...

	var SAFECHARS = "0123456789" +					// Numeric

					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic

					"abcdefghijklmnopqrstuvwxyz" +

					"-_.!~*'$()";					// RFC2396 Mark characters

	var HEX = "0123456789ABCDEF";



	var plaintext = normalurl;

	var encoded = "";

	for (var i = 0; i < plaintext.length; i++ )

	{

		var ch = plaintext.charAt(i);

	    if (ch == " ")

		{

		    encoded += "+";				// x-www-urlencoded, rather than %20

		}

		else if (SAFECHARS.indexOf(ch) != -1)

		{

		    encoded += ch;

		}

		else 

		{

		    var charCode = ch.charCodeAt(0);

			if (charCode > 255) 

			{

			 /*   alert( "Unicode Character '" 

							+ ch 

							+ "' cannot be encoded using standard URL encoding.\n" +

				          "(URL encoding only supports 8-bit characters.)\n" +

						  "A space (+) will be substituted." );*/

				encoded += "+";

			} 

			else 

			{

				encoded += "%";

				encoded += HEX.charAt((charCode >> 4) & 0xF);

				encoded += HEX.charAt(charCode & 0xF);

			}

		}

	} // for

	return encoded;

};





function userauthenticate() 

{

	var os = opensocial.Container.get();

	var dataReqObj = os.newDataRequest();

	//var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER);
	
	var viewerReq = os.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER);
	

	dataReqObj.add(viewerReq);

	dataReqObj.send(dataLoadCallback);

}  





switch (parseInt(appID))

{

    case 116267: { base_url="http://myspace.decayofcamelot.com/";	break ;}

    case 117633: { base_url="http://myspace.exmafia.com/"; break ;}

    case 118562: { base_url="http://myag3nts.exmafia.com/"; break ;}

    case 119434: { base_url="http://myspace.war2072.com/"; break ;}

    case 121237: { base_url="http://myspace.jailhouselife.com/"; break ;}

    case 122542: { base_url="http://myspace.rebelseas.com/"; break ;}

    case 123959: { base_url="http://mydev.exmafia.com/"; break ;}

    case 125289: { base_url="http://mydev2.exmafia.com/"; break ;}

    case 129631: { base_url="http://myspaceny.exmafia.com/"; break ;}

    case 131230: { base_url="http://myguards.jailhouselife.com/"; break ;}

    case 132592: { base_url="http://mybite.fairgamers.com/"; break ;}

    case 132594: { base_url="http://mygulf.fairgamers.com/"; break ;}

    case 136053: { base_url="http://mydarkages.fairgamers.com/"; break;}

	case 140640: { base_url="http://colonize.fairgamers.com/"; break ;}

	case 160725: { base_url="http://myspace.mercenary.fairgamers.com/"; break ;}

	case 160708: { base_url="http://myspace.wildwest.fairgamers.com/"; break ;}

	case 160705: { base_url="http://myspace.bikers.fairgamers.com/"; break ;}

	case 160727: { base_url="http://myspace.urban.fairgamers.com/"; break ;}

	case 189981: { base_url="http://my.devold.exmafia.com/"; break ;}
}







var serverURL= base_url+'auth.php';

var viewerID;

var randomNum;

randomNum = Math.random();

serverURL = serverURL + "?sessionKey=" + randomNum;



function homeBtn(){

	userauthenticate();

	init();      

}



function dataLoadCallback(dataResponse)

 {		

		//var viewerData = dataResponse.get(opensocial.DataRequest.PersonId.VIEWER).getData();	
		var viewerData = dataResponse.get(MyOpenSpace.RequestType.FETCH_PERSON).getData();	

		viewerID = viewerData.getField(opensocial.Person.Field.ID);		

	    var params = {};
		var ospace = opensocial;
		var myospace = MyOpenSpace.RequestParameters;
		var gad = gadgets;
	    //params[opensocial.ContentRequestParameters.METHOD] = opensocial.ContentRequestParameters.MethodType.GET;
		//params[opensocial.ContentRequestParameters.CONTENT_TYPE] = opensocial.ContentRequestParameters.ContentType.HTML;
	    //params[opensocial.ContentRequestParameters.AUTHENTICATION] = opensocial.ContentRequestParameters.AuthenticationType.SIGNED;
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
		params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
	    
	    gadgets.io.makeRequest(serverURL, loadiframe, params);

		//change to your user page and domain

	function loadiframe(response) 

	{

	//here if wanted but needed due to my crappy js skills	

	init();   

	}

}





userauthenticate();

//============================================================================ authentication code end

init();

//============================================================================ v0.8 invite friends code ===================================================================

var stepSize = 40;
var pageNumber = 1;
var totalFriends = 0;
var totalPages = 1;
function showGame()
{
document.getElementById('invitefrds').style.visibility = 'hidden';
document.getElementById('outer').style.visibility = 'hidden';
document.getElementById('game').style.visibility = 'visible';
//document.getElementById('popup').style.visibility = "hidden";
document.getElementById('invitemsg').style.display='none';
userauthenticate();
init();
}
function showfrds()
{
document.getElementById('invitefrds').style.visibility = 'visible';
document.getElementById('outer').style.visibility = 'visible';
document.getElementById('game').style.visibility = 'hidden';
//document.getElementById('popup').style.visibility = "hidden";
document.getElementById('invitemsg').style.display='none';
Game.init();
}
function next()
{
pageNumber++;
if(totalFriends != 0)
{
if(pageNumber == totalPages || (pageNumber+1) > totalPages)
{
	document.getElementById('next').disabled = "disabled";
}}
if(pageNumber > 1)
{
	document.getElementById('previous').disabled = "";
}
Game.init();
}
function previous()
{
pageNumber--;

if(pageNumber == 1)
{
	document.getElementById('previous').disabled = "disabled";
}
if(pageNumber < totalPages)
{
	document.getElementById('next').disabled = "";
}
Game.init();
}
var Game = {};
 Game.Friends = {};
 Game.Photos = {};
 
     function requestBasicViewer()
{
document.getElementById('spinner').innerHTML = 'Note: You need to add this app to invite your friend. <br />Please use the "Add App" link above to add the application. <br /><br />If you have already added the application and still see this error than please follow this steps: Go to Profile > My Apps from the top menu, locate the "Free Games 5 in 1" app then click on view app link below it then click on Invite Friends to invite your friends.   <br /><br />Please report a problem if you still face an issue. Thank you. Enjoy!';
}
    // the entry point for the app, fired from the onload handler.
    Game.init = function(){
 
		// check if the app is added
		Game.is_added = Game.isAdded();
 
        // create the opensocial.DataRequest object
        var request = opensocial.newDataRequest();
 
        if(Game.is_added){
			// show the relevant divs
			//document.getElementById("perms").style.display = "block";
			//document.getElementById("bulletin").style.display = "block";
			//document.getElementById("activity").style.display = "block";
			document.getElementById("friends_callout").style.display = "block";
			//document.getElementById("app_friends_callout").style.display = "block";
			document.getElementById("friends").style.display = "block";
			
			//getting total number of friends
			if(totalFriends == 0)
			{				
				Game.getTotalFriends();
			}
            
			// create the parameters for the idspec to send into the fetch app data request
            params = {};
            params[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
            params[opensocial.IdSpec.Field.NETWORK_DISTANCE] = 1;
 
            // create the idspec
            var idspec = opensocial.newIdSpec(params);
 
			params[opensocial.DataRequest.PeopleRequestFields.MAX] = stepSize;
			params[opensocial.DataRequest.PeopleRequestFields.FIRST] = stepSize * (pageNumber - 1) + 1;
			
            // add the fetch friend request to the queue
            request.add(request.newFetchPeopleRequest(idspec, params), "friends");
 
            // filter by users with the app
            //params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.HAS_APP;
 
            // add the fetch friends with the app request to the queue
            //request.add(request.newFetchPeopleRequest(idspec, params), "app_friends");
 
            // create the ID
            var id = opensocial.IdSpec.PersonId.VIEWER;
 
            // add the photos request to the queue
            request.add(MyOpenSpace.DataRequest.newFetchPhotosRequest(id), "photos");
        }
        else{
            // if the app isn't added, just get the basic viewer
            Game.requestBasicViewer();
            return;
        }
 
        // start executing the request, call back into got_init when done
        request.send(Game.got_init);
    }
 
    Game.Friends.friends = {};
    Game.Friends.app_friends = {};
 
    // the callback function for the initial data requests, 'response' is the opensocial.DataResponse object.
    Game.got_init = function(response){
		
        // create flags to use so we don't try to parse a response that had an error.
        var parse_friends = true;
        //var parse_app_friends = true;
        var parse_viewer = true;
        var parse_photos = true;
 
        // first check if an error occurred.
        if(!response){
            parse_friends = false;
            //parse_app_friends = false;
            parse_viewer = false;
            parse_photos = false;
        }
        else if(response.hadError()){
            var friends = response.get("friends");
            //var app_friends = response.get("app_friends");
            var viewer = response.get("viewer");
            var photos = response.get("photos");
 
            // create a locally scoped function to handle checking for errors
            var checkForError = function(ri){
                if(!ri){
                    return false;
                }
                else if(ri.hadError()){
                    if(ri.getErrorCode() === opensocial.ResponseItem.Error.INTERNAL_ERROR){
                        // retry the request?
                    }
                    return false;
                }
                return true;
            }
 
            parse_friends = checkForError(friends);
            //parse_app_friends = checkForError(app_friends);
            parse_viewer = checkForError(viewer);
            parse_photos = checkForError(photos);
        }
        else{
            if(!response.get("friends")) parse_friends = false;
            //if(!response.get("app_friends")) parse_app_friends = false;
            if(!response.get("viewer")) parse_viewer = false;
            if(!response.get("photos")) parse_photos = false;
        }
 
        if(parse_friends){
            Game.Friends.friends.array = response.get("friends").getData().asArray();
            Game.Friends.drawFriends(Game.Friends.friends.array, "friends");
        }
		/*
        if(parse_app_friends){
            Game.Friends.app_friends.array = response.get("app_friends").getData().asArray();
            Game.Friends.drawFriends(Game.Friends.app_friends.array, "app_friends");
        }
		*/
		
        var viewer;        
        if(parse_viewer){
            viewer = response.get("viewer").getData();
            document.getElementById("friends").style.display = "none";
        }
 
        if(parse_photos){
            photos = response.get("photos").getData().asArray();
 
            Game.Photos.drawPhotos(photos);
        }
 
        Game.setPermsDiv(viewer);
 
        // hide the spinner and show the content now that the DOM has been populated.
        document.getElementById("spinner").style.display = "none";
        document.getElementById("content").style.display = "block";
 
        // make the iframe fit the new content.
        gadgets.window.adjustHeight();
    }
	
	Game.getTotalFriends = function()
	{
		var mos = opensocial.Container.get();
		var dr = mos.newDataRequest();
		var params = {}; // No params
		// create the parameters for the idspec to send into the fetch app data request
            params1 = {};
            params1[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
            params1[opensocial.IdSpec.Field.NETWORK_DISTANCE] = 1;
 
            // create the idspec
            var idspec = opensocial.newIdSpec(params1);
		dr.add(mos.newFetchPeopleRequest( idspec, params), 'friends');
		
		//document.getElementById('next').disabled = "disabled";
		
		dr.send(responseHandler);
	}
	function responseHandler(response) {
		document.getElementById('next').disabled = "";
		temp = response.get('friends');
	  totalFriends = temp.getData().getTotalSize();
	  totalPages = totalFriends/stepSize;
		if(totalFriends%stepSize != 0) {totalPages++;}
		
	  // Or like this:
	  //var friendData = response.get('friends').getData();
	  //var friendTotalCount = friendData.getTotalSize();
	  //...
	}
 
    // the global app is added flag
    Game.is_added = null;
 
    // return true if the app is added
    // false otherwise
    Game.isAdded = function(){
        // the first time around the flag is null, so use the
        // parameters to determine install state
        if(null === Game.is_added){
            return ("1" === gadgets.views.getParams().installState + "");
        }
 
        // otherwise the flag was set directly, just return that
        else{
            return Game.is_added;
        }
    }
 
    Game.requestBasicViewer = function(){
        // create the opensocial.DataRequest object.
        var request = opensocial.newDataRequest();
 
        // specify the viewer
        var id = opensocial.IdSpec.PersonId.VIEWER;
 
        // add the basic viewer request to the queue
        request.add(request.newFetchPersonRequest(id), "viewer");
 
        // start executing the request, call back into got_init when done.
        request.send(Game.got_init);
    }
 
	// generate the markup for how to show permissions
	// based off of the user having added the app
	// and what permissions they already have set
	Game.setPermsDiv = function(viewer){
		var inner = "";
		//var perms = document.getElementById("perms");
 
		// first check if the app is added
		if(!Game.is_added){
		    if(!viewer.hadError()){
			    var viewer_name = (viewer) ? " " + viewer.getDisplayName() : "";
 
			    // it's not added so no permissions have yet been set
			    // show both permissions, if these are clicked the add
			    // app modal will show first
			    inner = 'Welcome to the Game';
			    inner += viewer_name;
			    inner += '!<br />Check out the app by allowing access ';
			    inner += 'to some of your photos: ';
			    inner += '<button onclick="reqPublic();">';
			    inner += 'Public Photos</button> ';
			    inner += '<button onclick="reqPrivate();">';
			    inner += 'Private Photos</button>';
 
            }
			else{
			    inner = "Oops, it looks like Open Canvas isn't switched on right now,<br />";
			    inner += "or some other error occurred, check back later or install the app."
			}
 
		    // hide the bulletin and activity buttons as
		    // requestSendMessage and requestCreateActivity won't
		    // work when the user hasn't added the app
		    document.getElementById("bulletin").style.display = "none";
		    document.getElementById("activity_divider").style.display = "none";
		    document.getElementById("activity").style.display = "none";
		    document.getElementById("friends").style.display = "none";
		}
		else{
 
			// permission object for public videos and photos
			var pub = MyOpenSpace.Permission.VIEWER_ACCESS_TO_PUBLIC_VIDEOS_PHOTOS;
 
			// permission object for private videos and photos
			var pri = MyOpenSpace.Permission.VIEWER_ACCESS_TO_PRIVATE_VIDEOS_PHOTOS;
 
			// check if both permissions are already granted
			if(opensocial.hasPermission(pub) &&
							opensocial.hasPermission(pri)){
				// if so, no need to display any permission buttons
				//perms.style.display = "none";
			}
			else{
				inner += "No access to photos? You can try: ";
 
				// add the public photo permission button if necessary
				if(!opensocial.hasPermission(pub)){
					inner += "<button onclick='reqPublic();'>";
					inner += "Public Photos</button> ";
				}
 
				// add the private photo permission button if necessary
				if(!opensocial.hasPermission(pri)){
					inner += "<button onclick='reqPrivate();'>";
					inner += "Private Photos</button>";
				}
			}
		}
 
		//perms.innerHTML = inner;
	}
 
    // global variable used to hold the ID of the clicked users
    Game.Friends.friend_clicked = [];
    Game.Friends.app_friend_clicked = [];
 
    // wrapper for requestShareApp
    Game.Friends.friendClicked = function(id, type){
        var friends_array;
 
        switch (type){
            case "friends":
                friends_array = Game.Friends.friend_clicked;
                break;
            case "app_friends":
                friends_array = Game.Friends.app_friend_clicked;
                break;
        }
 
        // look for duplicates
        for(var i = 0; i < friends_array.length; i++){
            if(friends_array[i] === id){
                // duplicate found, remove it from the list and reset the background
                document.getElementById(type + "_" + id).style.backgroundColor = "white";
                friends_array.splice(i, 1);
                return;
            }
        }
 
        // not a duplicate, add the id to the list
        document.getElementById(type + "_" + id).style.backgroundColor = "yellow";
        friends_array.push(id);
    }
 
    // wrap opensocial.requestShareApp
    Game.multipleRSAWrapper = function(){
        // create the rSA message
        //var body = "Hey [recipient]! [sender] wants you to ";
        //body += "add [app]. It's way awesome!";
        //var title = "A great fun game!";
		
		var body = msg_body;
		var title = msg_subject;
		
 
        var params = {};
        params[opensocial.Message.Field.TITLE] = title;
 
        // create an opensocial.Message object
        var reason = opensocial.newMessage(body, params);
 
        // initiate requestShareApp
        opensocial.requestShareApp(Game.Friends.friend_clicked, reason, Game.rsaCallback);
		
		//Set Cookie for Invitefriends....
		//setCookie();
		setflag();
		makePOSTRequest(Game.Friends.friend_clicked);
    }
 
    Game.notiPermCB = function(){
        // re-check perms
        // or does the response contain the new perms?
        if(opensocial.hasPermission(MyOpenSpace.Permission.VIEWER_SEND_NOTIFICATIONS)){
            Game.multipleNotificationWrapper();
        }
    }
 
    // wrap requestCreateNotification
    Game.multipleNotificationWrapper = function(){
        if(!opensocial.hasPermission(MyOpenSpace.Permission.VIEWER_SEND_NOTIFICATIONS)){
            opensocial.requestPermission([MyOpenSpace.Permission.VIEWER_SEND_NOTIFICATIONS], "In order to update you on Profile Deluxe.", notiPermCB);
            return;
        }
 
        var body = "Hi ${recipient}, here's a notification from <a href='${canvasUrl}'>Profile Deluxe</a>";
        var url1 = MyOpenSpace.NotificationButton.UrlTypes.CANVAS;
        var url2 = MyOpenSpace.NotificationButton.UrlTypes.APP_PROFILE;
        var params1 = { "k1" : "v1", "k2" : "v2" };
        var text1 = "GOTO Canvas";
        var text2 = "GOTO Profile";
 
        var button1 = MyOpenSpace.newNotificationButton(url1, text1, params1);
        var button2 = MyOpenSpace.newNotificationButton(url2, text2);
 
        var param = {};
 
        param[MyOpenSpace.Notification.Field.BODY] = body;
        param[MyOpenSpace.Notification.Field.BUTTONS] = [button1, button2];
 
        var mediaItemArray = [];
        mediaItemArray.push(opensocial.newMediaItem("", MyOpenSpace.MediaItemHelper.PROFILE_PICTURE));
        param[MyOpenSpace.Notification.Field.MEDIA_ITEMS] = mediaItemArray;
 
        var notification = MyOpenSpace.newNotification(param);
 
        MyOpenSpace.requestCreateNotification(Game.Friends.app_friend_clicked, notification, Game.rcnCallback);
    }
 
    Game.rcnCallback = function(response){
        if(response.hadError()){
            document.getElementById("notificationMessage").innerHTML = "Boo, there was an error!";
        }
        else{
            document.getElementById("notificationMessage").innerHTML = "Yay, notification sent!";
        }
 
        for(var i = 0; i < Game.Friends.app_friend_clicked.length; i++){
            document.getElementById("app_friends_" + Game.Friends.app_friend_clicked[i]).style.backgroundColor = "white";
        }
 
        Game.Friends.app_friend_clicked = [];
    }
 
    // global variable used to hold the IDs of the clicked photos
    Game.Photos.photos_clicked = [];
 
    Game.Photos.photoClicked = function(id){
 
        // locate the particular clicked photo
        var photo = document.getElementById("photo_" + id);
 
        // figure out if the photo is currently clicked
        // or not by iterating through the photos_clicked
        // array, save the index if found
        var photo_exists = -1;
        for(var i = 0; i < photos_clicked.length; i++){
            if(photos_clicked[i] === id){
                photo_exists = i;
                break;
            }
        }
 
        // the photo was already clicked
        if(photo_exists >= 0){
 
            // remove the photo from the list
            photos_clicked.splice(i, 1);
 
            // set the background to white
            photo.style.backgroundColor = "white";
        }
 
        // the photo wasn't clicked
        else{
 
            // a maximum of 3 photos are allowed
            // so take no action if 3 are already
            // clicked
            if(photos_clicked.length > 2) return;
 
            // add the photo to the array
            photos_clicked.push(id);
 
            // set the photo's background to yellow
            photo.style.backgroundColor = "yellow";
        }
    }
 
    Game.reqPublic = function(){
        var permissions = [MyOpenSpace.Permission.VIEWER_ACCESS_TO_PUBLIC_VIDEOS_PHOTOS];
        var reason = "This is to allow the app to display your photos that are set to public on your home page.";
        opensocial.requestPermission(permissions, reason, Game.reqCallback);
    }
 
    Game.reqPrivate = function(){
        var permissions = [MyOpenSpace.Permission.VIEWER_ACCESS_TO_PRIVATE_VIDEOS_PHOTOS];
        var reason = "This is to allow the app to display your photos that are set to private on your home page.";
        opensocial.requestPermission(permissions, reason, Game.reqCallback);
    }
 
    // callback function for requestPermission
    Game.reqCallback = function(response){
 
        // if the app was previously not added, but is
        // now added, reload the app
        if(!Game.is_added && "1" === gadgets.views.getParams().installState + ""){
 
            // set the global flag
            Game.is_added = true;
 
            // restart the app
            init();
        }
    }
 
    // if id starts with 'myspace.com:' it
    // will be stripped out and the resulting
    // value returned, otherwise return
    // the id as-is
    Game.stripMySpaceDotCom = function(id){
        if(0 === id.indexOf("myspace.com:")){
            return id.substr("myspace.com:".length);
        }
        else{
            return id;
        }
    }
 
    Game.showActivity = function(){
        document.getElementById("activity").style.display = "none";
        document.getElementById("activity_block").style.display = "block";
        document.getElementById("activity_divider").style.display = "block";
 
        gadgets.window.adjustHeight();
    }
 
    // wrapper for requestCreateActivity
    Game.sendActivity = function(){
 
        // the date variable is of type Literal
        var date = (new Date()).toLocaleDateString();
 
        // the action variable is also a Literal
        var action = document.getElementById("activity_action").value;
 
        // the friend varaible is of type Person, so 
        // parse out the ID of the selected friend
        var friend = document.getElementById("activity_friend");
        friend = friend.options[friend.selectedIndex].value;
 
        // note that there is currently a bug here, the template
        // does not accept an ID in the format "myspace.com:12345"
        // so strip out the "myspace.com" part of the ID to leave
        // just "12345"
        friend = Game.stripMySpaceDotCom(friend);
 
        // create the parameters for the activity
        var params = {};
 
        // select the particular template here
        params[opensocial.Activity.Field.TITLE_ID] = "date_message";
 
        // use the variables from above to generate the values
        // for the template variables
        params[opensocial.Activity.Field.TEMPLATE_PARAMS] = 
            { "date" : date, "action" : action, "friend" : friend };
 
        // iterate through the clicked photos
        if(photos_clicked.length > 0){
 
            // if some photos were clicked create an array to
            // store opensocial.MediaItem objects for each
            // photo
            var mediaItemArray = [];
 
            var uri, mi, photo_div, div_id;
            for(var i = 0; i < photos_clicked.length; i++){
                div_id = "photo_" + photos_clicked[i];
                photo_div = document.getElementById(div_id);
 
                // media items URIs are required to be in the format
                // of valid MySpace API URIs, these are supplied by
                // the API, here they are saved to a custom
                // "uri" attribute
                uri = photo_div.attributes.uri.nodeValue;
 
                // create the opensocial.MediaItem object
                mi = opensocial.newMediaItem("image/jpeg", uri);
 
                // add it to the array
                mediaItemArray.push(mi);
            }
 
            // once done, add the array to the activity parameters
            params[opensocial.Activity.Field.MEDIA_ITEMS] = mediaItemArray;
        }
 
        // create the opensocial.Activity object
        var activity = opensocial.newActivity(params);
 
        // request the event be raised, passing in the activity,
        // a priority of HIGH, and specify a callback
        opensocial.requestCreateActivity(activity, 
            opensocial.CreateActivityPriority.HIGH, Game.activityCallback);
    }
 
    // handles the callback from requestCreateActivity
    Game.activityCallback = function(response){
 
        // first check if the activity had an error
        if(!response || response.hadError() || -1 === response.getData()){
            document.getElementById("activity_message").innerHTML = 
                "There was an error, please refresh the page and try again!";
        }
        else{
            if(1 === response.getData()){
                // the user clicked "publish"
            }
            else if(0 === response.getData()){
                // the user clicked "deny"
            }
 
            // otherwise, take some action, in this case
            // reset the photo state
            var photo;
            for(var i = 0; i < Game.Photos.photos_clicked.length; i++){
                photo = document.getElementById("photo_" + Game.Photos.photos_clicked[i]);
                photo.style.backgroundColor = "white";
            }
 
            Game.Photos.photos_clicked = [];
        }
    }
 
    // wrapper for requestSendMessage
    Game.sendBulletin = function(){
        // link to the app's canvas
        var app_canvas = "http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=118991";
 
        // link to the app's icon
        var img_src = "http://c3.ac-images.myspacecdn.com/images02/21/l_e2b0c1f6a7b249a2a50d9a57444c5f12.jpg";
 
        // create the message
        var body = "Try it out! A fun new way to view your profile! Click ";
        body += "<a href='" + app_canvas + "'>here</a> to try it out!<br />";
        body += "<center><img src='" + img_src + "' /></center>"
        var title = "A fun way to view your profile!";
 
        var params = {};
        params[opensocial.Message.Field.TITLE] = title;
 
        // specify a message type of bulletin
        params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.NOTIFICATION;
 
        var message = opensocial.newMessage(body, params);
 
        // initiate requestSendMessage
        opensocial.requestSendMessage(opensocial.IdSpec.PersonId.VIEWER, message, Game.bulletinCallback);
    }
 
    Game.bulletinCallback = function(response){
        if(response && !response.hadError()){
            if(1 === response.getData()){
                document.getElementById("bulletin").innerHTML = "Thanks!";
            }
        }
    }
 
    // callback for requestShareApp
    Game.rsaCallback = function(response){
        if(response && !response.hadError()){
 
            for(var i = 0; i < Game.Friends.friend_clicked.length; i++){
 
                // use the global friend_clicked variable to
                // grab the correct div from the DOM
                var friend = document.getElementById("friends_" + Game.Friends.friend_clicked[i]);
 
                if(friend){
 
                    // if "Send" was clicked the response data
                    // will be 1, otherwise a 0
                    if(1 === response.getData()){
 
                        // remove that friend from the list
                        if(friend.parentNode){
                            friend.parentNode.removeChild(friend);
                        }
                    }
                    else{
                        friend.style.backgroundColor = "red";
                    }
                }
            }
        }
 
        Game.Friends.friend_clicked = [];
    }
 
    Game.rntWrapper = function(view_name){
        var supported_views = gadgets.views.getSupportedViews();
 
        var view = null;
        for(var v in supported_views){
            if(view_name === supported_views[v].getName()){
                view = supported_views[v];
                break;
            }
        }
 
        if(null !== view){
            gadgets.views.requestNavigateTo(view);
        }
    }
 
    // parses the friends response and outputs it to the page
    Game.Friends.drawFriends = function(friends, friend_type){
        var friends_div, activity_friend = null;
        switch(friend_type){
            case "app_friends":
                document.getElementById("app_friends_callout").style.display = "block";
                friends_div = document.getElementById("app_friends");
                break;
            case "friends":
                document.getElementById("friends_callout").style.display = "block";
                friends_div = document.getElementById("friends");
                activity_friend = document.getElementById("activity_friend");
                break;
        }
 
        var clear_div = '<div class="clear"></div>';
        var friend_format = '<center><img src="{0}" /><div>{1}</div></center>';
 
        var container = document.createElement("div");
 
        var id, image, name;
        for(var i = 0; i < friends.length; i++){
            id = friends[i].getId();
            image = friends[i].getField(opensocial.Person.Field.THUMBNAIL_URL);
            name = friends[i].getDisplayName();
 
            if(!id || !image || !name) continue;
 
            var div = document.createElement("div");
            div.id = friend_type + "_" + id;
            div.className = "friend float";
            div.innerHTML = friend_format.replace("{0}", image).replace("{1}", name);
 
            if(div.atachEvent){
                div.attachEvent("onclick", "Game.Friends.friendClicked('" + id + "', '" + friend_type + "')");
            }
            else{
                div.setAttribute("onclick", "Game.Friends.friendClicked('" + id + "', '" + friend_type + "')");
            }
 
            container.appendChild(div);
 
            if(null !== activity_friend){
                var option = document.createElement("option");
                option.value = id;
                option.text = name;
                activity_friend.options.add(option);
            }
        }
		friends_div.innerHTML = "";
        friends_div.appendChild(container);
 
        if(friends.length > 0){
            friends_div.innerHTML += clear_div;
        }
    }
 
    // parses the photos response and outputs it to the page
    Game.Photos.drawPhotos = function(photos){
 
        // build up the required markup
        var clear_div = '<div class="clear"></div>';
        var photos_format = '<div id="photo_{0}" onclick="photoClicked';
        photos_format += '(\'{1}\');" class="friend float" uri="{2}">';
        photos_format += '<center><img src="{3}" />';
        photos_format += '<div>{4}</div></center></div>';
        //var photos_div = document.getElementById("photos");
 
        // iterate through each photo
        var id, src, uri, caption;
        for(var i = 0; i < photos.length; i++){
            id = photos[i].getField(MyOpenSpace.Photo.Field.PHOTO_ID);
            src = photos[i].getField(MyOpenSpace.Photo.Field.IMAGE_URI);
            uri = photos[i].getField(MyOpenSpace.Photo.Field.PHOTO_URI);
            caption = photos[i].getField(MyOpenSpace.Photo.Field.CAPTION);
 
            if(!id || !uri) continue;
 
            if(!caption) caption = "";
 
            var this_photo = photos_format;
            this_photo = this_photo.replace("{0}", id);
            this_photo = this_photo.replace("{1}", id);
            this_photo = this_photo.replace("{2}", uri);
            this_photo = this_photo.replace("{3}", src);
            this_photo = this_photo.replace("{4}", caption);
 
            //photos_div.innerHTML += this_photo;
        }
 
        // add the clearing div if necessary
        if(photos.length > 0){
            //photos_div.innerHTML += clear_div;
        }
    }
 
    // add the app's entry point to the onload handler, this will fire when the body has finished loading.
    //gadgets.util.registerOnLoadHandler(Game.init);