/**
 * Constructor for the inter-tab manager
 *
 * @param {Object} options
 * @api public
 */

function Manager(opts) {
	/*
	 * TODO:
	 * See if tabs associated with this domain are also using inter-tab
	 * Add self to tab array
	 */

	// Listen to event when tab is closed or storage changes
	window.addEventListener('storage', this, false);
	window.addEventListener('unload', this, false);
}


/**
 * Broadcast message to all managed tabs
 *
 */

Manager.prototype.broadcast = function (key, value) {
	var data = {
		key: key,
		value: value
	};

    try {
        localStorage.setItem( 'broadcast', JSON.stringify(data));
    } catch (error) {}
};

Manager.prototype.handleEvent = function (event) {
    // if ( event.type === 'unload' ) {
    //     this.destroy();
    // } else if ( event.key === 'broadcast' ) {
    //     try {
    //         var data = JSON.parse( event.newValue );
    //         if ( data.id !== this.id ) {
    //             this[ data.type ]( data );
    //         }
    //     } catch ( error ) {}
    // }
    console.log(event);
    debugger;
};

/**
 * Send message to a specific tab
 *
 */

Manager.prototype.send = function (id, key, value) {

};


/**
 * Associate data with a specific tab
 *
 */

Manager.prototype.set = function (id, key, value) {

};


/**
 * Retrieve data for a specific tab
 *
 */

Manager.prototype.get = function (id, key) {

};


// Expose the inter-tab manager

// if (typeof module === 'object' && module.exports) {
//     module.exports = Manager;
// } else {
//     this.it = Manager;
// }
@@ -118,120 +118,32 @@
  %7B%0A%09
-/*%0A%09 * TODO:%0A%09 * See if tabs associated with this domain are also using inter-tab%0A%09 * Add self to tab array%0A%09 */
+this.id = Math.random();
 %0A%0A%09/
@@ -300,16 +300,176 @@
 se);%0A%7D%0A%0A
+Manager.prototype.destroy = function () %7B%0A    window.removeEventListener( 'storage', this, false );%0A    window.removeEventListener( 'unload', this, false );%0A%7D;%0A
 %0A/**%0A * 
@@ -775,17 +775,13 @@
 %0A   
- //
  if (
- 
 even
@@ -799,25 +799,24 @@
 'unload'
- 
 ) %7B%0A    
 //     t
@@ -807,23 +807,20 @@
 ) %7B%0A    
-//
     
- 
 this.des
@@ -830,19 +830,16 @@
 y();%0A   
- //
  %7D else 
@@ -842,17 +842,16 @@
 lse if (
- 
 event.ke
@@ -867,27 +867,23 @@
 oadcast'
- 
 ) %7B%0A   
- //
      try
@@ -889,26 +889,24 @@
 y %7B%0A    
-//
         
  var dat
@@ -901,235 +901,52 @@
     
- var data = JSON.parse( event.newValue );%0A    //         if ( data.id !== this.id ) %7B%0A    //             this%5B data.type %5D( data );%0A    //         %7D%0A    //     %7D catch ( error ) %7B%7D%0A    // %7D%0A    console.log(event);%0A    debugger;
+debugger;%0A        %7D catch ( error ) %7B%7D%0A    %7D
 %0A%7D;%0A

Add destroy method