/*******************************************************************************
TITLE: hacks.js
AUTHOR: Alan Shea Anderson-Priddy, copyright (c) 2015
LICENSE: AGPLv3+
DESCRIPTION OF DOCUMENT: 
DESCRIPTION OF ISSUE: 
NOTES ABOUT CODE: Purely js for the fun of it. I will consider a library if I need more functionality in less time than I have to hack it. 
ACKNOWLEDGEMENTS: 
*******************************************************************************/

// ==================== WINDOW.~foobars ====================
//TODO: move this stuff to the local main file and reuse the rest
window.onload = function () {
    var theElement = document.getElementById("hacks_where_ever_you_go");
    var theEvent = "click";
    var theHandler = function () { console.error("there you are! =D no error just awesome! ");}
    var theArgs = ["foo", "bar"];

    var doFunnyEvent = new PeersEventManager(theElement, theEvent, theHandler, theArgs);
    doFunnyEvent.add();
    
    //yeah could make this a little more efficient... 
    //such as creating both listeners for the hash removehash at the same time
    //but for now whatever =D
    var theElement2 = document.getElementById("hacks_remove_hash");
    var removeHash = function () { window.location.hash="";}
    var doFunnyEvent = new PeersEventManager(theElement2, theEvent, removeHash, theArgs);
    doFunnyEvent.add();
}


// ==================== PeersEventManager ====================
var PeersEventManager = function (theElement, theEvent, theHandler, theArgs) {
    this.theElement = theElement;
    this.theEvent = theEvent;
    this.theHandler = theHandler;
    this.theArgs = theArgs;
}
PeersEventManager.prototype = (function () {
    function printSlug() { return "fooooooooooo";}
    function addListener(yoElement, yoEvent, yoHandler, yoArg) {
        if (yoElement.addEventListener) {
            yoElement.addEventListener(yoEvent, function(){yoHandler(yoArg, 0)}, false);
        }
        else if (yoElement.attachEvent) {
            yoElement.attachEvent('on' + yoEvent, function(){yoHandler(yoArg, 0)});
        }
        else {
            yoElement['on' + yoEvent] = yoHandler;
        }
        return printSlug();
    }
    function removeListener(yoElement, yoEvent, yoHandler, yoArg) {
        if (yoElement.addEventListener) {
            yoElement.removeEventListener(yoEvent, function(){yoHandler(yoArg, 0)}, false);
        }
        else if (yoElement.detachEvent) {
            yoElement.detachEvent('on' + yoEvent, function(){yoHandler(yoArg, 0)});
        }
        else {
            yoElement['on' + yoEvent] = null;
        }
        return printSlug();
    }

    return {
        add: function () {
            var someArg = this.theArgs[0];
            return addListener(this.theElement, this.theEvent, this.theHandler, someArg);
        },
        remove:function () {
            //not really using this yet so foobar it
            //removeListener(this.theElement, this.theEvent, this.theHandler, this.theArgs);
            return printSlug();
        }
    };
})();


