Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/webroot/js/addons.js
blob: 6da858bd614aa0f7381a79839a2e4a03ed47b295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
/* Addons display js */
var gPlatform = PLATFORM_WINDOWS;
var gLatestVersionID = null; //latest version ID of any compatible addon for versions page.
var gLatestAddonVersion = null; //addon version of latest compatible addon for versions page.
var gLatestAppVersion = null; //application version of latest compatible addon for versions page.

var PLATFORM_OTHER    = 0;
var PLATFORM_WINDOWS  = 1;
var PLATFORM_LINUX    = 2;
var PLATFORM_MACOSX   = 3;
var PLATFORM_MAC      = 4;

if (navigator.platform.indexOf("Win32") != -1)
  gPlatform = PLATFORM_WINDOWS;
else if (navigator.platform.indexOf("Linux") != -1)
  gPlatform = PLATFORM_LINUX;
else if (navigator.userAgent.indexOf("Mac OS X") != -1)
  gPlatform = PLATFORM_MACOSX;
else if (navigator.userAgent.indexOf("MSIE 5.2") != -1)
  gPlatform = PLATFORM_MACOSX;
else if (navigator.platform.indexOf("Mac") != -1)
  gPlatform = PLATFORM_MAC;
else
  gPlatform = PLATFORM_OTHER;

function getPlatformName()
{
  if (gPlatform == PLATFORM_WINDOWS)
    return "Windows";
  if (gPlatform == PLATFORM_LINUX)
    return "Linux";
  if (gPlatform == PLATFORM_MACOSX)
    return "MacOSX";
  return "Unknown";
}

function getInstallURL(aEvent) {
    // The event target might be the link itself or one of its children
    var target = aEvent.target;
    while (target && !target.href)
      target = target.parentNode;
    
    return target && target.href;
}

function checkMatchUserAgentAppId() {
    var uapattern = /(?:Firefox|Minefield|Shiretoko|GranParadiso|BonEcho|Iceweasel)/;
    var ua = navigator.userAgent;
    var uamatch = uapattern.exec(ua);
	
    if( uamatch !=null && APP_ID == 1)	return true;

    uapattern = /(SeaMonkey|Iceape)/;
    ua = navigator.userAgent;
    uamatch = uapattern.exec(ua);
    if( uamatch !=null && APP_ID == 59) return true;
	
    return false;

}

/**
 * Install an add-on into the current browser-type application
 * (mostly: Firefox, SeaMonkey)
 */
function install( aEvent, extName, iconURL, extHash)  { 

    if (aEvent.altKey || !window.InstallTrigger || !checkMatchUserAgentAppId())
        return true;

    var url = getInstallURL(aEvent);

    if (url) {

        var params = new Array();

        params[extName] = {
            URL: url,
            IconURL: iconURL,
            toString: function () { return this.URL; }
        };

        // Only add the Hash param if it exists.
        //
        // We optionally add this to params[] because installTrigger
        // will still try to compare a null hash as long as the var is set.
        if (extHash) {
            params[extName].Hash = extHash;
        }

        InstallTrigger.install(params);

        return false;
    }
    return true;
}

/**
 * Install a search engine (opensearch)
 * Returns false in case of success (sic!) because that will keep the file link
 * from being followed.
 */
function addEngine(engineURL) { 	 
    if (window.external && ("AddSearchProvider" in window.external)) {
        window.external.AddSearchProvider(engineURL);
        return false;
    } else { 	 
        alert(error_opensearch_unsupported);
        return true;
    } 	 
} 	 

/**
 * Detect which install button should show, and hide the rest
 */
function fixPlatformLinks(versionID, name) {
    if (gPlatform == PLATFORM_OTHER) return true; // only hide something if we were able to detect platforms
    var platform = getPlatformName();
    var outer = $("#install-"+ versionID);
    var installs = outer.find("p.install-button");
    
    // hide incompatible installs
    var others = installs.not(".platform-ALL,.platform-"+platform);
    others.hide();
    
    if (installs.length == others.length) {
        outer.append($('<p class="not-avail"></p>').append(sprintf(addOnNotAvailableForPlatform, name, platform)));
    }

    return true;
}

