/**
 * @contributor Matthew Foster
 * @date 		September 4th 2007
 */
var NetworkDetection = Class.create();
		
Object.extend(Object.extend(NetworkDetection.prototype, Ajax.Service.Base.prototype),
				{
					
					initialize : function(url, options){
						
						this.url = url;
						this.options = Object.extend({ interval : 9000 }, options || {});
						this.createListener();
						this.status = "online";
						this.startTimer();	
					
					},
					startTimer : function(){
						this.stopTimer();
						this.timer = window.setInterval(this.checkNetwork.bind(this), this.options.interval);
					
					},
					stopTimer : function(){
						
						window.clearInterval(this.timer);
					
					},
					createListener : function(){
						
						this.receiveNetworkHandle = this.receiveNetwork.bind(this);
														
					},
					checkNetwork : function(){
					
						this.sendRequest({}, this.receiveNetworkHandle)
					
					},
					receiveNetwork : function(eAja){
						
						this.toggleNetwork("online", eAja);
					
					},
					ajaxFailure : function(eAja){
						
						this.toggleNetwork("offline", eAja);
					
					},
					ajaxException : function(eAja){
						
						this.toggleNetwork("offline", eAja);
					
					},
					toggleNetwork : function(str, eAja){
						
						if(this.status != str){
							this.dispatchEvent(str, eAja);
							this.setStatus(str);
						}
					},
					setStatus : function(str){
					
						this.status = str;
					
					},
					getStatus : function(){
						
						return this.status;
					
					}
						
				
				
				
				}
			)