/*global radioplayer, glow, document*/

/**
 * Iterate through the key/value pairs of all objects in iplayer.*, binding values (functions)
 * to elements as determined by keys (CSS selectors).  If an an object has an init() method,
 * that is also called.  (Following the bind.)
 *
 * @author Michael Stillwell <michael.stillwell@bbc.co.uk>
 */

(function(){

	    var bind = radioplayer.utils.events.bind,
			unbind = radioplayer.utils.events.unbind,
			rebind = radioplayer.utils.events.rebind;

	// this automatically adds the bind method to all the models & controllers
	// within iplayer
	var namespaces = [ radioplayer.models, radioplayer.controllers  ];
	var module, i, ns;

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

		ns = namespaces[i];

		for (module in ns) {

			if (ns.hasOwnProperty(module) && (typeof(ns[module]) === "function")) {
				ns[module].prototype.bind = bind;
				ns[module].prototype.unbind = unbind;
				ns[module].prototype.rebind = rebind;
			}
		}
	}
})();