/**
*   Used to select between the string Add to App and Download depending on whether Firefox is the UA
*/
function installVersusDownloadCheck(triggerID, installString, downloadString)
{
    var buttonMessage = installString;
    var uapattern = /Mozilla.*(Firefox|Minefield|Shiretoko|GranParadiso|BonEcho|SeaMonkey|Iceweasel|Iceape)\/.*$/;
    var ua = navigator.userAgent;
    var uamatch = uapattern.exec(ua);
    if (!uamatch || uamatch.length < 2 || !checkMatchUserAgentAppId()) // not a Firefox-like browser
        buttonMessage = downloadString;
    $("#" + triggerID + " strong").text(buttonMessage);
}

/**
 * Provide hints on install buttons for add-ons incompatible with the
 * currently used browser. 
 *
 * It has the side-effect that the first time it is called on a page and doesn't need to add hints, it will
 * set gLatestVersion to the passed versionID
 *
 * @param int addonID
 * @param int versionID
 * @param string fromVer minimum compatible Firefox version
 * @param string toVer maximum compatible Firefox version
 * @param bool showVersionLink offer a link to the user which will remove the compatibility hint (and allow them to download the add-on)
 * @param bool versionsPage whether the user is viewing /addons/versions/$id .  Why is this here instead of just not calling 
 *              addCompatibilityHints() if we don't want it in /views/addons/versions.thtml?
 */
function addCompatibilityHints(addonID, versionID, fromVer, toVer, showVersionLink, versionsPage) {
    var uapattern = /Mozilla.*(?:Firefox|Minefield|Shiretoko|GranParadiso|BonEcho|Iceweasel)\/([^\s]*).*$/;
    var ua = navigator.userAgent;
    var uamatch = uapattern.exec(ua);
    if (!uamatch || uamatch.length < 2) return true;

    var outer = $("#install-"+ versionID);

    var version = uamatch[1];
    var vc = new VersionCompare();
    if (vc.compareVersions(version, fromVer)<0)
        var needUpgrade = true;
    else if(vc.compareVersions(version, toVer)>0)
        var needUpgrade = false;
    else { //check if this is the first time on the page we have a platform and version compatitble addon
        if( gLatestVersionID == null) {
            var installs = outer.find("p.install-button");			
            if (installs.find(".platform-ALL") || installs.find(".platform-"+gPlatform)) {
                gLatestVersionID = versionID;
			    var tmpAddonVersion = outer.prev().prev().prev();
			    gLatestAddonVersion = tmpAddonVersion.clone();
			    gLatestApplicationVersion = version;
		    }
		}
        return true;
	}

    if(versionsPage) return true;

    var links = outer.find("p:visible a"); // find visible install boxes
    if (links.length == 0) return true; // nothing to do
    
    // duplicate button and hide original (to be able to restore it later)
    var cloned = outer.clone();
    cloned.attr('id', 'orig-'+ versionID);
    cloned.hide();
    outer.after(cloned);
    
    // gray out button
    var mydiv = document.createElement('div');
    mydiv.setAttribute('class', 'exp-loggedout');
    outer.wrapInner(mydiv);
    
    // remove link
    var url = links.attr('href');
    links.removeAttr("href");
    links.removeAttr("onClick");
    links.removeAttr("title");
    links.css('cursor', 'default');
    links.parent().css('float', 'none');
    
    // determine "all versions" page url
    if (url.indexOf('downloads') > 0)
        url = url.substring(0, url.indexOf('downloads'));
    else if (url.indexOf('addons') > 0)
        url = url.substring(0, url.indexOf('addons'));
    url = url+'addons/versions/'+addonID;


    if (needUpgrade && showVersionLink) {
        links.parent().after(sprintf(app_compat_older_version_or_ignore_check, url, "removeCompatibilityHint("+versionID+");return false;"));
    } else if (!needUpgrade && showVersionLink) {
        links.parent().after('<br /><a href="#" onclick="removeCompatibilityHint(\''+versionID+'\');return false;">' +app_compat_ignore_check+ '</a>');
        links.parent().after(app_compat_older_firefox_only);
    } else if (!needUpgrade) {
        links.parent().after(app_compat_older_firefox_only);
    } else {
        links.parent().after(sprintf(app_compat_try_old_version, url));
    }

    if (needUpgrade) {
        if (vc.compareVersions(fromVer, LATEST_FIREFOX_DEVEL_VERSION)>=0) {
            links.parent().after(sprintf("<strong>" + app_compat_unreleased_version + "</strong><br />", 'http://www.mozilla.com/' + LANG + '/firefox/all-beta.html#' + LANG, LATEST_FIREFOX_DEVEL_VERSION));
        }else if (vc.compareVersions(fromVer, LATEST_FIREFOX_VERSION)<0) {
            links.parent().after(sprintf("<strong>" + app_compat_update_firefox + "</strong><br />", 'http://www.mozilla.com/' + LANG + '/firefox/all.html#' + LANG, LATEST_FIREFOX_VERSION));
        }
    }
    
    return true;
}

