Push = function () {
	Push.superclass.constructor.apply(this, arguments);
    
    var _channels = this.set("chanels", []);
    
    this.addChannel = function (name, func) {
    	if(typeof realplexor == 'undefined'){
			return;
		}
        _channels.push(name);
        realplexor.subscribe(name, func);
		realplexor.execute();
    }
    
    this.initIndex = function () {
    	if(typeof realplexor == 'undefined'){
			return;
		}
        _channels.push('liveLists');
        
        realplexor.subscribe('liveLists', function(data, id, cursor) {
            $('.live-list li:not(:eq(0))').remove();
            if(data) {						
                $('.live-list li:not(:eq(0))').remove();
                $.each(data, function(i, item){
					if (item) {
						$('.live-list').append(
								"<li><a href='" + item['custom_route'] + "'>" + item['title'] + "</a> <span>" + item['count'] + " viewer" + ((item['count'] > 1) ? 's' : '') +  "</span></li>"
							);
					}
                })
            }

		});
		realplexor.execute();
    }
    
    this.unsubscribe = function () {
    	if(typeof realplexor == 'undefined'){
			return;
		}
        for (a in _channels) {
            realplexor.unsubscribe(_channels[a], function () {});
            realplexor.execute();
        }
		
		this.rpc (
			'/index/unsubscribe',
			{listId:this.get("masterListID", true)},
			function(data) {
			},
			false,
			false,
			false
		);
		
		return true;
    }
    
    this.init = function () {
        if (_config.isIndex) {
            this.initIndex();
        }
    }
    
    this.addListener ("ready", this.init);
    $(window).unload(this.context(this.unsubscribe));
}
extend (Push, Model);

push = new Push();
