SCC.Quotation = {
  jsonURL:"http://stockcharts.com/j-ts/ts?cmd=get_quote&callback=?",
  text:"",
  root:null,
  div:null,
  divContent:null,
  divHTML:"<div id=\"sccquotation\"><div id=\"sccquotationcontent\">{{QUOTE}}</div></div>",
  waitInit : function(){/*call first*/
    try{
      if (typeof(pageInitializing)!="undefined" && pageInitializing==true){
        setTimeout(function(){SCC.Quotation.waitInit();},100);
      }else {
      $.getJSON(this.jsonURL, function(data){SCC.Quotation.insert(data);});
      
//debug:
//SCC.Quotation.insert({"id":6,"quote":"\"I've been told a few times in my career that I was right, but for the wrong reasons - usually by someone who was wrong for the right reasons.\" --John Murphy's \"The Visual Investor\""});
      
      }
    }catch(e){}
  },
  init :function(){ 
    this.root=$("#alpha-inner");
    var quoteHTML=this.divHTML.replace("{{QUOTE}}",this.text);
    this.root.append(quoteHTML);
    this.divContent=$("#sccquotationcontent");
  },
  set: function(data){
    if (!data) return;
    if (data.quote) this.text=data.quote;
  },
  insert :function(data){
    if (typeof(data)!="undefined" && data.quote){
      this.set(data);
    }
    if (!this.text) return;
    if (!this.divContent || this.divContent.get().length!=1) this.init();
    if (!this.divContent || this.divContent.get().length!=1) return; //error!
    this.divContent.html(this.text);
  }
}
if (window.addEventListener) window.addEventListener("load", function(){SCC.Quotation.waitInit();}, false);
else if (document.addEventListener) document.addEventListener("load", function(){SCC.Quotation.waitInit();}, false);
else if (window.attachEvent) window.attachEvent("onload", function(){SCC.Quotation.waitInit();});
