(function ($) {
    $.extend({
        getQueryString: function (name) {
            function parseParams() {
                var params = {},
                    e,
                    a = /\+/g,  // Regex for replacing addition symbol with a space
                    r = /([^&=]+)=?([^&]*)/g,
                    d = function (s) {return decodeURIComponent(s.replace(a, " "));},
                    q = window.location.search.substring(1);

                while (e = r.exec(q))
                    params[d(e[1])] = d(e[2]);

                return params;
            }

            if (!this.queryStringParams)
                this.queryStringParams = parseParams();

            return this.queryStringParams[name];
        }
    });
})(jQuery);

function turnOffLights(number, limit) {

        if ($.browser.msie  && parseInt($.browser.version) <= 7) return;
        if (!limit) limit = 3;
        if (!number) number = 0;
        $('.light .lighting').each(function(){
                var light = this;
                setTimeout(function(){
                        turnOffLight(light, number, limit);
                }, Math.random() * 3000);
                
        });
        
        
        
}

function turnOffLight(light, number, limit) {
        
        $(light).fadeTo('slow', Math.random(), function(){
                
                
                if (number >= limit) {
                        $(this).hide();
                        //$(this).parent().css()
                }
                else {
                        $(this).fadeTo('fast', 1 - (Math.random() / 4), function(){
                                
                                number++;
                                setTimeout(function(){
                                      turnOffLight(light, number, limit);  
                                }, Math.random() * 2000); 
                        });
                }
                
                        
        });
}
