contract ArtworkBase is ArtworkAccessControl {
    /*** EVENTS ***/

    /// @dev The Birth event is fired whenever a new artwork comes into existence. This obviously
    ///  includes any time a artwork is created through the giveBirth method, but it is also called
    ///  when a new artwork is created.
    event Birth(address owner, uint256 artworkId, string name, string author, uint32 series);

    /// @dev Transfer event as defined in current draft of ERC721. Emitted every time a artwork
    ///  ownership is assigned, including births.
    event Transfer(address from, address to, uint256 tokenId);

    /*** DATA TYPES ***/
    /// @dev The main Artwork struct. Every art in CryptoArtworks is represented by a copy
    ///  of this structure, so great care was taken to ensure that it fits neatly into
    ///  exactly two 256-bit words. Note that the order of the members in this structure
    ///  is important because of the byte-packing rules used by Ethereum.
    ///  Ref: http://solidity.readthedocs.io/en/develop/miscellaneous.html
    struct Artwork {
         // The timestamp from the block when this artwork came into existence.
        uint64 birthTime;
        // The name of the artwork
        string name;
        string author;
        //sometimes artists produce a series of paintings with the same name
        //in order to separate them from each other by introducing a variable series.
        //Series with number 0 means that the picture was without series
        uint32 series;
    }

    // An approximation of currently how many seconds are in between blocks.
    // uint256 public secondsPerBlock = 15;
    /*** STORAGE ***/
    /// @dev An array containing the Artwork struct for all Artworks in existence. The ID
    ///  of each artwork is actually an index into this array.
    ///  Artwork ID 0 is invalid... ;-)
    Artwork[] internal artworks;
    /// @dev A mapping from artwork IDs to the address that owns them. All artworks have
    ///  some valid owner address.
    mapping (uint256 => address) public artworkIndexToOwner;

    // @dev A mapping from owner address to count of tokens that address owns.
    //  Used internally inside balanceOf() to resolve ownership count.
    mapping (address => uint256) internal ownershipTokenCount;

    /// @dev A mapping from artworkIDs to an address that has been approved to call
    ///  transferFrom(). Each Artwork can only have one approved address for transfer
    ///  at any time. A zero value means no approval is outstanding.
    mapping (uint256 => address) public artworkIndexToApproved;


    /// @dev The address of the ClockAuction contract that handles sales of Artworks. This
    ///  same contract handles both peer-to-peer sales as well as the initial sales which are
    ///  initiated every 15 minutes.
    SaleClockAuction public saleAuction;

    /// @dev Assigns ownership of a specific Artwork to an address.
    function _transfer(address _from, address _to, uint256 _tokenId) internal {
        // Since the number of artworks is capped to 2^32 we can't overflow this
        ownershipTokenCount[_to]++;
        // transfer ownership
        artworkIndexToOwner[_tokenId] = _to;
        // When creating new artworks _from is 0x0, but we can't account that address.
        if (_from != address(0)) {
            ownershipTokenCount[_from]--;
            // clear any previously approved ownership exchange
            delete artworkIndexToApproved[_tokenId];
        }
        // Emit the transfer event.
        Transfer(_from, _to, _tokenId);
    }

    /// @dev An internal method that creates a new artwork and stores it. This
    ///  method doesn't do any checking and should only be called when the
    ///  input data is known to be valid. Will generate both a Birth event
    ///  and a Transfer event.
    /// @param _id The artwork's genetic code.
    /// @param _owner The inital owner of this art, must be non-zero (except for ID 0)
         // The timestamp from the block when this artwork came into existence.
    uint64 internal birthTime;
    string internal author;
    // The name of the artwork
    string internal name;
    uint32 internal series;

    function _createArtwork(string _name, string _author, uint32 _series, address _owner ) internal returns (uint) {
        Artwork memory _artwork = Artwork({ birthTime: uint64(now), name: _name, author: _author, series: _series});
        uint256 newArtworkId = artworks.push(_artwork) - 1;

        // It's probably never going to happen, 4 billion artworks is A LOT, but
        // let's just be 100% sure we never let this happen.
        require(newArtworkId == uint256(uint32(newArtworkId)));

        // emit the birth event
        Birth(_owner, newArtworkId, _artwork.name, _artwork.author, _series);

        // This will assign ownership, and also emit the Transfer event as
        // per ERC721 draft
        _transfer(0, _owner, newArtworkId);

        return newArtworkId;
    }

}
/// @title Base contract for CryptoArtworks. Holds all common structs, events and base variables.
/// @dev See the ArtworkCore contract documentation to understand how the various contract facets are arranged.
function _transfer(address _from, address _to, uint256 _tokenId) internal {
    // Since the number of artworks is capped to 2^32 we can't overflow this
    ownershipTokenCount[_to]++;
    // transfer ownership
    artworkIndexToOwner[_tokenId] = _to;
    // When creating new artworks _from is 0x0, but we can't account that address.
    if (_from != address(0)) {
        ownershipTokenCount[_from]--;
        // clear any previously approved ownership exchange
        delete artworkIndexToApproved[_tokenId];
    }
    // Emit the transfer event.
    Transfer(_from, _to, _tokenId);
}

/// @dev Assigns ownership of a specific Artwork to an address.