
/*  new/common/js/jquery.popupWindow.js  */
(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = settings.windowURL?settings.windowURL:this.href;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){
						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);

/*  new/common/js/global_async.js  */
$(document).ready(function(){
    if ('function' === typeof $().popupWindow)
    {
        $('a.tw', '#share-links').popupWindow({
            centerBrowser:1,
            windowURL:'http://twitter.com/intent/follow?region=follow&screen_name=avaaz',
            windowName:'twitter_popup_follow'
        });
    }
});

/*  common/js/MCounter.js  */
var counterdata;
function MCounter(options) {
    this['mcounter_' + options.cid] = {};
    var counter = this['mcounter_' + options.cid];
    counter.setCurrency = function () {
        $('.progress-currency' + counter.mckey + ', .progress-currency-no-key').each(function () {
            $(this).html(counter.currency_value);
        });
    };
    counter.setTarget = function () {
        var target = counter.number_format(counter.target, 0, '.', options.thousand_separator),
            h = '',
            k = '';
        $('.progress-target' + counter.mckey).each(function () {
            if (counter.is_target) {
                $(this).html(target);
            } else {
                $(this).html('');
            }
        });
        counter.text = counter.text.replace('{target}', target);
        if (counter.is_target) {
            if ('' !== counter.currency_value) {
                h = ' ';
            } else {
                k = ' ';
            }
            $('.progress-target-additional' + counter.mckey).html(k + counter.number_format(counter.target, 0, '.', options.thousand_separator));
            $('.progress-currency-target' + counter.mckey).html(h + counter.currency_value);
        }
    };
    counter.setText = function () {
        if (counter.in_array(counter.counter_type, ['countries_donate', 'donates'])) {
            counter.setAdditionalCurrency();
        }
        $('.progress-text' + counter.mckey).html(' ' + counter.text);

    };
    counter.setAdditionalCurrency = function () {
        if ('euro_dollar' === counter.currency) {
            $('.progress-additional-currency' + counter.mckey).html('($' + counter.number_format(counterdata.USD) + ')');
        } else if ('dollar_euro' === counter.currency) {
            $('.progress-additional-currency' + counter.mckey).html('(&euro;' + counter.number_format(counterdata.EUR) + ')');
        }
    };
    counter.setCountryCount = function () {
        if ('countries' === counter.counter_type) {
            $('.progress-country' + counter.mckey).html(' ' + counterdata.countries_cnt + ' ' + counter.country_text);
        } else if ('countries_donate' === counter.counter_type) {
            $('.progress-country' + counter.mckey).html(' ' + counterdata.donate_countries_cnt + ' ' + counter.country_text);
        }
    };
    counter.setData = function (num) {
        var togo = counter.target - num;
        if (counter.default_max > counter.target) {
            togo = counter.default_max - num;
        }
        $('.progress-data' + counter.mckey).each(function () {
            $(this).html(counter.number_format(num, 0, '.', options.thousand_separator));
        });

        $('.progress-data-nearby' + counter.mckey).each(function () {
            $(this).html(counter.number_format(counter.max_nearby, 0, '.', options.thousand_separator));
        });

        $('.progress-data-togo' + counter.mckey + ', .progress-data-togo-no-key').each(function () {
            if (0 > togo) {
                togo = 0;
            }
            $(this).html(counter.number_format(togo, 0, '.', options.thousand_separator)).change();
        });
        $('.progress-data-goal' + counter.mckey + ', .progress-data-goal-no-key').each(function () {
            $(this).html(counter.number_format(counter.target, 0, '.', options.thousand_separator)).change();
        });
    };
    counter.showCounter = function () {
        var px,
            iw;
        counter.setData(counter.num);
        if (counter.max > counter.default_max) {
            counter.default_max = parseInt(counter.max, 10);
            counter.proc = counter.progress_bar_width / counter.max;
        }
        px = parseInt(counter.proc * counter.num, 10);
        iw = $('.progress-inline' + counter.mckey).width();
        if (0 !== iw && (iw + 10) > px) {
            px = iw + 10;
        }
        $('.progress-move' + counter.mckey).width(px + 'px');
    };

    counter.showNearbyCounter = function () {
        var px,
            iw;
        counter.setData(counter.num);
        if (counter.nearby_max > counter.default_max) {
            counter.default_max = parseInt(counter.nearby_max, 10);
            counter.proc = counter.progress_bar_width / counter.nearby_max;
        }
        px = parseInt(counter.proc * counter.nearby_max, 10);
        iw = $('.progress-inline' + counter.mckey).width();
        if (0 !== iw && (iw + 10) > px) {
            px = iw + 10;
        }
        $('.progress-move' + counter.mckey).width(px + 'px');
    };

    counter.getSumm = function (nnm, nnm2) {
        var rand, timeout;
        if (nnm2 < 1) {
            rand = nnm + nnm2;
        } else if (nnm2 < 10) {
            rand = nnm + 1;
            timeout = 100;
        } else if (nnm2 < 100) {
            rand = nnm + Math.floor((Math.random() * 9) + 1);
            timeout = 0;
        } else if (nnm2 < 1000) {
            rand = nnm + Math.floor((Math.random() * 91) + 10);
            timeout = 50;
        } else if (nnm2 < 10000) {
            rand = nnm + Math.floor((Math.random() * 901) + 100);
            timeout = 50;
        } else if (nnm2 < 100000) {
            rand = nnm + Math.floor((Math.random() * 2001) + 1000);
            timeout = 50;
        } else if (nnm2 < 1000000) {
            rand = nnm + Math.floor((Math.random() * 20001) + 5000);
            timeout = 50;
        } else if (nnm2 >= 1000000) {
            rand = nnm + Math.floor((Math.random() * nnm2 / 100) + nnm2 / 100);
            timeout = 50;
        } else {
            rand = nnm + counter.plus;
        }
        counter.timeout = timeout;
        return rand;
    };

    counter.startCounter = function () {
        var rand, num2;

        if (counter.franchise_cid && undefined != counter.franchise_cid){
            counter.showNearbyCounter();
        } else {
            counter.showCounter();
        }

        if (counter.timerId) {
            clearTimeout(counter.timerId);
        }
        if (counter.num < counter.max) {
            rand = counter.getSumm(counter.num, counter.max);
            if (rand > counter.max) {
                num2 = counter.max - counter.num;
                counter.num = counter.getSumm(counter.num, num2);
            } else {
                counter.num = rand;
            }
            counter.timerId = setTimeout(counter.startCounter, counter.timeout);
        } else if (true === counter.ajax_data) {
            counter.ajaxCounter();
        }

    };
    counter.addCommas = function (nStr) {
        var rgx, x, x1, x2;
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    };
    counter.ajaxCounter = function () {
        if (counter.ajax_counter_timer) {
            clearTimeout(counter.ajax_counter_timer);
        }
        $.ajax({
            url: '/act/ajax_counter.php?cid=' + counter.cid + '&type=' + counter.template +
                (undefined !== counter.petition_id ? '&petition_id=' + counter.petition_id : '') +
                (counter.franchise_cid && undefined !== counter.franchise_cid ? '&franchise_cid=' + counter.franchise_cid : '') +
                (counter.petition_latitude && undefined !== counter.petition_latitude ? '&petition_latitude=' + counter.petition_latitude : '') +
                (counter.petition_longitude && undefined !== counter.petition_longitude ? '&petition_longitude=' + counter.petition_longitude : '') +
                (counter.petition_distance && undefined !== counter.petition_distance ? '&distance=' + counter.petition_distance : ''),
            dataType: 'json',
            type: 'GET',
            success: function (json) {
                if (json && 0 == json.paused) {
                    switch (counter.counter_type) {
                    case 'countries_donate':
                    case 'donates':
                        if (counter.in_array(counter.currency, ['euro', 'euro_dollar'])) {
                            counter.max = json.EUR;
                        } else if (counter.in_array(counter.currency, ['other'])) {
                            counter.max = json.OTHER;
                        } else {
                            counter.max = json.USD;
                        }
                        counterdata.USD = json.USD;
                        counterdata.EUR = json.EUR;
                        counterdata.OTHER = json.OTHER;
                        counter.setAdditionalCurrency();
                        break;
                    case 'x_number':
                        counter.max = json.donations;
                        break;
                    case 'ct_x_unique_donors':
                        counter.max = json.donors;
                        break;

                    case 'sign':
                        counter.max = json.count;
                        if (undefined !== counter.franchise_cid){
                            counter.max_nearby = json.count_nearby;
                        }
                        break;
                    }
                }
                counter.ajax_data = false;
                counter.startCounter();
                counter.ajax_counter_timer = setTimeout(counter.ajaxCounter, 20000);
            }
        });
    };
    counter.in_array = function (needle, haystack, argStrict) {
        var key = '', strict = !!argStrict;
        if (strict) {
            for (key in haystack) {
                if (haystack[key] === needle) {
                    return true;
                }
            }
        } else {
            for (key in haystack) {
                if (haystack[key] == needle) {
                    return true;
                }
            }
        }
        return false;
    };
    counter.number_format = function (number, decimals, dec_point, thousands_sep) {
        var n = number, prec = decimals, toFixedFix, sep, dec, s, abs, v, i, decPos;

        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return (Math.round(n * k) / k).toString();
        };

        n = !isFinite(+n) ? 0 : +n;
        prec = !isFinite(+prec) ? 0 : Math.abs(prec);
        sep = (undefined === thousands_sep) ? ',' : thousands_sep;
        dec = (undefined === dec_point) ? '.' : dec_point;

        s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;

        abs = toFixedFix(Math.abs(n), prec);

        if (abs >= 1000) {
            v = abs.split(/\D/);
            i = v[0].length % 3 || 3;

            v[0] = s.slice(0, i + (n < 0)) +
                v[0].slice(i).replace(/(\d{3})/g, sep + '$1');
            s = v.join(dec);
        } else {
            s = s.replace('.', dec);
        }

        decPos = s.indexOf(dec);
        if (prec >= 1 && decPos !== -1 && (s.length - decPos - 1) < prec) {
            s += new Array(prec - (s.length - decPos - 1)).join(0) + '0';
        } else if (prec >= 1 && decPos === -1) {
            s += dec + new Array(prec).join(0) + '0';
        }
        return s;
    };

    counter.cid = options.cid;
    counter.mckey = options.key;

    if (undefined !== options.petition_id) {
        counter.petition_id = options.petition_id;
    }

    counter.progress_bar_width = options.autodect_width ? $(options.progress_container).width() : options.max_width;
    counter.counter_type = options.subtype;
    counter.currency_value = options.current_currency_value;
    counter.currency = options.current_currency;
    counter.text = options.text;
    counter.country_text = options.country_text;
    counter.is_target = options.is_target;
    counter.franchise_cid = false;
    counter.petition_latitude = false;
    counter.petition_longitude = false;
    counter.petition_distance = false;

    if (options.franchise_cid && 'undefined' !== options.franchise_cid){
        counter.franchise_cid = options.franchise_cid;

        counter.petition_latitude  = options.petition_latitude;
        counter.petition_longitude = options.petition_longitude;
        counter.petition_distance = options.petition_distance;
    }

    counter.is_progress_target = ('undefined' !== typeof options.is_progress_target) ? options.is_progress_target : true;
    counter.template = '';

    if (undefined === window.counterdata) {
        window.counterdata = {target: 0, target_donate: 0, EUR: 0, OTHER: 0, USD: 0, sign: 0, sign_nearby: 0, donations: 0};
    }

    switch (counter.counter_type) {
    case 'donates':
        counter.target = counterdata.target_donate;
        if (counter.in_array(counter.currency, ['euro', 'euro_dollar'])) {
            counter.current_value = counterdata.EUR;
        } else if (counter.in_array(counter.currency, ['dollar', 'dollar_euro'])) {
            counter.current_value = counterdata.USD;
        } else if (counter.in_array(counter.currency, ['other'])) {
            counter.current_value = counterdata.OTHER;
        }
        counter.template = 'donates';
        break;
    case 'countries_donate':
        counter.target = counterdata.target_donate;
        if (counter.in_array(counter.currency, ['euro', 'euro_dollar'])) {
            counter.current_value = counterdata.EUR;
        } else if (counter.in_array(counter.currency, ['dollar', 'dollar_euro'])) {
            counter.current_value = counterdata.USD;
        }
        counter.template = 'donates';
        break;
    case 'sign':
        counter.currency_value = '';
        counter.target = counterdata.target;
        counter.current_value = counterdata.sign;
        if (false !== counter.franchise_cid){
            counter.current_nearby_value = counterdata.sign_nearby;
        }
        counter.template = 'sign';
        break;
    case 'x_number':
        counter.currency_value = '';
        counter.target = counterdata.target;
        counter.current_value = counterdata.donations;
        counter.template = 'donations';
        break;

    case 'ct_x_unique_donors':
        counter.currency_value = '';
        counter.target = counterdata.target;
        counter.current_value = counterdata.donors;
        counter.template = 'donors';
        break;

    case 'countries':
        counter.currency_value = '';
        counter.target = counterdata.target;
        counter.current_value = counterdata.sign;
        counter.template = 'sign';
        break;
    }

    counter.max2 = counter.target;
    counter.max = counter.current_value;
    counter.nearby_max = counter.current_nearby_value;
    counter.default_max = parseInt(counter.max2, 10);
    counter.num = 0;//arguments[5]?arguments[5]:0;
    counter.timerId = null;
    counter.plus = undefined !== options.plus ? options.plus : 1;
    counter.timeout = 0;
    counter.proc = counter.progress_bar_width / counter.max2;
    counter.ajax_counter_timer = null;
    counter.ajax_data = options.ajax;
    counter.aj_counter_flag = false;
    if (counter.max > counter.max2) {
        counter.proc = counter.progress_bar_width / counter.max;
        counter.default_max = parseInt(counter.max, 10);
    }
    counter.setText();
    counter.setCurrency();
    counter.setTarget();
    counter.setCountryCount();
    counter.startCounter();
}

