//-- Daily Horse Quotes - javascript code
//-- Copyright 2012 Five Star Ranch, http://www.fivestarranch.com , All Rights Reserved.


var framework = '<link href="http://www.fivestarranch.com/horsiness.css" rel="stylesheet" type="text/css">' + "\n" 
 + '  <div id="outer" style="width: 100%;" align="center">' + "\n"
 + '  <div id="title"><a class="xjf" href="http://www.fivestarranch.com/horse-quotes.html">Daily Horse Quotes!</a></div>' + "\n"
 + '  <div id="data" style="position: relative; width: 180px; height: 129px;' + "\n"
 + 'background-image:url(http://lh3.googleusercontent.com/-TcKtM9a43e4/SvONPKdHJ_I/AAAAAAAAABU/04jXsr5g8-M/s180/horse-background.jpg);background-repeat:no-repeat;"></div>' + "\n";

document.write(framework);


var loading = 1;
var indate = new Date();
var jday = 2 + indate.getDay();
var jmonth = 1 + indate.getMonth();
var year = indate.getFullYear();

  if (jmonth == 2) { jday = jday + 31; }
  if (jmonth == 3) { jday = jday + 60; }
  if (jmonth == 4) { jday = jday + 91; }
  if (jmonth == 5) { jday = jday + 121; }
  if (jmonth == 6) { jday = jday + 152; }
  if (jmonth == 7) { jday = jday + 182; }
  if (jmonth == 8) { jday = jday + 213; }
  if (jmonth == 9) { jday = jday + 244; }
  if (jmonth == 10) { jday = jday + 273; }
  if (jmonth == 11) { jday = jday + 305; }
  if (jmonth == 12) { jday = jday + 335; }

function cellEntries(json) {

  removeOldResults();
  
  var entry = json.feed.entry[0];

  var quote = json.feed.entry[1];

  var finalquote = rtrim(quote.content.$t);

  var showme =  '<div id="capo"></div><div id="scriv" align="center"><div id="quoted">&quot;' + finalquote + '&rdquo;</div><div id="author">' + entry.content.$t +  '</div></div>';
  showme = showme + ' <div id="controls"><div id="prev">&nbsp;&nbsp;<a href="" class="pagination" onClick="jday=jday-1;init();return false;" alt="Previous">&larr;</a>&nbsp;</div><div id="page"><a class="pagination" href="" onClick="jday=jday+1;init();return false;" alt="Next">&rarr;</a>&nbsp;&nbsp;</div></div><div id="copyyear">' + year + '&nbsp;&nbsp;</div>';

  document.getElementById("data"). innerHTML = showme;

  CheckScrollBar('scriv');

}

function rtrim(stringToTrim) {
  return stringToTrim.replace(/\s+$/,"");
}

function init() {

if (loading == 1) {
  var div = document.getElementById('data');
  var img = document.createElement('img');
  img.src = 'http://www.google.com/ig/images/spinner.gif';
  div.appendChild(img);
  loading = loading -1;
}

  if (jday >= 368) { jday = 2; }
  if (jday <= 1) { jday = 367; }

  var script = document.createElement('script');
  var range = "A" + jday + ":" + "B" + jday;

  script.setAttribute('src', 'http://spreadsheets.google.com/feeds/cells/tzjsw1C-wNZhK3mCLhPrnZA/od6/public/basic?range='
                           + range
                           + '&alt=json-in-script&callback=cellEntries');

  var gurgle = 'http://spreadsheets.google.com/feeds/cells/tzjsw1C-wNZhK3mCLhPrnZA/od6/public/basic?range=' + range + '&alt=json-in-script&callback=cellEntries';

  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  document.documentElement.firstChild.appendChild(script);

}

function CheckScrollBar(ObjectId)
{
    quotesize = document.getElementById('quoted');
    authorsize = document.getElementById('author');

    if (IsScrollBarExist(ObjectId)) {   quotesize.style.width="142px";
                                                   authorsize.style.width="142px";
                                                   quotesize.style.padding="0px 0px 5px 14px"; }
    else {  quotesize.style.width="150px";
              authorsize.style.width="150px";  }
}
function IsScrollBarExist(ObjectId)
{
    Object=document.getElementById(ObjectId);

            Object.scrollTop=1;
            if (Object.scrollTop>0) {Object.scrollTop=0; return true;}
            else {return false;}
}

function removeOldResults() {
  var div = document.getElementById('data');
  if (div.firstChild) {
    div.removeChild(div.firstChild);
  }
}
