
// TagCount object  (file: TagCount.js.php)
// Version 1.1, modified by Jon to add Array contains method to fix IE balking at .indexOf.
Array.prototype.contains = function (element) {
	for (var elementCounter = 0; elementCounter < this.length; elementCounter++) {
		if (this[elementCounter] == element) {
			return true;
		}
	}
	return false;
}
function TagCount() {

  // private variables
  var keepZeros  = false;       // bool

  // public variables
  this.tags       = new Array;
  this.lexias     = new Object;  // format: this.lexias['tagName'] = ##
  this.documents  = new Object;  // format: this.documents['tagName'] = ##
  this.idFromTag  = new Object;  // format: this.idFromTag['tagName'] = ##

  // public functions

  this.addTag = function (tagName, numLexias, numDocuments, tagId) {
  	if ( this.tags.contains(tagName) ) return;  // no duplicates
  	this.tags.push(tagName);
    if (keepZeros) {
      this.lexias[tagName] = (null == numLexias) ? 0 : numLexias;
      this.documents[tagName] = (null == numDocuments) ? 0 : numDocuments;
    } else {
      if (null != typeof(numLexias) && numLexias > 0) this.lexias[tagName] = numLexias;
      if (null != typeof(numLexias) && numLexias > 0) this.documents[tagName] = numDocuments;
    }
    if (typeof(tagId) == 'number') {
    	tagId = parseInt(tagId);
    	this.idFromTag[tagName] = tagId;
    }
 	if (keepZeros || this.lexias[tagName] || this.documents[tagName]) return true;
    return false;
  }

  this.zeros = function (bool) {
    keepZeros = (true == bool) ? true : false;
    var x;
    if (!keepZeros) {
      for (x in this.lexias) {
        if (this.lexias[x] == 0) delete this.lexias[x];
      }
      for (x in this.documents) {
        if (this.documents[x] == 0) delete this.documents[x];
      }
    }
  }

  this.makeAlphabetical = function() {
  	 this.tags.sort(function(x,y){
      var a = String(x).toUpperCase();
      var b = String(y).toUpperCase();
      if (a > b)
         return 1
      if (a < b)
         return -1
      return 0;
     });  // case insensitive
  }

  this.getNumLexias = function (tagName) {
    return (this.lexias[tagName]) ? this.lexias[tagName] : false;
  }

  this.getNumDocuments = function (tagName) {
    return (this.documents[tagName]) ? this.documents[tagName] : false;
  }

  this.getTagFromId = function (tagId) {
  	 tagId = parseInt(tagId);
  	 for (var a in this.idFromTag) {
  	 	if (parseInt(this.idFromTag[a]) == tagId) {
  	 		return a;
  	 	}
  	 }
  	 return false;
  }

  this.getIdFromTag = function (tagName) {
  	 return (typeof(this.idFromTag[tagName]) != 'undefined') ? this.idFromTag[tagName] : false;
  }

  this.addAmountToLexias = function (tagName, myNum) {
    if (this.lexias[tagName] || this.addTag(tagName)) {
      if (null == myNum) myNum = 1;
      if (this.lexias[tagName]) this.lexias[tagName] = this.lexias[tagName] + myNum;
    }
  }

  this.addAmountToDocuments = function (tagName, myNum) {
    if (this.documents[tagName] || this.addTag(tagName)) {
      if (null == myNum) myNum = 1;
      if (this.documents[tagName]) this.documents[tagName] = this.documents[tagName] + myNum;
    }
  }

} // end object

// add content to object
var numTaggedWith = new TagCount();

numTaggedWith.addTag('1973', 1, 1, 1362);
numTaggedWith.addTag('activism', 3, 1, 1262);
numTaggedWith.addTag('aesthetics', 3, 1, 1358);
numTaggedWith.addTag('annotated', 1, 1, 1727);
numTaggedWith.addTag('anthology', 2, 1, 1305);
numTaggedWith.addTag('appropriate', 1, 1, 1308);
numTaggedWith.addTag('closet', 2, 1, 1726);
numTaggedWith.addTag('complexity', 1, 1, 1770);
numTaggedWith.addTag('criticism', 2, 1, 1738);
numTaggedWith.addTag('criticisms', 1, 1, 582);
numTaggedWith.addTag('death', 1, 1, 1778);
numTaggedWith.addTag('defines', 1, 1, 1724);
numTaggedWith.addTag('discourse', 1, 1, 471);
numTaggedWith.addTag('dissident', 1, 1, 1779);
numTaggedWith.addTag('drama', 2, 1, 524);
numTaggedWith.addTag('DuPlessis', 3, 1, 1736);
numTaggedWith.addTag('editing', 1, 1, 1307);
numTaggedWith.addTag('Elizabeth Bishop', 1, 1, 1728);
numTaggedWith.addTag('ellipses', 1, 1, 1775);
numTaggedWith.addTag('erotic', 1, 1, 1503);
numTaggedWith.addTag('essay', 1, 1, 354);
numTaggedWith.addTag('exile', 2, 1, 1740);
numTaggedWith.addTag('experimental', 3, 1, 1537);
numTaggedWith.addTag('family', 3, 1, 593);
numTaggedWith.addTag('feminist', 2, 2, 1306);
numTaggedWith.addTag('foregrounds', 1, 1, 1311);
numTaggedWith.addTag('fractal', 1, 1, 1771);
numTaggedWith.addTag('gender', 1, 1, 1233);
numTaggedWith.addTag('grandmother', 1, 1, 1741);
numTaggedWith.addTag('immigration', 1, 1, 1772);
numTaggedWith.addTag('law', 1, 1, 206);
numTaggedWith.addTag('lesbian', 5, 1, 1725);
numTaggedWith.addTag('literature', 2, 1, 525);
numTaggedWith.addTag('loss', 1, 1, 1777);
numTaggedWith.addTag('love', 2, 1, 182);
numTaggedWith.addTag('marginalized', 1, 1, 1309);
numTaggedWith.addTag('memories', 1, 1, 1340);
numTaggedWith.addTag('patriarch', 1, 1, 1774);
numTaggedWith.addTag('performance', 3, 1, 456);
numTaggedWith.addTag('perspectives', 1, 1, 1310);
numTaggedWith.addTag('play', 2, 1, 1739);
numTaggedWith.addTag('playability', 1, 1, 491);
numTaggedWith.addTag('poetics', 4, 2, 1361);
numTaggedWith.addTag('poetry', 3, 1, 1360);
numTaggedWith.addTag('politics', 2, 1, 1737);
numTaggedWith.addTag('sedition', 1, 1, 1780);
numTaggedWith.addTag('sexuality', 3, 1, 224);
numTaggedWith.addTag('sisters', 1, 1, 1776);
numTaggedWith.addTag('static', 1, 1, 1773);
numTaggedWith.addTag('vol', 1, 1, 416);
numTaggedWith.addTag('writings', 1, 1, 1488);
