﻿function Repeater(templateElement, destinationElement) {

    var repeater = {

        templateMarkup: templateElement.innerHTML.replace(/(<!--|-->|\n|\t)/g, ""),
        
        replace: function(variable, value) {
            repeater.templateMarkup = repeater.templateMarkup.replace(new RegExp(variable, "g"), value);
        },
        
        output: function(append) {
        
            // Hide the template
            templateElement.style.display = "none";
            
            // If there is no destinationElement specified, return the markup
            
            if (!destinationElement)
                return repeater.templateMarkup;
            
            // If there is one, display it in the destinationElement's innerHTML
            
            if (append)
                destinationElement.innerHTML += repeater.templateMarkup;
            else
                destinationElement.innerHTML = repeater.templateMarkup;
                
        }
        
    };
    
    return repeater;
    
};