'use strict';

var PageFactory = angular.module('home.factory', [
]).factory('PageFactory', [
    'Common',
    function (Common) {
        
        var expanded = [];
        
        function Page(data) {
            var self = this;
            if (data) angular.extend(this, data);
            this.PublishedOn = new Date(this.PublishedOn);
            this.ExpiresOn = new Date(this.PublishedOn);
        }

        var create = function(data) {
            return new Page(data);
        };
        
        var addExpanded = function (id) {
            var exist = false;
            
            for (var i = 0; i < expanded.length; i++) {
                if (expanded[i] === id) {
                    exist = true;
                }
            }
            
            if(exist == false) {
                expanded.push(id);
            }
        };

        var removeExpanded = function(id) {
            angular.forEach(expanded, function (value, key) {
                if (value == id) {
                    expanded.splice(key, 1);
                }
            });
        };

        var allExpanded = function () {
            return expanded;
        };

        return {
            create: create,
            addExpanded: addExpanded,
            allExpanded: allExpanded,
            removeExpanded: removeExpanded
        };
    }
]);