var template = {"url":"http://jsbin.com/ociko/2","html" : "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=utf-8 \/>\n<title>JS Bin<\/title>\n<!--[if IE]>\n  <script src=\"http:\/\/html5shiv.googlecode.com\/svn\/trunk\/html5.js\"><\/script>\n<![endif]-->\n<style>\n  article, aside, figure, footer, header, hgroup, \n  menu, nav, section { display: block; }\n  body { background-color: #000; color: #fff; }\n<\/style>\n<\/head>\n<body>\n  <p id=\"result\"><\/p>\n<\/body>\n<\/html>","javascript":"function Publisher(name) {\n   this.name = name;\n   this.subscribers = [];\n}\nPublisher.prototype.deliver = function (data, scope) {\n   scope = scope || window;\n\n   var self = this;\n\n   this.subscribers.forEach(\n       function (value) {\n           value.call(scope, self.name, data);\n       }\n   );\n\n   return this;\n};\nFunction.prototype.subscribe = function (publisher) {\n   var self = this,\n       isExistent = publisher.subscribers.some(\n           function (value) {\n               return (value === self);\n           }\n       );\n\n   if (!isExistent) {\n       publisher.subscribers.push(this);\n   }\n\n   return this;\n};\nFunction.prototype.unsubscribe = function (publisher) {\n   var self = this;\n\n   publisher.subscribers = publisher.subscribers.filter(\n       function(value) {\n           if (value !== self) {\n               return value;\n           }\n       }\n   );\n\n   return this;\n};\nvar Index = {\n    init: function () {\n        var randomTime = function () { return ((Math.floor(Math.random() * 11)) + 1) * 1000; };\n\n        [\n            { name: 'NPR', message: 'Obama is splendiferous!' },\n            { name: 'BBC', message: 'Chance is causative!' },\n            { name: 'Chase', message: 'Your account is overdrawn!' },\n            { name: 'Friend', message: 'Buy this new curricula!' }\n        ].forEach(function (value) {\n            Index[value.name] = new Publisher(value.name);\n            (function (value, when) {\n                setTimeout(\n                    function () {\n                        Index[value.name].deliver(value.message)\n                    },\n                    when\n                );\n            })(value, randomTime());\n        });\n        [\n            { name: 'Husband', color: '#888;' },\n            { name: 'Wife', color: '#f33;' },\n            { name: 'Son', color: '#33f;' }\n        ].forEach(function (value) {\n                Index[value.name] = (function (to) {\n                    return function (from, data) {\n                        document.getElementById('result').innerHTML += '<p>' +\n                              'Delivery From: ' +\n                              from +\n                              '<br \/>&nbsp;&nbsp;&nbsp;&nbsp;To: <span style=\"color: ' + to.color + '\">' +\n                              to.name +\n                              '<\/span><br \/>&nbsp;&nbsp;&nbsp;&nbsp;Data: ' +\n                              data +\n                          '<\/p>';\n                    };\n                })(value);\n            }\n        );\n        Index.Husband.subscribe(Index.BBC).subscribe(Index.NPR).subscribe(Index.Chase);\n        Index.Wife.subscribe(Index.BBC).subscribe(Index.Friend).subscribe(Index.Chase);\n        Index.Son.subscribe(Index.BBC);\n    },\n    Husband: {},\n    Wife: {},\n    Son: {},\n    BBC: {},\n    NPR: {},\n    Chase: {},\n    Friend: {}\n};\nsetTimeout(Index.init, 500);\n"}
