define([
	'underscore',
	'backbone'
], function(_, Backbone){
	
	var Jenkins = {};
	
	Jenkins.STATUS_OK = 'ok';
	Jenkins.STATUS_KO = 'ko';
	Jenkins.STATUS_INSTABLE = 'instable';
	Jenkins.STATUS_NONE = 'none';

	Jenkins.Model = Backbone.Model.extend({
		url: function() {
			return '%s/api/json'.replace('%s', this.get('url'));
		}
	});
	
	Jenkins.EzWall = Jenkins.Model.extend({
		defaults: {
			url: "http://localhost:8080/ezwall",
			pollInterval: 5
		}
	});

	Jenkins.Job = Jenkins.Model.extend({
	    defaults: {
		    name: "My job",
		    status: Jenkins.STATUS_NONE,
		    building: false
		},
		
		color_regex: /([A-Za-z]+)(_anime)?/,
		
		parse: function(data) {
			var m = this.color_regex.exec(data.color);
			
			switch (m[1]) {
				case 'blue':
					data.status = Jenkins.STATUS_OK;
					break;
				case 'red':
					data.status = Jenkins.STATUS_KO;
					break;
				case 'yellow':
					data.status = Jenkins.STATUS_INSTABLE;
					break;
				default:
					break;
			}
			data.building = m[2] != undefined;
			return data;
		}
	});

	Jenkins.JobList = Backbone.Collection.extend({
	    model: Jenkins.Job,
	    
	    initialize: function() {
	    	_.bindAll(this, 'poll');
	    },
	    
	    poll: function(refresh){
	    	this.each(function(job){
				job.fetch()
			});
	    	_.delay(this.poll, refresh*1000, refresh);
	    }
	});

	Jenkins.View = Jenkins.Model.extend({
	    defaults: {
		    name: "All",
		    url: "http://localhost:8080/",
		    refresh: 10
		},
		initialize: function() {
			var ezWall = new Jenkins.EzWall({
				url: this.get('url')+'/ezwall'
			});
			ezWall.on('change', this.updateSettings, this);
			this.set({
				jobs: new Jenkins.JobList(),
				ezwall: ezWall
			});
		},
		parse: function(data, xhr) {
			this.get('jobs').reset(data.jobs, {parse: true});
			delete data.jobs;
			return data;
		},
		fetch: function(options) {
			var view = this;
			this.get('ezwall').fetch({
				success: function() {
					Jenkins.Model.prototype.fetch.call(view, options);
				}
			});
		},
		poll: function() {
			this.get('jobs').poll(this.get('refresh'));
		},
		updateSettings: function() {
	      this.set('refresh', this.get('ezwall').get('pollInterval'));
	    }
	    
	});

	return Jenkins;
});

@@ -1124,85 +1124,14 @@
     
-initialize: function() %7B%0A%09    %09_.bindAll(this, 'poll');%0A%09    %7D,%0A%09    %0A%09    po
+fetchA
 ll: 
@@ -1139,24 +1139,18 @@
 unction(
-refresh
 )
+ 
 %7B%0A%09    %09
@@ -1201,57 +1201,8 @@
 %7D);%0A
-%09    %09_.delay(this.poll, refresh*1000, refresh);%0A
 %09   
@@ -1345,16 +1345,16 @@
 10%0A%09%09%7D,%0A
-
 %09%09initia
@@ -1368,24 +1368,52 @@
 unction() %7B%0A
+%09%09%09_.bindAll(this, 'poll');%0A
 %09%09%09var ezWal
@@ -1958,13 +1958,45 @@
 s').
+fetchAll();%0A%09    %09_.delay(this.
 poll
-(
+, 
 this
@@ -2010,16 +2010,21 @@
 efresh')
+*1000
 );%0A%09%09%7D,%0A

Refactor polling to handle interval update