/*  new/common/js/user_activity_do.js  */
if (!window.UserActivityStream) {
    var empty = function (mixed_var) {
        var key, breaker = true;
        if (mixed_var === "" ||
                mixed_var === 0 ||
                mixed_var === "0" ||
                mixed_var === null ||
                mixed_var === false ||
                mixed_var === undefined
                ) {
            return true;
        }
        if (typeof mixed_var === 'object') {
            // array
            if (mixed_var.length !== undefined) {return !mixed_var.length; }

            for (key in mixed_var) {
                if (breaker) {
                    return false;
                }
            }
            return true;
        }
        return false;
    };

    var UserActivityStream = function (type, load_id, cid, uid, blurbs, limit, lang, width, rtl, upid, options) {
        var self = this;
        self.options = $.extend({
            donates: false,
            show_more: false,
            is_closed: false,
            currencies: false
        }, options);
        self.load_id = load_id;
        self.type = type;//ua or fua
        self.key = Math.floor(Math.random() * 9999999);
        self.cid = cid;
        self.uid = uid;
        self.blurbs = blurbs;
        self.limit = limit;
        self.lang = lang;
        self.width = width;
        self.load_type = 'ajax'; // can be 'ajax' = same server and 'script' = debug from other server
        self.load_limit = self.limit * 3;
        self.overload_time = 5000;
        self.additional_time = 5;
        self.ajax_timeout = null;
        self.shownext_timeout = null;
        self.use_translate = false;
        self.one_user_time = 0;
        self.QUEUE = [];
        self.data = [];
        self.static_height = true;
        self.loaded_limit = 0;
        self.updater_time_id = null;
        self.loaded = {};
        self.rtl = rtl;
        self.upid = typeof upid === 'number' ? upid : 0;
        self.loggin = false;
        self.entries_cnt = 0;
        self.show_more_link = false;
        self.first_request = true;

        self.templates = {
            'normal' : '<li id="{$ID}"{$class}{$style}>' +
                    '<div id="{$PrettyTimeID}" class="time-ago">{$PrettyTime}</div>' +
                    '<div class="flag">' +
                        '<div class="flag-place">' +
                            '<span class="flag-{$CC} user_activity_flag23x14">' +
                                '<img src="/images/spacer.gif">' +
                            '</span>' +
                            '<span class="ua-flag-overground">' +
                                '<img src="/images/spacer.gif">' +
                            '</span>' +
                        '</div>' +
                    '</div>' +
                    '<div class="info" style="padding-top: 6px; width: 240px;">' +
                    (self.options.donates ?
                        ('<p class="person" style="margin-top: 0px; margin-bottom: 0px;">${$amount}&nbsp;<big>{$UserName}</big>, {$UserCountry}</p>')
                        : ('<p class="person" style="margin-top: 0px; margin-bottom: 0px;"><big>{$UserName}</big>, {$UserCountry}</p>')) +
                    '</div>' +
                '</li>'
        };

        self.load = function () {
            self.loadActivity();
            self.timeUpdater();
        };

        self.getKey = function (entry) {
            var key = entry.id + '_';
            if (self.options.donates) {
                key = entry.id + '_' + entry.ntime;
            }
            return key;
        };

        self.timeUpdater = function () {
            var updatetime = false;
            if (self.updater_time_id) {
                clearTimeout(self.updater_time_id);
                updatetime = true;
            }
            if (0 < self.QUEUE.length &&  true === updatetime) {
                self.updateOldEntry(1);
                self.updateOldEntryHTML();
            }
            self.updater_time_id = setTimeout(self.timeUpdater, 1200);
        };

        /**
        *   Function for remove data from array and update array length;
        *
        **/
        self.remove = function (list, index) {
            var i;
            for (i = index + 1; i < list.length; ++i) {
                list[i - 1] = list[i];
            }
            list.length--;
        };

        self.log = function (what, name) {
            if (!self.loggin) {
                return;
            }
            if (name) {
                console.log(' -- ' + name + ' -- ');
            }
            console.log(what);
        };

        /**
         *    function for load new data that came from ajax request
         */
        self.load_data = function () {
            var newEntry;
            if (empty(self.QUEUE)) {
                $('#petition-scroller > #loader').remove();
                self.loadActivityHTML(self.data, true);
                self.showNext();
            } else {
                newEntry = self.getNewEntry(self.data);
                self.entries_cnt = newEntry.length;
                self.QUEUE = self.setQUEUE(newEntry, self.QUEUE);
                self.loadActivityHTML(newEntry, false);
            }
        };

        /**
        *   Update html for one entry with new time
        *
        **/
        self.updateOneOldEntryHTML = function (user) {
            $('#prettytime_u_' + self.key + '_u_' + user.id).html(self.prettyDate(user.last_date));
        };

        /**
        *   Update html for entries with new time
        *
        **/
        self.updateOldEntryHTML = function () {
            var h;
            for (h in self.QUEUE) {
                self.updateOneOldEntryHTML(self.QUEUE[h]);
            }
        };

        /**
        *   Show list with slideshow effect
        **/
        self.showNext = function () {
            var $container, last, first, lastid, $first;
            if (self.shownext_timeout) {
                clearTimeout(self.shownext_timeout);
            }
            if (self.loaded_limit >= self.limit && false === self.static_height) {
                $container = $('#ua_container');
                if (3 < $container.height()) {
                    self.static_height = true;
                    $container.css({height: ($container.height() + 3) + 'px', overflow: 'hidden'});
                }
            }

            if (self.QUEUE.length > self.limit) {
                last = self.QUEUE.length - 1;
                first = self.QUEUE.length - self.limit - 1;
                lastid = self.QUEUE[last].id;
                $first = $('#activity_user_id_' + self.QUEUE[first].id);
                $first.addClass('first');
                $('#activity_user_id_' + self.QUEUE[first + 1].id).removeClass('first');
                self.QUEUE[first].last_date = 0;
                self.updateOneOldEntryHTML(self.QUEUE[first]);
                $first.slideDown(1000,
                    function () {
                        if (self.QUEUE.length > self.limit) {
                            $('#activity_user_id_' + lastid).remove();
                            self.remove(self.QUEUE, last);
                        }
                        self.shownext_timeout = setTimeout(self.showNext, 1500);
                    });
            } else {
                /*$('#petition-scroller > li.first').removeClass('first');
                $('#petition-scroller > li').first().addClass('first');*/
                self.shownext_timeout = setTimeout(self.showNext, 1500);
            }
        };
        /**
        *   Update time for old entries
        *
        *   time in seconds
        *
        **/
        self.updateOldEntry = function (time) {
            var h;
            for (h in self.QUEUE) {
                self.QUEUE[h].last_date = parseInt(self.QUEUE[h].last_date, 10) + parseInt((time || self.additional_time), 10);
            }
        };
        /**
        *   Get new entry that not loaded
        **/
        self.getNewEntry = function (entries) {
            var newentries = [],
                key,
                entry,
                h;
            for (h in entries) {
                entry = entries[h];
                key = self.getKey(entry);
                if (!self.loaded[key]) {
                    newentries.push(entry);
                }
            }
            return newentries;
        };
        /**
        *   Update queue with new entries
        **/
        self.setQUEUE = function (newdata, data) {
            var mdata = [], h;
            for (h in newdata) {
                mdata.push(newdata[h]);
            }
            for (h in data) {
                mdata.push(data[h]);
            }
            return mdata;
        };

        self.template = function (name, data) {
            var text = self.templates[name], i;
            if (undefined !== self.options.template && '' !== self.options.template) {
                text = tmpl(self.options.template, data);
            } else {
                if (typeof data === 'object') {
                    for (i in data) {
                        text = text.replace('{$' + i + '}', data[i]);
                    }
                }
            }
            return text;
        };

        /**
        *   Create html for entries on campaign page
        *
        **/
        self.getActivityHTML = function (data, first_load) {
            var html = '',
                key,
                index,
                user,
                h;
            if (true === first_load) {
                for (h = data.length; h > self.limit; h--) {
                    index = h - 1;
                    key = self.getKey(data[index]);
                    self.loaded[key] = true;
                    self.remove(data, index);
                    self.show_more_link = true;
                }
                self.initializeFull();
                self.initializeShowMoreLink();
            }
            for (h in data) {
                if ('function' === typeof data[h]) {
                    continue;
                }
                //if (self.loaded_limit >= self.limit && true === first_load) break;
                user = data[h];
                key = self.getKey(user);
                if (self.loaded[key]) {
                    continue;
                }
                if (true === first_load) {
                    self.QUEUE[h] = data[h];
                }
                self.loaded[key] = true;
                self.loaded_limit++;
                if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(user.name)) {
                    continue;
                }
                html += self.template('normal', {
                    ID : 'activity_user_id_' + user.id,
                    CC : String(user.cc).toLowerCase(),
                    'class' : ((1 === (h + 1) && true === first_load) ? ' class="first"' : ''),
                    style : (self.loaded_limit > self.limit ? ' style="display:none;"' : ''),
                    UserName : (user.name || 'Laila'),
                    UserCountry : (user.country || 'Afghanistan'),
                    PrettyTimeID : 'prettytime_u_' + self.key + '_u_' + user.id,
                    PrettyTime : self.prettyDate(user.last_date),
                    amount: self.number_format(user.amount, 0),
                    currency: self.getCurrency(user.currency || 'USD'),
                    message: user.message || ''
                });
            }
            if (html && self.loaded_limit > self.limit) {
                self.showMoreLink();
            }
            return html;
        };

        /**
        *   Create html for entries on front page
        *
        **/
        self.getActivityFUAHTML = function (data, first_load) {
            var html = '', key, user, index, h;
            if (true === first_load) {
                for (h = data.length; h > self.limit; h--) {
                    index = h - 1;
                    key = self.getKey(data[index]);
                    self.loaded[key] = true;
                    self.remove(data, index);
                }
            }
            for (h in data) {
                user = data[h];
                key = self.getKey(user);
                if (self.loaded[key]) {
                    continue;
                }
                if (true === first_load) {
                    self.QUEUE[h] = data[h];
                }
                self.loaded[key] = true;
                self.loaded_limit++;
                if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(user.name)) {
                    continue;
                }
                html += '<li id="activity_user_id_' + user.id + '"  style="' + (self.loaded_limit > self.limit ? 'display:none;' : '') + '"  class="' + ((1 === (h + 1) && true === first_load) ? ' first' : '') + '">';
                if (!self.rtl) {
                    html += '    <div class="time-ago" id="prettytime_u_' + self.key + '_u_' + user.id + '">' + self.prettyDate(user.last_date) + '</div>';
                    //html += '    <div class="flag"><img src="/new/images/blue/ua_flag_bg.png" width="27" height="31" alt="fr" style="background-image: url(/images/flags/' + (user.cc+'').toLowerCase() +'.gif); background-position:7px 7px;background-repeat: no-repeat;"/></div>';
                    html += '    <div class="flag">';
                    html += '       <div class="flag-place">';
                    html += '           <span class="flag-' + String(user.cc).toLowerCase() + ' user_activity_flag23x14"><img src="/images/spacer.gif" /></span><span class="ua-flag-overground"><img src="/images/spacer.gif" /></span>';
                    html += '       </div>';
                    html += '    </div>';
                    html += '    <div class="info">';
                    html += '        <p class="person"><big>' + (user.name || 'Laila') + '</big>, ' + (user.country || 'Afghanistan') + '</p>';
                    html += '        <p class="action"><a href="/' + (user.lang || 'en') + '/' + user.cn + '/?fpla">' + (empty(user.ct) ? user.cn.toLowerCase() : user.ct.toLowerCase()) + '</a></p>';
                    html += '    </div>';
                } else {
                    html += '    <div class="info">';
                    html += '        <p class="person"><big>' + (user.name || 'Laila') + '</big>, ' + (user.country || 'Afghanistan') + '</p>';
                    html += '        <p class="action"><a href="/' + (user.lang || 'en') + '/' + user.cn + '/?fpla">' + (empty(user.ct) ? user.cn.toLowerCase() : user.ct.toLowerCase()) + '</a></p>';
                    html += '    </div>';
                    //html += '    <div class="flag"><img src="/new/images/blue/flags/fr.png" width="29" height="35" alt="fr" style="background-image: url(/images/flags/' + (user.cc+'').toLowerCase() +'.gif); background-position:7px 7px;background-repeat: no-repeat;"/></div>';
                    html += '    <div class="flag">';
                    html += '       <div class="flag-place">';
                    html += '           <span class="flag-' + String(user.cc).toLowerCase() + ' user_activity_flag23x14"><img src="/images/spacer.gif" /></span><span class="ua-flag-overground"><img src="/images/spacer.gif" /></span>';
                    html += '       </div>';
                    html += '    </div>';
                    html += '    <div class="time-ago" id="prettytime_u_' + self.key + '_u_' + user.id + '">' + self.prettyDate(user.last_date) + '</div>';

                }

                html += '</li>';
                //html += '<li style="'+(self.loaded_limit > self.limit?'display:none;':'')+'" class="Comment ' + ((self.limit == (h + 1) && true === first_load)?' Last':'')+ '" id="activity_user_id_'+user.id+'" ><table celpadding="0" cellspacing="0" width="100%"><tr><td><img src="/images/spacer.gif" style="width:16px; height:11px;background-image: url(/images/flags/all-images.png); background-repeat: no-repeat;" class="'+ 'sprite-' + (user.cc+'').toLowerCase() +'"/>&nbsp;&nbsp;' + (user.name?user.name:'Laila') + ',&nbsp;<span style="font-size:11px; color:#6D6E70;">' + (user.country?user.country:'Afghanistan') + '</span></td><td><div style="text-align:right;"><em style="font-size:11px;" id="prettytime_u_'+self.key+'_u_'+user.id+'">' +self.prettyDate(user.last_date)+'</em></div></td></tr><tr><td colspan="2"><a style="padding-left:24px;" href="/'+(user.lang?user.lang:'en')+'/'+user.cn+'/?fpla">'+(empty(user.ct)?user.cn.toLowerCase():user.ct.toLowerCase())+'</a></td></tr></table></li>';

            }
            return html;
        };

        /**
        *    Add new entries on the page
        *
        **/

        self.loadActivityHTML = function (data, first_load) {
            var html = '';
            if ('fua' === self.type) {
                html = self.getActivityFUAHTML(data, first_load);
            } else {
                html = self.getActivityHTML(data, first_load);
            }
            if (!empty(html)) {
                $('#petition-scroller').prepend(html);
            }
        };

        self.sort_by_date = function (a, b) {
            var aa = parseInt(a.last_date, 10),
                bb = parseInt(b.last_date, 10);
            if (aa === bb) {
                return 0;
            }
            return (aa < bb) ? -1 : 1;
        };

        self.ajaxLoad = function (settings) {
            var default_data = (settings && settings.data) ? settings.data : {},
                data,
                options = $.extend({
                    timeout: true
                }, settings);

            if (options.timeout && self.ajax_timeout) {
                clearTimeout(self.ajax_timeout);
            }

            if (options.timeout && self.QUEUE.length > self.limit) {
                self.ajax_timeout = setTimeout(self.ajaxLoad, self.overload_time);
                return;
            }
            data = $.extend({cid: self.cid, lang: self.lang, uid: self.uid, /*time: self.one_user_time,*/
                type: self.type, upid: self.upid}, default_data);
            if (self.options.donates) {
                data.donates = 1;
            }
            $.ajax({
                url: '/act/get_user_activity.php',
                dataType: 'json',
                type: 'GET',
                data: data,
                success: function (data) {
                    if ('function' === typeof options.callback) {
                        data.sort(self.sort_by_date);
                        options.callback(data);
                        return 0;
                    }
                    self.one_user_time = self.one_user_time + self.additional_time;
                    if (data && !empty(data)) {
                        data.sort(self.sort_by_date);
                        if (data.disabled) {
                            self.showDisableActivity();
                        } else {
                            self.data = $.extend([], data);
                            self.load_data();
                            self.ajax_timeout = setTimeout(self.ajaxLoad, self.overload_time);
                        }
                    } else {
                        if (self.first_request) {
                            self.initializeShowMoreLink();
                            self.initializeEmpty();
                            self.first_request = false;
                        }
                        $('#petition-scroller > #loader').remove();
                        self.ajax_timeout = setTimeout(self.ajaxLoad, self.overload_time * 2);
                    }
                }
            });
        };

        self.scriptLoad = function () {
            if (self.ajax_timeout) {
                clearTimeout(self.ajax_timeout);
            }
            if ((self.QUEUE.length) > self.limit) {
                self.ajax_timeout = setTimeout(self.scriptLoad, 1500);
                return;
            }
            $.ajax({
                url: 'https://secure.avaaz.org/act/get_user_activity.php',
                dataType: 'jsonp',
                jsonpCallback: 'UserActivityCallback.dataLoader',
                type: 'GET',
                data: {cid: self.cid, lang: self.lang, uid: self.uid, /*time: self.one_user_time,*/ type: self.type}
            });
        };

        self.dataLoader = function (data) {
            self.one_user_time = self.one_user_time + self.additional_time;
            if (self.ajax_timeout) {
                clearTimeout(self.ajax_timeout);
            }
            if (data && !empty(data)) {
                if (data.disabled) {
                    self.showDisableActivity();
                } else {
                    data.sort(self.sort_by_date);
                    self.data = data;
                    self.load_data();
                    self.ajax_timeout = setTimeout(self.scriptLoad, (self.entries_cnt > self.limit) ? 1500 : self.overload_time);
                }
                $('script', 'head').filter(function () {
                    return (/act\/get_user_activity\.php/).test(this.src);
                }).each(function () {$(this).remove(); });
            } else {
                $('#petition-scroller > #loader').remove();
                self.ajax_timeout = setTimeout(self.ajaxLoad, self.overload_time * 2);
            }
        };

        self.loadActivity = function () {
            switch (self.load_type) {
            case 'ajax':
                self.ajaxLoad();
                break;
            case 'script':
                self.scriptLoad();
                break;
            }
        };
        /**
        * INSERT ELEMT INTO HEADER
        */
        self.insert = function (element) {
            (document.getElementsByTagName('HEAD')[0] || document.body).appendChild(element);
        };

        self.prettyDate = function (time) {
            if (undefined === time) {
                time = 0;
            }
            var date = new Date((time.toString() || "").replace(/-/g, "/").replace(/[TZ]/g, " ")),
                //diff = (((_self.calcTime('0')).getTime() - date.getTime()) / 1000),
                diff = parseInt(time, 10),
                day_diff = Math.floor(diff / 86400);
            if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) {
                return self.blurbs.PrettyTimeMonthAgo;
            }

            return (day_diff === 0 && (
                (diff < 5 && self.blurbs.PrettyTimeJustNow.replace("{time}", '<big>' + diff + '</big>')) ||
                    (diff < 60 && self.blurbs.PrettyTimeSecondsAgo.replace("{time}", '<big>' + diff + '</big>')) ||
                    (diff < 120 && self.blurbs.PrettyTimeMinuteAgo.replace("{time}", '<big>' + diff + '</big>')) ||
                    (diff < 3600 && self.blurbs.PrettyTimeMinutesAgo.replace("{time}", '<big>' + Math.floor(diff / 60) +
                        '</big>')) ||
                    (diff < 7200 && self.blurbs.PrettyTimeHourAgo) ||
                    (diff < 86400 &&
                        self.blurbs.PrettyTimeHoursAgo.replace("{time}", '<big>' + Math.floor(diff / 3600) +
                            '</big>'))
            )) ||
                (day_diff === 1 && self.blurbs.PrettyTimeYesterday) ||
                (day_diff < 7 && self.blurbs.PrettyTimeDaysAgo.replace("{time}", '<big>' + day_diff + '</big>')) ||
                (day_diff < 31 &&
                    self.blurbs.PrettyTimeWeeksAgo.replace("{time}", '<big>' + Math.ceil(day_diff / 7) + '</big>'));
        };

        self.initializeEmpty = function () {
            if (self.options.is_closed) {
                $('#' + self.load_id).hide();
            }
            $('.bd-la-control').hide();
            $('.bd-la-empty').show();
        };

        self.initializeFull = function () {
            $('.bd-la-empty').hide();
        };

        self.initializeShowMoreLink = function () {
            if (self.show_more_link) {
                self.showMoreLink();
            } else if (!self.show_more_link) {
                self.hideMoreLink();
            }
        };

        self.showMoreLink = function () {
            if (self.options.show_more) {
                $('.show-more-activity-container').show();
            }
        };

        self.hideMoreLink = function () {
            if (self.options.show_more) {
                $('.show-more-activity-container').hide();
            }
        };

        self.showMoreActivity = function () {
            var offset;
            clearTimeout(self.shownext_timeout);
            offset = $('li', '#ua_container').length;
            self.ajaxLoad({
                'data': {
                    'offset': offset,
                    limit: 5
                },
                timeout: false,
                callback: function (data) {
                    var h, user, html = '';
                    if (data.length < 5) {
                        self.hideMoreLink();
                    }
                    self.QUEUE = self.setQUEUE(self.QUEUE, data);
                    for (h in data) {
                        if ('function' === typeof data[h]) {
                            continue;
                        }
                        self.limit++;
                        self.loaded_limit++;
                        user = data[h];
                        html += self.template('normal', {
                            ID : 'activity_user_id_' + user.id,
                            CC : String(user.cc).toLowerCase(),
                            'class' : '',
                            style : '',
                            UserName : (user.name || 'Laila'),
                            UserCountry : (user.country || 'Afghanistan'),
                            PrettyTimeID : 'prettytime_u_' + self.key + '_u_' + user.id,
                            PrettyTime : self.prettyDate(user.last_date),
                            amount: self.number_format(user.amount, 0),
                            currency: self.getCurrency(user.currency || 'USD'),
                            message: user.message || ''
                        });
                    }
                    if (!empty(html)) {
                        $('#petition-scroller').append(html);
                        self.showNext();
                    }
                }
            });

        };
        self.addCommas = function (nStr) {
            var rgx, x, x1, x2;
            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        };
        self.getCurrency = function (currency) {
            if (self.options.currencies) {
                return self.options.currencies[currency].replace(currency + ' - ', '');
            }
            return '$';
        };
        self.number_format = function (number, decimals, dec_point, thousands_sep) {
            var n = number, prec = decimals, toFixedFix, sep, dec, s, abs, v, i, decPos;

            toFixedFix = function (n, prec) {
                var k = Math.pow(10, prec);
                return (Math.round(n * k) / k).toString();
            };

            n = !isFinite(+n) ? 0 : +n;
            prec = !isFinite(+prec) ? 0 : Math.abs(prec);
            sep = (undefined === thousands_sep) ? ',' : thousands_sep;
            dec = (undefined === dec_point) ? '.' : dec_point;

            s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;

            abs = toFixedFix(Math.abs(n), prec);

            if (abs >= 1000) {
                v = abs.split(/\D/);
                i = v[0].length % 3 || 3;

                v[0] = s.slice(0, i + (n < 0)) +
                    v[0].slice(i).replace(/(\d{3})/g, sep + '$1');
                s = v.join(dec);
            } else {
                s = s.replace('.', dec);
            }

            decPos = s.indexOf(dec);
            if (prec >= 1 && decPos !== -1 && (s.length - decPos - 1) < prec) {
                s += new Array(prec - (s.length - decPos - 1)).join(0) + '0';
            } else if (prec >= 1 && decPos === -1) {
                s += dec + new Array(prec).join(0) + '0';
            }
            return s;
        };
        /**************CONSTRUCTOR ACTION***************/
        window.UserActivityCallback = self;
        $('#' + self.load_id).data('LA', self);
        $(document).ready(function () {
            self.load();
            $('a.show-more-activity').click(function (e) {
                e.preventDefault();
                self.showMoreActivity();
            });
        });
        /*********END OF CONSTRUCTOR ACTION*************/
    };
}

