// JavaScript Document
	include('/Scripts/jquery-1.3.2.js');
	
	var jsReady = false;
	var jsMovieName = "VolcanoSolitaire";

	function InitGoogle() {
		
		//google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
		//google.friendconnect.container.initOpenSocialApi({
		//  site: '08413419022563927158',
		//  onload: function(securityToken) {  }
		//});
				
		var skin = {};
		skin['FONT_FAMILY'] = 'verdana,sans-serif';
		skin['BORDER_COLOR'] = '#000000';
		skin['ENDCAP_BG_COLOR'] = '#C00E1A';
		skin['ENDCAP_TEXT_COLOR'] = '#333333';
		skin['ENDCAP_LINK_COLOR'] = '#4A1408';
		skin['ALTERNATE_BG_COLOR'] = '#ffffff';
		skin['CONTENT_BG_COLOR'] = '#ffffff';
		skin['CONTENT_LINK_COLOR'] = '#4A1408';
		skin['CONTENT_TEXT_COLOR'] = '#333333';
		skin['CONTENT_SECONDARY_LINK_COLOR'] = '#4A1408';
		skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
		skin['CONTENT_HEADLINE_COLOR'] = '#333333';
		skin['ALIGNMENT'] = 'left';
		google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
		google.friendconnect.container.renderSignInGadget(
		 { id: 'div-6197953275682915539',
		   site: '08413419022563927158' },
		  skin);
		
	}

	 
	 function setMovieName( movieName ) {
		 jsMovieName = movieName;
	 }
	 
     function isReady() {
         return jsReady;
     }
     function pageInit() {
         jsReady = true;
		 jsMovieName = "VolcanoSolitaire";
     }
     function thisMovie() {
		 if( jsMovieName == "UNKNOWN" ) {
			 return null;
		 }
		 
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[jsMovieName];
         } else {
             return document[jsMovieName];
         }
		 
         //return document["VolcanoSolitaire"];
     }
     function sendToJavaScript(value) {
         $('#jsMessage').append("ActionScript says: " + value + "\n" );
		 $('#jsMessage').append('Package #' + what.selectedIndex );

     }

// STUFF FOR COMMUNICATING WITH GOOGLE FRIEND CONNECT
    function userNameRequest() {
	 	$('#jsMessage').append('userNameRequest | ');
		var req = opensocial.newDataRequest();
		req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
		
        req.send(setUserName);
	 	$('#jsMessage').append('Sending username request!');
    }

      function setUserName(dataResponse) {
	 	$('#jsMessage').append(' UserName received!');
		
        //var viewer = dataResponse.get('viewer').getData();
		var viewer = dataResponse.get('viewer').getData();
	 	$('#jsMessage').append(' viewer retrieved!');
		
		if( viewer == null ) {
			$('#jsMessage').append(' Username is NULL');
		}
		else {
			$('#jsMessage').append(' viewer=' + viewer);
			$('#jsMessage').append('! Username received ' + viewer.getDisplayName());
			$('#jsMessage').append('! thisMovie=' + thisMovie());
			try {
			thisMovie().SetUserName(viewer.getDisplayName());
			$('#jsMessage').append(' DISPLAY NAME CALLED');
			}
			catch( exception ) {
				$('#jsMessage').append(exception);
			}
		}
		/*
        var friends = dataResponse.get('get_friends').getData(); 
        var html = 'Friends of ' + owner.getDisplayName();
        html += ':<br><ul>';
        friends.each(function(person) {
          html += '<li>' + person.getDisplayName() + '</li>';
        });
        html += '</ul>';
        document.getElementById('message').innerHTML = html;
		*/
      };

	function initAllData() {
	  $('#jsMessage').append("Begin Init All Data | ");
	  var req = opensocial.newDataRequest();
	  req.add(req.newFetchPersonRequest("OWNER"), "owner_data");
	  req.send(onData);
	  $('#jsMessage').append("END Init All Data | ");
	};
	
	function onData(data) {
	  if (!data.get("owner_data").hadError()) {
		var owner_data = data.get("owner_data").getData();
		thisMovie().SetUserName(owner_data.getDisplayName());
		$('#jsMessage').append("Owner Name=" + owner_data.getDisplayName() + " | ");
	  }
	  else {
		$('#jsMessage').append("ERROR ON DATA!");
	  }
	};