/**
 * Remove "incompatible" message for given version ID, by restoring the
 * original button.
 */
function removeCompatibilityHint(versionID) {
    // find all hidden install buttons
    var orig = $('#orig-' + versionID);
    // remove compatibility hints
    orig.prev().remove();
    // show original buttons
    orig.attr('id', 'install-'+versionID);
    orig.show();
    
    return true;
}

/**
 * This function is used on the addon version page to create an element
 * at the top of the page with the most recent compatible version of an addon
 */
function createLatestVersionElement(get_latest_version_text) {
	var container = $("#latest-version-container");
	
	container.wrapInner("<p>" + get_latest_version_text + " (" + gLatestApplicationVersion + ")" + "</p>");
	container.append(gLatestAddonVersion);	
    var installButton = $("#install-"+ gLatestVersionID);
    var cloned = installButton.clone();
    cloned.attr('id', 'install-0'+ gLatestVersionID); // prepend 0 to this version id to make unique
	container.append(cloned);
	container.attr('id', 'latest-version');
	fixPlatformLinks("0"+ gLatestVersionID, ""); // show only one platform when dealing with most recent compatible app.
}

/**
 *  replaces options in a select drop-down (used for advanced search)
 *  @param select_id - the id of the select tag to replace the options of
 *  @param opt_array - array of options to use
 *  @param selected - which option will be marked as selected
 *
 */
function replaceOptions( select_id , opt_array, selected) {
  $(select_id + " > *").remove();
  
  for( opt in opt_array) {
	  sel_text = "";
      val = opt_array[opt];
      opt_obj = document.createElement("option");
	  if( val == selected) {opt_obj.selected = "selected";}
      opt_obj.value = val;
      opt_obj.appendChild(document.createTextNode(opt));	  
      $(select_id).append(opt_obj);  
  }
}

/**
 * replace noscript email by an actual link
 * @param obj id of email node
 * @param lp local part
 * @param hp host part
 */
function emailLink(obj, lp, hp) {
    var cont = document.getElementById(obj);
    var em = lp +'@'+ hp;
    var a = document.createElement('a');
    a.setAttribute('href', 'mailto:'+em);
    a.appendChild(document.createTextNode(em));
    cont.replaceChild(a, cont.lastChild);
}


/**
 * sprintf() implementation for Javascript
 * adapted from public domain code initially published at:
 * http://jan.moesen.nu/code/javascript/sprintf-and-printf-in-javascript/
 */