/*  common/js/ZeroClipboard.js  */
// Simple Set Clipboard System
// Author: Joseph Huckaby

var ZeroClipboard = {

	version: "1.0.7",
	clients: {}, // registered upload clients on page, indexed by id
	moviePath: 'ZeroClipboard.swf', // URL to movie
	nextId: 1, // ID of next movie

	$: function(thingy) {
		// simple DOM lookup utility function
		if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
		if (!thingy.addClass) {
			// extend element with a few useful methods
			thingy.hide = function() { this.style.display = 'none'; };
			thingy.show = function() { this.style.display = ''; };
			thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
			thingy.removeClass = function(name) {
				var classes = this.className.split(/\s+/);
				var idx = -1;
				for (var k = 0; k < classes.length; k++) {
					if (classes[k] == name) { idx = k; k = classes.length; }
				}
				if (idx > -1) {
					classes.splice( idx, 1 );
					this.className = classes.join(' ');
				}
				return this;
			};
			thingy.hasClass = function(name) {
				return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
			};
		}
		return thingy;
	},

	setMoviePath: function(path) {
		// set path to ZeroClipboard.swf
		this.moviePath = path;
	},

	dispatch: function(id, eventName, args) {
		// receive event from flash movie, send to client
		var client = this.clients[id];
		if (client) {
			client.receiveEvent(eventName, args);
		}
	},

	register: function(id, client) {
		// register new client to receive events
		this.clients[id] = client;
	},

	getDOMObjectPosition: function(obj, stopObj) {
		// get absolute coordinates for dom element
		var info = {
			left: 0,
			top: 0,
			width: obj.width ? obj.width : obj.offsetWidth,
			height: obj.height ? obj.height : obj.offsetHeight
		};

		while (obj && (obj != stopObj)) {
			info.left += obj.offsetLeft;
			info.top += obj.offsetTop;
			obj = obj.offsetParent;
		}
		return info;
	},

	Client: function(elem) {
		// constructor for new simple upload client
		this.handlers = {};

		// unique ID
		this.id = ZeroClipboard.nextId++;
		this.movieId = 'ZeroClipboardMovie_' + this.id;

		// register client with singleton to receive flash events
		ZeroClipboard.register(this.id, this);

		// create movie
		if (elem) this.glue(elem);
	}
};

