// U T I L S . js
// A collection of handy scripting tools
//
// Version 1.00 - 2011-June.
//

// This function parses ampersand-separated name=value argument pairs from the
// query string of the URL. It stores the name=value pairs in the properties of
// an object and returns the object. (Lifted from David Flanigan's 'Javascript, the Definitive Guide'.

function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);       // get query string
    var pairs = query.split("&");                   // break at ampersand

    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');            // look for "name=value"
        if (pos == -1) continue;                    // if not found, skip
        var argname = pairs[i].substring(0, pos);   // extract the name
        var value = pairs[i].substring(pos + 1);    // extract the value
        value = decodeURIComponent(value);          // decode as necessary
        args[argname] = value;                      // store it as a property
    }
    return args;                                    // return object
};

// This function gets the width of the window and the width of the element specified by the passed in
// parameter and returns the difference as an integer number of pixels. The selector is required and is
// expected to be a valid CSS selector.

function imgSize(selector) {
    if (!selector) { return 0 };

    var winX = $(window).width();
    var selectorX = $(selector).width();
    var diffX = winX - selectorX;
    return diffX;
};

/* Added Pub/Sub utility  */
(function (a) { var b = {}; a.publish = function (c, e) { b[c] && a.each(b[c], function () { this.apply(a, e || []) }) }, a.subscribe = function (a, c) { b[a] || (b[a] = []), b[a].push(c); return [a, c] }, a.unsubscribe = function (c) { var e = c[0]; b[e] && a.each(b[e], function (a) { this == c[1] && b[e].splice(a, 1) }) } })(jQuery)