function sprintf()
{
    if (!arguments || arguments.length < 1 || !RegExp) {
        return null;
    }
    var str = arguments[0];
    var re = /([^%]*)%((\d+)\$)?('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
    var a = b = [], numSubstitutions = 0, numMatches = 0;
    
    while ((a = re.exec(str))) {
        var leftpart = a[1], pPos = a[3], pPad = a[4], pJustify = a[5];
        var pMinLength = a[6], pPrecision = a[7], pType = a[8];
        var rightPart = a[9];

        numMatches++;
        if (pType == '%') {
            subst = '%';
        } else {
            if (pPos == '') {
                numSubstitutions++;
                pPos = numSubstitutions;
            }
            if (parseInt(pPos) >= arguments.length) {
                alert('Error! Not enough function arguments (' + (arguments.length - 1)
                    + ', excluding the string)\n'
                    + 'for the number of substitution parameters in string ('
                    + numSubstitutions + ' so far).');
            }
            var param = arguments[parseInt(pPos)];
            var pad = '';
            if (pPad && pPad.substr(0,1) == "'")
                pad = leftpart.substr(1,1);
            else if (pPad)
                pad = pPad;
            var justifyRight = true;
            if (pJustify && pJustify === "-") justifyRight = false;
            var minLength = -1;
            if (pMinLength) minLength = parseInt(pMinLength);
            var precision = -1;
            if (pPrecision && pType == 'f')
                precision = parseInt(pPrecision.substring(1));
            var subst = param;
         
            switch (pType) {
            case 'b':
                subst = parseInt(param).toString(2);
                break;
            case 'c':
                subst = String.fromCharCode(parseInt(param));
                break;
            case 'd':
                subst = parseInt(param) ? parseInt(param) : 0;
                break;
            case 'u':
                subst = Math.abs(param);
                break;
            case 'f':
                subst = (precision > -1)
                    ? Math.round(parseFloat(param) * Math.pow(10, precision))
                    / Math.pow(10, precision)
                    : parseFloat(param);
                break;
            case 'o':
                subst = parseInt(param).toString(8);
                break;
            case 's':
                subst = param;
                break;
            case 'x':
                subst = ('' + parseInt(param).toString(16)).toLowerCase();
                break;
            case 'X':
                subst = ('' + parseInt(param).toString(16)).toUpperCase();
                break;
            }
            var padLeft = minLength - subst.toString().length;
            if (padLeft > 0) {
                var arrTmp = new Array(padLeft+1);
                var padding = arrTmp.join(pad?pad:" ");
            } else {
                var padding = "";
            }
        }
        str = leftpart + padding + subst + rightPart;
    }
    return str;
}


/*
 ### jQuery Star Rating Plugin v2.0 - 2008-03-12 ###
 By Diego A, http://www.fyneworks.com, diego@fyneworks.com
 - v2 by Keith Wood, http://keith-wood.name/, kbwood@virginbroadband.com.au
 
 Project: http://plugins.jquery.com/project/MultipleFriendlyStarRating
 Website: http://www.fyneworks.com/jquery/star-rating/
	
	This is a modified version of the star rating plugin from:
 http://www.phpletter.com/Demo/Jquery-Star-Rating-Plugin/
*/
// ORIGINAL COMMENTS:
/*************************************************
 This is hacked version of star rating created by <a href="http://php.scripts.psu.edu/rja171/widgets/rating.php">Ritesh Agrawal</a>
 It thansform a set of radio type input elements to star rating type and remain the radio element name and value,
 so could be integrated with your form. It acts as a normal radio button.
 modified by : Logan Cai (cailongqun[at]yahoo.com.cn)
 website:www.phpletter.com
************************************************/


/*# AVOID COLLISIONS #*/
;if(jQuery) (function($){
/*# AVOID COLLISIONS #*/

$.fn.rating = function(settings) {
 settings = $.extend({
		cancel: '', // advisory title for the 'cancel' link
		cancelValue: 0,         // value to submit when user click the 'cancel' link
		required: false,         // disables the 'cancel' button so user can only select one of the specified values
		readOnly: false          // disable rating plugin interaction/ values cannot be changed
	}, settings || {});
 
  var container = this;

 // multiple star ratings on one page
 var groups = {};
 
	// plugin events
 var event = {
  fill: function(n, el, style){ // fill to the current mouse position.
	  this.drain(n);
	  $(el).prevAll('.star').andSelf().addClass( style || 'star_hover' );
  },
  drain: function(n) { // drain all the stars.
  	$(groups[n].valueElem).siblings('.star').
		 removeClass('star_on').removeClass('star_hover');
  },
  reset: function(n){ // Reset the stars to the default index.
  	if (!$(groups[n].currentElem).is('.cancel')) {
 		 $(groups[n].currentElem).prevAll('.star').andSelf().addClass('star_on');
	  }
  },
  click: function(n, el) { // Selected a star or cancelled
			groups[n].currentElem = el;
			var curValue = $(el).children('a').text();
			// Set value
			$(groups[n].valueElem).val(curValue);
			// Update display
			event.drain(n);
			event.reset(n);
			// callback function, as requested here: http://plugins.jquery.com/node/1655
			if(settings.callback) settings.callback.apply(groups[n].valueElem, [curValue, el]);
  }      
 };
 
	// loop through each matched element
	
	var radioButtons = $(this).find('input[@type=radio]');

	$(this).empty();
	$(this).removeClass('degrade');

 	radioButtons.each(function(i){
		// grouping:
		var n = this.name;
	    
		if(!groups[n]) groups[n] = {count: 0};
		i = groups[n].count;
		groups[n].count++;
		
		// Things to do with the first element...
		if(i == 0){
			// Accept readOnly setting from 'disabled' property
			settings.readOnly = $(this).attr('disabled') || settings.readOnly;
			// Create value element (disabled if readOnly)
		 groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');
			// Insert value element into form
   $(container).append(groups[n].valueElem);
 		
			if(settings.readOnly || settings.required){
			// DO NOT display 'cancel' button
			}
			else{
			 
    
			}
		}; // if (i == 0) (first element)
		
		// insert rating option right after preview element
		eStar = $('<div class="star"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
		$(container).append(eStar);

		if(settings.readOnly){
			// Mark star as readOnly so user can customize display
			$(eStar).addClass('star_readonly');
		}
		else{
			// Attach mouse events
			$(eStar)
			.mouseover(function(){ event.drain(n); event.fill(n, this); })
			.mouseout(function(){ event.drain(n); event.reset(n); })
			.click(function(){ event.click(n, this); });
		};
		
		//if(console) console.log(['###', n, this.checked, groups[n].initial]);
		if(this.checked) groups[n].currentElem = eStar;
		
		
		
		// reset display if last element
		if(i + 1 == this.length) event.reset(n);
	
	}); // each element
  	

	
	// initialize groups...
	for(n in groups)//{ not needed, save a byte!
		if(groups[n].currentElem){
			event.fill(n, groups[n].currentElem, 'star_on');
			$(groups[n].valueElem).val($(groups[n].currentElem).children('a').text());
		}
	//}; not needed, save a byte!
	
	return this; // don't break the chain...
};



/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/


function VersionCompare() {
    /**
     * Mozilla-style version numbers comparison in Javascript
     * (JS-translated version of PHP versioncompare component)
     * @return -1: a<b, 0: a==b, 1: a>b
     */
    this.compareVersions = function(a,b) {
        var al = a.split('.');
        var bl = b.split('.');
    
        for (var i=0; i<al.length || i<bl.length; i++) {
            var ap = (i<al.length ? al[i] : null);
            var bp = (i<bl.length ? bl[i] : null);
    
            var r = this.compareVersionParts(ap,bp);
            if (r != 0)
                return r;
        }
    
        return 0;
    }
    
    /**
     * helper function: compare a single version part
     */
    this.compareVersionParts = function(ap,bp) {
        var avp = this.parseVersionPart(ap);
        var bvp = this.parseVersionPart(bp);
    
        var r = this.cmp(avp['numA'],bvp['numA']);
        if (r) return r;
    
        r = this.strcmp(avp['strB'],bvp['strB']);
        if (r) return r;
    
        r = this.cmp(avp['numC'],bvp['numC']);
        if (r) return r;
    
        return this.strcmp(avp['extraD'],bvp['extraD']);
    }

    /**
     * helper function: parse a version part
     */
    this.parseVersionPart = function(p) {
        if (p == '*') {
            return {
                'numA'   : Number.MAX_VALUE,
                'strB'   : '',
                'numC'   : 0,
                'extraD' : ''
                };
        }

        var pattern = /^([-\d]*)([^-\d]*)([-\d]*)(.*)$/;
        var m = pattern.exec(p);

        var r = {
            'numA'  : parseInt(m[1]),
            'strB'   : m[2],
            'numC'   : parseInt(m[3]),
            'extraD' : m[4]
            };

        if (r['strB'] == '+') {
            r['numA']++;
            r['strB'] = 'pre';
        }

        return r;
    }

    /**
     * helper function: compare numeric version parts
     */
    this.cmp = function(an,bn) {
        if (isNaN(an)) an = 0;
        if (isNaN(bn)) bn = 0;
        
        if (an < bn)
            return -1;

        if (an > bn)
            return 1;

        return 0;
    }

    /**
     * helper function: compare string version parts
     */
    this.strcmp = function(as,bs) {
        if (as == bs)
            return 0;
        
        // any string comes *before* the empty string
        if (as == '')
            return 1;
        
        if (bs == '')
            return -1;
        
        // normal string comparison for non-empty strings (like strcmp)
        if (as < bs)
            return -1;
        else if(as > bs)
            return 1;
        else
            return 0;
    }
}

/**
 * jQuery slider plugin - 2008-07-07
 * lorchard@mozilla.com
 */

/*# AVOID COLLISIONS #*/
;if(jQuery) (function($){
/*# AVOID COLLISIONS #*/

$.fn.slider = function(settings) {
    var $slider = arguments.callee.support;
    new $slider(this[0].id, settings);
    return this;
}

$.fn.slider.support = function(slider_id, options) {
    this.init(slider_id, options);
};

$.fn.slider.support.prototype = function() {

    return {

        /**
         * Wire up the scroll events.
         */
        init: function(slider_id, options) {
            this.options = $.extend({
                duration: 250,
                prev_img_src: '/img/slider-prev.gif',
                prev_disabled_img_src: '/img/slider-prev-disabled.gif',
                next_img_src: '/img/slider-next.gif',
                next_disabled_img_src: '/img/slider-next-disabled.gif'
            }, options || {});

            this.slider_id  = slider_id;
            this.slider_sel = '#' + slider_id;

            this._resize_timer = null;

            var that = this;
            $(window).unload(function() { return that.onUnload(); });
            $(window).resize(function() { return that.onResize(); });
            $(document).ready(function() { return that.onReady(); });
        },

        /**
         * Perform scroller initialization on page readiness
         */
        onReady: function() {
            this.items = $(this.slider_sel + ' .item');
            this.item_idx = 0;
            
            var that = this;
            $(this.slider_sel + ' .controls .prev').click(function(e) { 
                return that.onClickPrev(e) 
            });
            $(this.slider_sel + ' .controls .next').click(function(e) { 
                return that.onClickNext(e) 
            });

            this.onResize();
        },

        /**
         * Unload some resources on page unload, being superstitous about a
         * memory leak.
         */
        onUnload: function() {
            delete this.items;
        },

        /**
         * React to browser resizing, with a delayed timer to prevent lots of
         * overlapping calls.
         */
        onResize: function() {
            var that = this;
            if (this._resize_timer)
                clearTimeout(this._resize_timer);
            this._resize_timer = window.setTimeout(function() {
                that._doResize();
            }, 50);
        },

        /**
         * Perform the actual work of readjusting after resize.
         */
        _doResize: function() {
            var slider = $(this.slider_sel);
            var viewport = slider.select('.viewport')[0];
            
            $(this.slider_sel + ' .addon').width(viewport.offsetWidth - 260);
            this.revealSelectedItem(15);
        },

        /**
         * React to "prev" button click.
         */
        onClickPrev: function(e) {
            if ( (this.item_idx - 1) < 0 ) return false;
            this.item_idx--;
            return this.changeSelectedItem();
        },

        /**
         * React to "next" button click.
         */
        onClickNext: function(e) {
            if ( (this.item_idx + 1) >= this.items.length ) return false;
            this.item_idx++;
            return this.changeSelectedItem();
        },

        /**
         * Update the selected item, item number, and button display states.
         */
        changeSelectedItem: function() {
            this.updateItemNumber();
            this.updateButtonStates();
            this.revealSelectedItem();
            return false;
        },

        /**
         * Update the number displayed indicating current item.
         */
        updateItemNumber: function() {
            $(this.slider_sel + ' .controls .index').text( this.item_idx + 1 );
        },

        /**
         * Update the enabled / disabled images for the next / prev buttons.
         */
        updateButtonStates: function() {
            var img_p = $(this.slider_sel + ' .controls .prev img')[0];
            if ( this.item_idx == 0 ) {
                img_p.src = this.options.prev_disabled_img_src;
            } else {
                img_p.src = this.options.prev_img_src;
            }

            var img_n = $(this.slider_sel + ' .controls .next img')[0];
            if ( this.item_idx == this.items.length - 1 ) {
                img_n.src = this.options.next_disabled_img_src;
            } else {
                img_n.src = this.options.next_img_src;
            }
        },

        /**
         * Reveal the selected item with an animation.
         */
        revealSelectedItem: function(delay) {
            if (!delay) delay = this.options.slide_duration;
            $(this.slider_sel + ' .viewport').animate({ 
                scrollLeft: this.items[ this.item_idx ].offsetLeft 
            }, delay)
        },

        EOF: null // I hate trailing comma errors.
    };
}();

/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/

/*# AVOID COLLISIONS #*/
;if(jQuery) (function($){
/*# AVOID COLLISIONS #*/

$.fn.collection = function(options) {
    options = $.extend({
               'shoppingCart':false
        }, options || {});
    
    var installUrl = options.installUrl;
    
    $('input.want').change(function() {
        $('#done-'+$(this).attr('value')).slideToggle('fast');
        $('.installsubmit input').attr('disabled', ($('input.want:checked').length == 0))
    });
	$('input.want:checked').each(function() {
		$('#done-'+$(this).attr('value')).show();
	});
    $('.installsubmit input').attr('disabled', ($('input.want:checked').length == 0))
    
        var confirmInstall = function() {
            $.post(installUrl, $('input.want:checked').serialize(),
                function(data,status){
                    $('#installdialog').html(data)
                                       .jqmAddClose('#installdialog .installsubmit input.cancel')
                                       .show();
                });
        };
        $('#installdialog').jqm({onShow: confirmInstall,
                                trigger: '#collectionform .installsubmit input,a.installlink',
                                overlay: 80});
        $(document).keypress(function(e){if (e.keyCode == 27) $('#installdialog').jqmHide();}) // esc
}
/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/