ZeroClipboard.Client.prototype = {

	id: 0, // unique ID for us
	ready: false, // whether movie is ready to receive events or not
	movie: null, // reference to movie object
	clipText: '', // text to copy to clipboard
	handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
	cssEffects: true, // enable CSS mouse effects on dom container
	handlers: null, // user event handlers

	glue: function(elem, appendElem, stylesToAdd) {
        var addedStyle;
		// glue to DOM element
		// elem can be ID or actual DOM element object
		this.domElement = ZeroClipboard.$(elem);

		// float just above object, or zIndex 99 if dom element isn't set
		var zIndex = 99;
		if (this.domElement.style.zIndex) {
			zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
		}

		if (typeof(appendElem) === 'string') {
			appendElem = ZeroClipboard.$(appendElem);
		}
		else if (appendElem === undefined) {
			appendElem = document.getElementsByTagName('body')[0];
		}

        this.appendElem = appendElem;

		// find X/Y position of domElement
		var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
		// create floating DIV above element
		this.div = document.createElement('div');
		var style = this.div.style;
		style.position = 'absolute';
		style.left = '' + box.left + 'px';
		style.top = '' + box.top + 'px';
		style.width = '' + box.width + 'px';
		style.height = '' + box.height + 'px';
		style.zIndex = zIndex;

		if (typeof(stylesToAdd) === 'object') {
			for (addedStyle in stylesToAdd) {
				style[addedStyle] = stylesToAdd[addedStyle];
			}
		}

		// style.backgroundColor = '#f00'; // debug

		appendElem.appendChild(this.div);

		this.div.innerHTML = this.getHTML( box.width, box.height );
	},

	getHTML: function(width, height) {
		// return HTML for movie
		var html = '';
		var flashvars = 'id=' + this.id +
			'&width=' + width +
			'&height=' + height;

		if (navigator.userAgent.match(/MSIE/)) {
			// IE gets an OBJECT tag
			var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
			html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
		}
		else {
			// all other browsers get an EMBED tag
			html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
		}
		return html;
	},

	hide: function() {
		// temporarily hide floater offscreen
		if (this.div) {
			this.div.style.left = '-2000px';
		}
	},

	show: function() {
		// show ourselves after a call to hide()
		this.reposition();
	},

	destroy: function() {
		// destroy control and floater
		if (this.domElement && this.div) {
			this.hide();
			this.div.innerHTML = '';

			var body = document.getElementsByTagName('body')[0];
			try { body.removeChild( this.div ); } catch(e) {;}

			this.domElement = null;
			this.div = null;
		}
	},

	reposition: function(elem) {
		// reposition our floating div, optionally to new container
		// warning: container CANNOT change size, only position
		if (elem) {
			this.domElement = ZeroClipboard.$(elem);
			if (!this.domElement) this.hide();
		}

		if (this.domElement && this.div) {
			var box = ZeroClipboard.getDOMObjectPosition(this.domElement, this.appendElem);
			var style = this.div.style;
			style.left = '' + box.left + 'px';
			style.top = '' + box.top + 'px';
            style.width = '' + box.width + 'px';
            style.height = '' + box.height + 'px';
            this.div.innerHTML = this.getHTML( box.width, box.height );
		}
	},

	setText: function(newText) {
		// set text to be copied to clipboard
		this.clipText = newText;
		if (this.ready) this.movie.setText(newText);
	},

	addEventListener: function(eventName, func) {
		// add user event listener for event
		// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');
		if (!this.handlers[eventName]) this.handlers[eventName] = [];
		this.handlers[eventName].push(func);
	},

	setHandCursor: function(enabled) {
		// enable hand cursor (true), or default arrow cursor (false)
		this.handCursorEnabled = enabled;
		if (this.ready) this.movie.setHandCursor(enabled);
	},

	setCSSEffects: function(enabled) {
		// enable or disable CSS effects on DOM container
		this.cssEffects = !!enabled;
	},

	receiveEvent: function(eventName, args) {
		// receive event from flash
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');

		// special behavior for certain events
		switch (eventName) {
			case 'load':
				// movie claims it is ready, but in IE this isn't always the case...
				// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
				this.movie = document.getElementById(this.movieId);
				if (!this.movie) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 1 );
					return;
				}

				// firefox on pc needs a "kick" in order to set these in certain cases
				if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 100 );
					this.ready = true;
					return;
				}

				this.ready = true;
                try {
                    this.movie.setText( this.clipText );
                    this.movie.setHandCursor( this.handCursorEnabled );
                } catch (e) {
                    //silently skip IE8 error
                    // Upgrade ZeroClipboard to latest version
                    // Remove this if the STO Wizard layout + DM does not pass tests
                }


				break;

			case 'mouseover':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('hover');
					if (this.recoverActive) this.domElement.addClass('active');
				}
				break;

			case 'mouseout':
				if (this.domElement && this.cssEffects) {
					this.recoverActive = false;
					if (this.domElement.hasClass('active')) {
						this.domElement.removeClass('active');
						this.recoverActive = true;
					}
					this.domElement.removeClass('hover');
				}
				break;

			case 'mousedown':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('active');
				}
				break;

			case 'mouseup':
				if (this.domElement && this.cssEffects) {
					this.domElement.removeClass('active');
					this.recoverActive = false;
				}
				break;
		} // switch eventName

		if (this.handlers[eventName]) {
			for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
				var func = this.handlers[eventName][idx];

				if (typeof(func) == 'function') {
					// actual function reference
					func(this, args);
				}
				else if ((typeof(func) == 'object') && (func.length == 2)) {
					// PHP style object + method, i.e. [myObject, 'myMethod']
					func[0][ func[1] ](this, args);
				}
				else if (typeof(func) == 'string') {
					// name of function
					window[func](this, args);
				}
			} // foreach event handler defined
		} // user defined handler for event
	}

};

