var FoodArena = FoodArena || {}

FoodArena.dataContext = (function ($) {
    "use strict";
    var dataList = [],
    dataStorageKey;


  //  var saveUserData = function (data) {
  //      $.jStorage.set(dataStorageKey, data);
  //  };

    var getUserData = function () {
        dataList = $.jStorage.get(dataStorageKey);
        if (dataList !== null) {
            return dataList;
        }
		dataList = [];
        return dataList;
    };
    

    var saveUserData = function (data) {
		for(var i=0; i<=data.length; i++){
			//dataList.splice(i, 0, data);
		}
        $.jStorage.set(dataStorageKey, data);
    };
    
    
    var deleteUserData = function (index) {
        dataList.splice(index,1);
        $.jStorage.set(dataStorageKey, dataList);
    };
/*
//---------------------
    var getLastLocations = function () {

       var count = 3;
        var locations = [];
        for (var i = 0; i < count; i++) {
  
            var location = new FoodArena.Location ({
            id: i,
            text: "lenina" + i
             });
            
            locations.push(location);
        }


        return locations;
    };
/*
    var loadNotesFromLocalStorage = function () {

        var storedNotes = $.jStorage.get(notesListStorageKey);

        if (storedNotes !== null) {
            notesList = storedNotes;
        }

    };

    var saveNotesToLocalStorage = function () {
        $.jStorage.set(notesListStorageKey, notesList);
    };

    var saveNote = function (noteModel) {

        var found = false;
        var i;

        for (i = 0; i < notesList.length; i += 1) {
            if (notesList[i].id === noteModel.id) {
                notesList[i] = noteModel;
                found = true;
                i = notesList.length;
            }
        }

        if (!found) {
            notesList.splice(0, 0, noteModel);
        }

        saveNotesToLocalStorage();
    };

    var deleteNote = function (noteModel) {

        var i;
        for (i = 0; i < notesList.length; i += 1) {
            if (notesList[i].id === noteModel.id) {
                notesList.splice(i, 1);
                i = notesList.length;
            }
        }

        saveNotesToLocalStorage();
    };

    var getNotesList = function () {
        return notesList;
    };
*/

//----------------------------------
    var init = function (storageKey) {
        dataStorageKey = storageKey;
       // getLastLocations();
    };

    var pub = {
        init: init,
        getUserData:getUserData,
        deleteUserData:deleteUserData,
        saveUserData: saveUserData//,
       // getNotesList: getNotesList,
       // saveNote: saveNote,
       // deleteNote: deleteNote
    };

    return pub;

} (jQuery));