/*
* Copyright (C) 2010 Tocloud.com 
*/

/*
<style type='text/css'>
a {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
.w2 { color: #ff0000; }
.w3 { color: #ff0000; }
.w4 { color: #ff0000; }
.w5 { color: #ff0000; }
.w6 { color: #ff0000; }
.w7 { color: #ff0000; }
.w8 { color: #ff0000; }
.w9 { color: #ff0000; }
.w10 { color: #ff0000; }
.p2 { color: #00ff00; }
.p3 { color: #00ff00; }
.p4 { color: #00ff00; }
.p5 { color: #00ff00; }
.p6 { color: #00ff00; }
.p7 { color: #00ff00; }
.p8 { color: #00ff00; }
.p9 { color: #00ff00; }
.p10 { color: #00ff00; }
.fq { color: #cccccc; }
</style>
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script language="JavaScript">
  google.load("prototype","1.6.0.3");
<script>
<script language="JavaScript">
</script>
<script type='text/javascript' src='cloudview.js'></script>
<script language="JavaScript">
  cloudview.setMinWordFrequency(2); // minimum time a word should occur
  cloudview.setWordCount(25); // maximum number of words in the cloud. 0 is all 
  cloudview.setShowFrequencies(1); // 0 to not show frequencies next to the word
  cloudview.setPhrasesOnly(0); // 1 to show only phrases. 0 to show both phrases and words
  cloudview.setCloudScriptURL('cloudview.pl'); // can be absolute path where installed, like /tocloud/cloudview.pl
  cloudview.setInterpolation('l'); // l = linear, g = logarithmic
  cloudview.setTitle('');
  cloudview.setHeader('');
  cloudview.setFooter('<div style="font-style:italic;color:#0f0fcf">Generated By ToCloud.com</div>');
  cloudview.init();
</script>
*/

function CloudView() {
  var self = this;
  this.id = '';
  this.mwf = 2;
  this.wc = 25;
  this.po = 0;
  this.sf = 1;
  this.elementid = 'tagcloud';
  this.cloudScriptURL = 'cloudview.pl';
  this.interpolation = 'l';
  this.sort = 'a';
  this.title;
  this.header;
  this.footer = '<div style="font-style:italic;text-align:right;">Generated By <a href="http://www.tocloud.com/cloudview/">Cloud View</a></div>';
  this.targetURL;

  this.setId = function(id) {
    this.id = id;
  }

  this.setMinWordFrequency = function(mwf) {
    this.mwf = mwf;
  }

  this.setWordCount = function(wc) {
    this.wc = wc;
  }

  this.setPhrasesOnly = function(po) {
    this.po = po;
  }

  this.setShowFrequencies = function(sf) {
    this.sf = sf;
  }

  this.setElementId = function(elementid) {
    this.elementid = elementid;
  }

  this.setCloudScriptURL = function(scriptURL) {
    this.cloudScriptURL = scriptURL;
  }

  this.setTargetURL = function(targetURL) {
    this.targetURL = targetURL;
  }

  this.setDisplaySort = function(displaySort) {
    this.sort = sort;
  }

  this.setInterpolation = function(interpolation /* l = linear, g = logarithmic */) {
    this.interpolation = interpolation;
  }

  this.setTitle = function(title) {
    this.title = title;
  }
  
  this.setHeader = function(header) {
    this.header = header;
  }

  this.setFooter = function(footer) {
    this.footer = footer;
  }

  this.onclick = function(event,word,cid) {
    if(this.targetURL) {
      document.location.href = this.targetURL + escape(word);
    }
    return false;
  }

/*
  this.onmouseover = function(event,word,cid) { }
  this.onmouseout = function(event,word,cid) { }
*/

  function onload() {
    var action = self.cloudScriptURL;
    var html = document.body.innerHTML;
    html = html.replace(/\u00a0/g," ");
    new Ajax.Request(action,
     {
       contentType: 'application/x-www-form-urlencoded'
      ,method: 'post'
      ,parameters: {
         'txt' : html
        ,'id' : self.id
        ,'interpolation' : self.interpolation
        ,'mwf'  : self.mwf
        ,'wc'   : self.wc
        ,'po'   : self.po
        ,'sf'   : self.sf
        ,'sort' : self.sort
        ,'onmouseover' : self.onmouseover ? 'cloudview.onmouseover' : ''
        ,'onmouseout' : self.onmouseout ? 'cloudview.onmouseout' : ''
        ,'title' : self.title ? self.title : ''
        ,'header': self.header ? self.header: ''
        ,'footer': self.footer ? self.footer: ''
       }
      ,onSuccess: function(transport) {
         $(self.elementid).innerHTML = transport.responseText; 
       }
     }
    );
  }
  
  this.init = function() {
    Event.observe(window,'load',onload);
  }
}

cloudview = new CloudView();

