Pervasive Computing promotes an environment that blurs the distinction between digital and physical devices and integrates all entities in a physical space into a cohesive programmable unit. Some of the early research activities in pervasive computing focused on developing infrastructures for pervasive applications. These infrastructures successfully merged physical and digital entities in an environment to create aware homes, smart offices and active spaces. In recent years, ad-hoc pervasive computing has attracted attention with the proliferation of low cost, short-range wireless devices. Adhoc pervasive computing does not assume digital devices to be tied to physical environments and aims to create digital "clusters" that can be viewed as a unified entity. The user can program this cluster of devices with a single programming interface. In this paper, we introduce our middleware, called Mobile Gaia, for ad-hoc pervasive computing. Mobile Gaia is a services-based middleware that integrates resources of various devices. It manages several functions such as forming and maintaining device collections, sharing resources among devices and enables seamless service interactions. It also provides an application framework to develop applications for the device collection. The application framework decomposes the application into smaller components that can run on different devices in this collection. We discuss the architecture of Mobile Gaia and introduce a sample application that has been designed using our middleware.