SDNA = SDNA || {};

SDNA.global.onAreaLoad();

//Setup our custom events
SDNA.Event.create('rate', 					PT.rate );
SDNA.Event.create('window.open', 		PT.window.open);
SDNA.Event.create('window.close', 		PT.window.close);
SDNA.Event.create('form.submitting', 	SDNA.forms.submitting );
SDNA.Event.create('form.submitted', 	SDNA.forms.submitted );
SDNA.Event.create('change_home', 		PT.changeHome );
SDNA.Event.create('activate_phone', 	PT.activatePhone);
SDNA.Event.create('ajax.error',			SDNA.ajax.error );
SDNA.Event.create('ajax.complete',		SDNA.ajax.complete );
SDNA.Event.create('edit_fp', 				PT.frontpage);


//Subscribe to home_changed to update home links
SDNA.Event.subscribe('home_changed', PT.changeHome.updateHome );

//Subscribe to home_changed to update the check in back at home links
SDNA.Event.subscribe('home_changed', PT.changeHome.updateCheckinHome );

//bind dom to follow handlers
PT.follow.bind();

//bind dom to checkin handlers
PT.checkin.bind();

//bind dom for ratings handlers
PT.rate.bind();

//bind dom for sharing (comments, photos, etc)
PT.share.bind();

//bind person menus
PT.user.bind();	

//bind dom for rvsp (yes, no, maybe)
PT.rsvp.bind();

//bind dom for invites
PT.invite.bind();

//bind form actions
SDNA.forms.bind();

//bind dom for changing home handlers
PT.changeHome.bind();

//bind phone activation dialog
PT.activatePhone.bind();

//bind fsm dialog
PT.fsm.bind();

// bind entity handling
PT.entity.bind();

//bind frontpage dialog
PT.frontpage.bind();

//bind ajax error handling
SDNA.ajax.error.bind();
SDNA.ajax.complete.bind();

//setup photo zooming
SDNA.photos.bind();	

//bind more/less toggles
SDNA.global.bind();

if (typeof PT.activityHub !== "undefined") {
    PT.activityHub.bind();
}

$j().ready(function() {
  // popup Set Home Location form if the user has not *manually* set their home location
  if ( SDNA.user.logged_in === true && !SDNA.user.home_location_set ) {
	  
	  Window.pop(
	  		'/ajax/User/HomeLocation.htm'
	  		,
	  		{
	  			modal:true,
	  			addClose: false,
	  			close : function () {
	  		        // on close make sure the user doesn't see this popup again
        	  		$j.get('/ajax/User/HomeLocationOptOut.jsn');
                    SDNA.user.home_location_set = 1;
	  		    }
	  		}		
	  );
  }
});