/*  common/js/Share.js  */
if (!window.share_data) {
    window.share_data = {};
}
if (!window.Share) {
    Share = {
        event_id: 0,
        results: {},
        URLdata: [],
        shareCallback: [],
        petition_id: false,
        resetUrls: function () {
            this.urls = {};
            this.urlsA = [];
        },
        addQS: function (d, c) {
            var a = [];
            for (var b in c) if (c[b]) a.push(b.toString() + '=' + encodeURIComponent(c[b]));
            return d + '?' + a.join('&');
        },
        getUrl: function (a) {
            return a.getAttribute('share_url') || window.location.href;
        },
        getType: function (a) {
            return a.getAttribute('type') || 'button_count';
        },
        pretty: function (a) {
            return a >= 1e+07 ? Math.round(a / 1e+06) + 'M' : (a >= 10000 ? Math.round(a / 1000) + 'K' : a);
        },
        updateButton: function (a) {
            var cid = $(a).attr('sharecid');
            var type = $(a).attr('sharetype');
            for (h in this.results[cid]) {
                if (this.results[cid]) {
                    a[type + '_count'] = this.results[cid][type + '_count'];
                } else {
                    a[type + '_count'] = 0;
                }
                this.displayBox(a, 0);
            }

        },
        getWindowInnerSize: function () {
            var width = 0;
            var height = 0;
            var elem = null;
            if ('innerWidth' in window) {
                // For non-IE
                width = window.innerWidth;
                height = window.innerHeight;
            } else {
                // For IE,
                if (('BackCompat' === window.document.compatMode)
                    && ('body' in window.document)) {
                    elem = window.document.body;
                } else if ('documentElement' in window.document) {
                    elem = window.document.documentElement;
                }
                if (elem !== null) {
                    width = elem.offsetWidth;
                    height = elem.offsetHeight;
                }
            }
            return [width, height];
        },
        getParentCoords: function () {
            var width = 0;
            var height = 0;
            if ('screenLeft' in window) {
                // IE-compatible variants
                width = window.screenLeft;
                height = window.screenTop;
            } else if ('screenX' in window) {
                // Firefox-compatible
                width = window.screenX;
                height = window.screenY;
            }
            return [width, height];
        },
        getCenteredCoords: function (width, height) {
            var parentSize = this.getWindowInnerSize();
            var parentPos = this.getParentCoords();
            var xPos = parentPos[0] +
                Math.max(0, Math.floor((parentSize[0] - width) / 2));
            var yPos = parentPos[1] +
                Math.max(0, Math.floor((parentSize[1] - height) / 2));
            return [xPos, yPos];
        },
        displayBox: function (a, d) {
            var type = $(a).attr('sharetype');
            if (typeof(a[type + '_count']) == 'number' && a[type + '_count'] >= d) {
                $('.' + $(a).attr('sharetype') + '_share_counter_' + $(a).attr('sharecid')).each(function () {
                    $(this).html(Share.pretty(a[type + '_count']))
                });
            }
        },
        addEvent: function (href) {
            if ('undefined' !== typeof rsvp_event_id) {
                return href + '&id=' + rsvp_event_id + '';
            }
            return href;
        },
        renderButton: function (c) {
            var bIsMobile = (window.bIsMobile != undefined) ? window.bIsMobile : false;
            var cid = $(c).attr('sharecid');
            var type = $(c).attr('sharetype');
            var lang = $(c).attr('sharelang');
            var href = $(c).attr('href');
            var method = $(c).attr('sharemethod');
            if (!method || bIsMobile) {
                method = 'stream.publish';
            }
            /***************************FACEBOOK**************************/
            var global_response = null;

            var stream_callback = function (post) {
                $(document).facebookReady(function () {
                    FB.getLoginStatus(
                        function (response) {
                            if (response.session) {
                                //login_response(response);
                                var a = document.createElement('script');
                                if ('undefined' !== typeof post && null !== post && post.post_id) {
                                    var send_data = {
                                        action: 'save_share_counter',
                                        cid: cid,
                                        lang: lang,
                                        random: Math.random(),
                                        value: 'shared',
                                        fb_uid: response.session.uid
                                    };
                                    if (Share.petition_id) {
                                        send_data.petition_id = Share.petition_id;
                                    }
                                    a.src = Share.addQS('/act/facebook.php', send_data);
                                } else {
                                    var send_data = {
                                        action: 'save_share_counter',
                                        cid: cid,
                                        lang: lang,
                                        random: Math.random(),
                                        value: 'closed',
                                        fb_uid: response.session.uid
                                    };
                                    if (Share.petition_id) {
                                        send_data.petition_id = Share.petition_id;
                                    }
                                    a.src = Share.addQS('/act/facebook.php', send_data);
                                }
                                Share.insert(a);
                                if ('undefined' !== typeof post && null !== post && post.post_id) {
                                    Share.updateHiddenCounter(c, 'shared', { fb_uid: response.session.uid });
                                } else {
                                    Share.updateHiddenCounter(c, 'closed', { fb_uid: response.session.uid });
                                }
                            } else {
                                //FB.login(login_response);
                            }
                        }
                    );
                });
            };
            var facebook_click = function (e) {
                var $el = $(this);
                e.preventDefault();
                $('body').trigger('sharing_started');
                Share.updateCounter(c);

                var login_response = function (response) {
                    if (response.session) {
                        Share.updateHiddenCounter(c, 'user_clicked', { fb_uid: response.session.uid });
                        global_response = response;
                    }
                };

                var condition =
                    ('stream.dm' === method || 'stream.fbdm' === method || 'stream.taggingdm' === method) &&
                        (typeof($.fn.FBTagFriendsWidget) == 'function');
                if (condition) {
                    var options = {sMethod: method};
                    if (!window.oFBTagWidget) {
                        if ($el.data('title')) {
                            $('#dialogTagFBFriendsTitle').html($el.data('title'));
                        }
                        if ($el.data('description')) {
                            $('#dialogTagFBFriendsText').html($el.data('description'));
                        }

                        // check if scope was provided let's use it
                        if ($el.data('scope') !== undefined) {
                            options.scope = $el.data('scope');
                        }

                        window.oFBTagWidget = $('div#dialogTagFBFriends').FBTagFriendsWidget(options);
                    }
                    var fbdm_options = $el.data('fbdm_options');
                    if (fbdm_options) {
                        window.oFBTagWidget.init_new_form(fbdm_options);
                    }
                    window.oFBTagWidget.process(null, cid);
                } else {
                    $(document).facebookReady(function () {
                        FB.getLoginStatus(
                            function (response) {
                                share_data[cid].facebook.href = Share.addEvent(share_data[cid].facebook.href);

                                var fb_object = {
                                    display: 'popup',
                                    method: method,//'stream.publish',
                                    attachment: $.extend({}, share_data[cid].facebook),
                                    action_links: share_data[cid].facebook.action_links
                                };

                                if ($el.data('custom_fb_wall_url') && method === 'stream.publish') {
                                    fb_object.attachment.href = $el.data('custom_fb_wall_url');
                                }

                                if ('stream.share' === method) {
                                    fb_object.u = share_data[cid].facebook.href;
                                    fb_object.t = share_data[cid].facebook.name;
                                    fb_object.attachment = '';
                                    fb_object.action_links = '';
                                }
                                if (fb_object.attachment) {
                                    if ($el.data('title')) {
                                        fb_object.attachment.name = $el.data('title');
                                    }
                                    if ($el.data('description')) {
                                        fb_object.attachment.description = $el.data('description');
                                    }
                                }

                                if (response.session) {
                                    login_response(response);
                                    if (share_data[cid].facebook.status && '' !== share_data[cid].facebook.status) {
                                        fb_object.message = share_data[cid].facebook.status;
                                    }
                                    FB.ui(
                                        fb_object,
                                        stream_callback
                                    );
                                } else {

                                    if ($.browser['msie']) {
                                        //fb_object.display = '';
                                        //FB.login(function(){
                                        FB.ui(
                                            fb_object,
                                            stream_callback
                                        );
                                        //});
                                    } else {
                                        FB.ui(
                                            fb_object,
                                            stream_callback
                                        );

                                    }
                                }
                            }
                        );
                    });

                    Share.displayBox(this, 1);

                    $('body').trigger('sharing_complete');

                    return false;
                }
            };

            /***********************END OF FACEBOOK***********************/

            /***************************ORKUT ****************************/
            var orkut_click = function () {
                $('body').trigger('sharing_started');

                Share.updateCounter(c);
                window.open(decodeURIComponent(Share.addEvent(share_data[cid].orkut.href)), "orkutwindow", "status=1,toolbar=1,height=650,width=1024");

                $('body').trigger('sharing_complete');

                return false;
            };
            /************************END OF ORKUT*************************/

            /****************************TUMBLR***************************/
            var tumblr_click = function () {
                $('body').trigger('sharing_started');

                Share.updateCounter(c);
                var coordinates = Share.getCenteredCoords(500, 420);
                window.open('http://www.tumblr.com/share/link?url=' + Share.addEvent(share_data[cid].tumblr.href) + '&name=' + share_data[cid].tumblr.text + '&description=' + share_data[cid].tumblr.description, "tweetwindow", "status=1,toolbar=1,height=420,width=500" + ",left=" + coordinates[0] + ",top=" + coordinates[1]);

                $('body').trigger('sharing_complete');
                return false;
            };
            /************************END OF TUMBLR*************************/

            /****************************TWITTER ***************************/
            var twitter_click = function () {
                $('body').trigger('sharing_started');

                Share.updateCounter(c);
                var coordinates = Share.getCenteredCoords(500, 350);
                var sWindowUrl = 'http://twitter.com/share?related=Avaaz&url=' + Share.addEvent(share_data[cid].twitter.href) + '&text=' + encodeURIComponent(share_data[cid].twitter.text) /*decodeURIComponent(j)*/;

                if (typeof(sRetweetUrl) != 'undefined') {
                    sWindowUrl = sRetweetUrl;
                }


                window.open(sWindowUrl, "tweetwindow", "status=1,toolbar=1,height=350,width=500" + ",left=" + coordinates[0] + ",top=" + coordinates[1]);

                $('body').trigger('sharing_complete');
                return false;
            };
            /************************END OF TWITTER*************************/

            /*************************** VK ****************************/
            var vk_click = function () {
                Share.updateCounter(c);
                window.open(decodeURIComponent(Share.addEvent(share_data[cid].vk.href)), "vkwindow", "status=1,toolbar=1,height=650,width=1024");
                return false;
            };
            /************************END OF VK*************************/

            var isValidSelector = function (selector) {
                try {
                    var $element = $(selector);
                } catch(error) {
                    return false;
                }
                return ($element.length > 0);
            }

            /****************************EMAIL ***************************/
            var email_click = function () {

                $('body').trigger('sharing_started');

                Share.updateCounter(c);
                if (!c.email_clicked) {
                    c.email_count += 1;
                    c.email_clicked = true;
                }

                var bStats = true;
                if ($(this).data('stats')) {
                    bStats = !!$(this).data('stats');
                }

                var sSubject = $(this).data('subject');
                if (sSubject !== undefined) {
                    if (isValidSelector(sSubject)) {
                        sSubject = $(sSubject).val();
                    }
                } else {
                    sSubject = '';
                }

                var sBody = $(this).data('body');
                if (sBody !== undefined) {
                    if (isValidSelector(sBody)) {
                        sBody = $(sBody).val();
                    }
                } else {
                    sBody = '';
                }


                var domain = GetEmailDomain();
                var mailto = true;
                domain = domain && !$(c).data('mobile') ? domain : 'other';

                sBody = getEdgeData({event: (('undefined' !== typeof rsvp_event_id) ? 'id=' + rsvp_event_id : '')}, (sBody !== '' ? sBody : share_data[cid].email.body));
                sBody = $('<textarea />').html(sBody).text();

                switch (domain) {
                    case 'gmail':
                        mailto = false;
                        href = Share.addQS('https://mail.google.com/mail/', {
                            view: 'cm',
                            fs: 1,
                            to: '',
                            su: sSubject !== '' ? sSubject : share_data[cid].email.subject,
                            body: sBody,
                            ui: 2,
                            shva: 1
                        });
                        break;
                    default:
                        href = Share.addQS('mailto:', {
                            subject: sSubject !== '' ? sSubject : share_data[cid].email.subject,
                            body: sBody
                        });
                        break;
                }
                var send_data = {campaign_id: cid, domain: domain};
                if (Share.petition_id) {
                    send_data.petition_id = Share.petition_id;
                }
                if (bStats) {
                    jQuery.post('/act/ajax_send_stats.php', send_data, function () {
                    });
                }

                Share.displayBox(this, 1);
                $('body').trigger('sharing_complete');

                if (!mailto) {
                    window.open(href, "emailwindow", "status=1,toolbar=1,height=650,width=1024");
                } else {
                    $(c).attr('target', '_blank');
                    $(c).attr('href', href);
                    return true;
                }

                return false;
            };
            var email_popup = null;
            var email_click_popup = function () {

                var bStats = true;
                if ($(this).data('stats')) {
                    bStats = !!$(this).data('stats');
                }
                var domain = GetEmailDomain();
                if (!c.email_clicked) {
                    c.email_count += 1;
                    c.email_clicked = true;
                    var send_data = {campaign_id: cid, domain: domain};
                    if (Share.petition_id) {
                        send_data.petition_id = Share.petition_id;
                    }
                    if (bStats) {
                        jQuery.post('/act/ajax_send_stats.php', send_data, function () {
                        });
                    }
                }
                if (email_popup) {
                    email_popup.trigger('click');
                } else {
                    if (!window.colorbox_dialogs) {
                        colorbox_dialogs = {};
                    }
                    colorbox_dialogs.email_popup = $.colorbox(
                        {
                            opacity: 0.5,
                            inline: true,
                            href: "#" + $(c).attr('use_popup'),
                            showClose: ('undefined' !== typeof $(c).data('showclose') ? $(c).data('showclose') : true),
                            onClosed: function () {
                                openid.closeColorbox();
                            },
                            onComplete: function () {
                                $(this).colorbox.resize();
                            }
                        });
                }
                //$(c).attr('href', href);
                Share.displayBox(this, 1);
                return false;
            }
            /************************END OF EMAIL*************************/
            if (type != 'email')
                $(c).click(function () {
                    return false;
                }); // fix for IE redirect
            if (share_data[cid] && share_data[cid][type]) {
                switch (type) {
                    case 'facebook':
                        /****************** ADD FACEBOOK SHARE URL ******************/
                        $(c).attr('href', this.addQS('http://www.avaaz.org/act/facebook_share.php', {
                            cid: cid,
                            lang: lang,
                            src: 'sp'
                        }));
                        $(c).click(facebook_click);
                        /************************************************************/
                        break;
                    case 'orkut':
                        /****************** ADD ORKUT SHARE URL ******************/
                        $(c).attr('href', share_data[cid].orkut.href);

                        $(c).click(orkut_click);
                        /************************************************************/
                        break;
                    case 'tumblr':
                        /****************** ADD TUMBLR SHARE URL ******************/
                        $(c).attr('href', 'http://www.tumblr.com/share/link?url=' + share_data[cid].tumblr.href + '&name=' + share_data[cid].tumblr.text + '&description=' + share_data[cid].tumblr.description);
                        $(c).click(tumblr_click);
                        /************************************************************/
                        break;
                    case 'twitter':
                        /****************** ADD TWITTER SHARE URL ******************/
                        $(c).attr('href', 'http://twitter.com/share?related=Avaaz&url=' + share_data[cid].twitter.href + '&text=' + share_data[cid].twitter.text);
                        $(c).click(twitter_click);
                        /************************************************************/
                        break;
                    case 'email':
                        /****************** ADD EMAIL SHARE URL ******************/
                        $(c).attr('href', 'javascript:void(0);');

                        $(c).click(function (e) {
                            if (!window.useContactImporter || window.isContactImporterV1) {
                                if ($(this).attr('use_popup')) {
                                    e.preventDefault();
                                    return email_click_popup.apply(this);
                                } else {
                                    return email_click.apply(this);
                                }
                            }
                        });

                        /************************************************************/
                        break;
                    case 'vk':
                        /****************** ADD VK SHARE URL ******************/
                        $(c).attr('href', share_data[cid].vk.href);
                        $(c).click(vk_click);
                        /************************************************************/
                        break;
                }
            }
            c.fb_rendered = true;
        },
        insert: function (a) {
            (document.getElementsByTagName('HEAD')[0] || document.body).appendChild(a);
        },
        renderAll: function () {
            $('.share').filter(function () {
                return ('undefined' === typeof $(this).attr('sharetype') ? false : true);
            }).each(function (i) {
                Share.URLdata[i] = this;
            });
            var c = Share.URLdata;
            var a = c.length;
            for (var b = 0; b < a; b++) {
                if (!c[b].fb_rendered && $(c[b]).hasClass('janrain-share') === false) {
                    this.renderButton(c[b]);
                }
                if (this.results[$(c[b]).attr('sharecid')]) this.updateButton(c[b]);
            }
        },
        fetchData: function () {
            var data = {};
            for (var h in Share.URLdata) {
                if ('function' === typeof Share.URLdata[h])
                    continue;
                var link = Share.URLdata[h];
                var type = $(link).attr('sharetype');
                var cid = $(link).attr('sharecid');
                if (share_data[cid]) {
                    if ('undefined' === typeof data[cid]) {
                        data[cid] = {};
                    }
                    if ('undefined' === typeof data[cid]['type']) {
                        data[cid]['type'] = {};
                    }
                    data[cid]['type'][type] = 1;
                    /** ADDON FOR PETITIONS ***/
                    if (share_data[cid].petition) {
                        Share.petition_id = share_data[cid].petition;
                    }
                }
            }
            var send_data = {
                v: '1.0',
                action: 'get_share_count',
                format: 'json',
                data: data
            };
            if (Share.petition_id) {
                send_data.petition_id = Share.petition_id;
            }
            this.resetUrls();

            $.ajax(
                {
                    url: '/act/share_stats.php?' + $.param(send_data),
                    type: 'GET',
                    dataType: 'json',
                    success: function (data) {
                        if (data)
                            share_render(data);
                    }
                }
            );
        },
        runShareCallback: function (type) {
            for (var i = 0; i <= Share.shareCallback.length; i++) {
                if ('function' === typeof Share.shareCallback[i]) {
                    Share.shareCallback[i](type);
                }
            }
        },
        updateCounter: function (el) {
            el = $(el);
            if (Share.updateHiddenCounter(el, 'clicked', {})) {
                var elShareButton = el[0];
                var sType = $(elShareButton).attr('sharetype');
                if ($.inArray(sType, ['twitter', 'tumblr', 'orkut', 'email', 'vk']) != -1) {
                    if (!elShareButton[sType + '_clicked']) {
                        elShareButton[sType + '_count'] += 1;
                        elShareButton[sType + '_clicked'] = true;
                    }
                } else {
                    if (sType == 'facebook') {
                        if (!elShareButton['fb_clicked']) {
                            elShareButton['facebook_count'] += 1;
                            elShareButton['fb_clicked'] = true;
                        }
                    }
                }
                Share.displayBox(elShareButton, 1);
                Share.runShareCallback(sType);
            }
        },
        updateHiddenCounter: function (el, sAction, oExtras) {
            var iCid = $(el).attr('sharecid');
            var sType = $(el).attr('sharetype');
            var sLang = $(el).attr('sharelang');
            if (iCid && sType && sLang) {
                if (sType == 'email') {
                    return Share.updateEmailCounter(el);
                } else {
                    var oSendData = {
                        action: 'save_share_counter',
                        cid: iCid,
                        lang: sLang,
                        random: Math.random(),
                        value: sAction
                    };
                }
                if (Share.petition_id) {
                    oSendData.petition_id = Share.petition_id;
                }
                $.extend(oSendData, oExtras);
                var sclick = document.createElement('script');
                var sUpdateScripts = {
                    email: 'ajax_send_stats',
                    facebook: 'facebook',
                    twitter: 'twitter',
                    tumblr: 'tumblr',
                    orkut: 'orkut',
                    vk: 'vkontakte'
                };
                if (typeof sUpdateScripts[sType] !== 'undefined') {
                    sclick.src = Share.addQS('/act/' + sUpdateScripts[sType] + '.php', oSendData);
                    Share.insert(sclick);
                    return true;
                }
            }
            return false;
        },
        updateEmailCounter: function (el) {
            var bStats = true;
            if ($(el).data('stats')) {
                bStats = !!$(el).data('stats'); // convert to boolean
            }
            if (bStats) {
                var sDomain = GetEmailDomain();
                sDomain = sDomain && !$(el).data('mobile') ? sDomain : 'other';
                oSendData = {
                    campaign_id: $(el).attr('sharecid'),
                    domain: sDomain
                };
                if (Share.petition_id) {
                    oSendData.petition_id = Share.petition_id;
                }
                $.post('/act/ajax_send_stats.php', oSendData);
                return true;
            }
            return false;
        },
        renderPass: function () {
            Share.renderAll();
            if (Share.URLdata.length > 0) {
                Share.fetchData();
            }
        },
        _onFirst: function () {
            this.resetUrls();
            window.share_render = function (b) {
                for (var h in b) Share.results[h] = b[h];
                Share.renderAll();
            };
            this.renderPass();
        },
        init: function () {
            if (typeof bDoNotRunShare === 'undefined' || !bDoNotRunShare) {
                Share._onFirst();
            }
        }
    };
    $(document).ready(function () {
        Share.init();
    });
}

/*  new/common/js/async_done.js  */
function async_load_function() {
    if (typeof(async_load) != 'undefined' && async_load) {
	var func = async_load.pop();
	while (func) {
	    func();
	    func = async_load.pop();
	};
    }
    setTimeout(async_load_function,1000);
};
async_load_function();
