var DataAccess = new Class({
	initialize: function(ctor, core){
		this.core = core;
		this.ctor = ctor;
		this.dataService = core.dataService;
        this.isBusy = false;
	},

	getData: function(){
		if(!this.isBusy) { 
            this.isBusy=true;
			var modDates = this.core.dataManager.getModifiedTypes();
			this.dataService.getData(modDates, this.getDataSuccessCallback, this.getDataFailedCallback, {scope: this} );
        }else{
            this.error('DataManager.getData: Cannot call getData while DataAccess is busy');
        }
	},

	getDataSuccessCallback: function(response, eventObj)
	{
		eventObj.scope.core.dataManager.loadToBuffer(response);
		eventObj.scope.isBusy=false;
	},
	
	getDataFailedCallback: function(error, eventObj)
	{
		eventObj.scope.error("GetData Error: " + error.get_message());
		eventObj.scope.isBusy=false;
		Debug(eventObj.scope.core);
	},

	boolSuccessCallback: function(response, eventObj)
	{
		Debug(response);
	},

	failedCallback: function(error, eventObj)
	{
	    alert('failedCallback');
		//eventObj.scope.error("Service Error: " + error.get_message());
		//Debug(this.core);
	},
	
	getPageContent: function(sitePage){
		if(!this.isBusy) { 
            this.isBusy=true;  
            
			this.dataService.getPageContent(sitePage.ctor.source, this.getPageContentSuccessCallback, this.failedCallback, {scope: this, sitePage: sitePage})
			
        }else{
            this.error('dataService.GetPage: Cannot call getPage while DataAccess is busy');
        }
	},

	getPageContentSuccessCallback: function(response, eventObj)
	{
	    //alert('success');
		//eventObj.scope.core.dataManager.loadToBuffer(response);
		
		eventObj.sitePage.fillContentCallback(response);
		eventObj.scope.isBusy=false;
	},

	submitContact: function(cName, cEmail, cMsg){
		this.dataService.submitContact(cName, cEmail, cMsg, this.submitContactSuccessCallback, this.failedCallback, {scope: this} );		
	},
	
	submitContactSuccessCallback: function(response, eventObj)
	{
	    $('contactResultMsg').innerHTML=response;
	},
	

	error: function(msg){
		this.core.log.push('DataAccess Error: ' + msg);
	}
});

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
