PTWTR = window.PTWTR || {};

function html_entity_decode(str) {
  var ta=document.createElement("textarea"); 
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");  
  return ta.value;
}

function checkCharacters(strObj){
	var str = strObj.value;
	if(str.length > 140){
		strObj.value = str.substr(0,140);
		str = strObj.value;
	}
}

/**
  * add core functionality to JS
  * Sugar Arrays http://www.dustindiaz.com/basement/sugar-arrays.html
  */
if (!Array.forEach) {

  // iterates over an array
  Array.prototype.forEach = function(fn, thisObj) {
    var scope = thisObj || window;
    for ( var i=0, j=this.length; i < j; ++i ) {
      fn.call(scope, this[i], i, this);
    }
  };

  Array.prototype.filter = function(fn, thisObj) {
    var scope = thisObj || window;
    var a = [];
    for ( var i=0, j=this.length; i < j; ++i ) {
      if ( !fn.call(scope, this[i], i, this) ) {
        continue;
      }
      a.push(this[i]);
    }
    return a;
  };

  // sorta like inArray if used clever-like
  Array.prototype.indexOf = function(el, start) {
    var start = start || 0;

    for (var i=0; i < this.length; ++i) {
      if ( this[i] === el ) {
        return i;
      }
    }

    return -1;
  };
}

(function() {
PTWTR.Widget = function(opts) {
	this.init(opts);
};

(function() {
	var browser = function() {
      var ua = navigator.userAgent;
      return {
        ie: ua.match(/MSIE\s([^;]*)/)
      };
    }();

    var byId = function(id) {
      if (typeof id == 'string') {
        return document.getElementById(id);
      }
      return id;
    };

    var trim = function(str) {
      return str.replace(/^\s+|\s+$/g, '')
    };
	
	var removeElement = function(el) {
      try {
        el.parentNode.removeChild(el);
      }
      catch (ex) { }
    };
	
	var is = {
      bool: function(b) {
        return typeof b === 'boolean';
      },

      def: function(o) {
        return !(typeof o === 'undefined');
      },
	  
	  number: function(n) {
        return typeof n === 'number' && isFinite(n);
      },

      string: function(s) {
        return typeof s === 'string';
      },

      fn: function(f) {
        return typeof f === 'function';
      }
    };
	
	/**
      * relative time calculator
      * @param {string} twitter date string returned from Twitter API
      * @return {string} relative time like "2 minutes ago"
      */
	var ify = {
      link: function(tweet) {
        return tweet.replace(/\b(((https*\:\/\/)|www\.).+?)(([!?,.\)]+)?(\s|$))/g, function(link, m1, m2, m3, m4) {
          var http = m2.match(/w/) ? 'http://' : '';
          return '<a class="twtr-hyperlink" target="_blank" href="' + http + m1 + '">' + ((m1.length > 25) ? m1.substr(0, 24) + '...' : m1) + '</a>' + m4;
        });
      },

      at: function(tweet) {
        return tweet.replace(/\B\@([a-zA-Z0-9_]{1,20})/g, function(m, username) {
          return '@<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + username + '">' + username + '</a>';
        });
      },

      list: function(tweet) {
        return tweet.replace(/\B\@([a-zA-Z0-9_]{1,20}\/\w+)/g, function(m, userlist) {
          return '@<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + userlist + '">' + userlist + '</a>';
        });
      },

      hash: function(tweet) {
        return tweet.replace(/\B\#(\w+)/gi, function(m, hash) {
          return '<a target="_blank" class="twtr-hashtag" href="http://twitter.com/search?q=%23' + hash + '">#' + hash + '</a>';
        });
      },

      clean: function(tweet) {
        //return this.hash(this.at(this.list(this.link(tweet))));
		//return htmlspecialchars_decode(tweet,1);
		return html_entity_decode(tweet);
      }
    };
	
	function htmlspecialchars_decode(string, quote_style) {
		// Convert special HTML entities back to characters  
		// 
		// version: 1004.2314
		// discuss at: http://phpjs.org/functions/htmlspecialchars_decode    // +   original by: Mirek Slugen
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   bugfixed by: Mateusz "loonquawl" Zalega
		// +      input by: ReverseSyntax
		// +      input by: Slawomir Kaniecki    // +      input by: Scott Cariss
		// +      input by: Francois
		// +   bugfixed by: Onno Marsman
		// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // +      input by: Ratheous
		// +      input by: Mailfaker (http://www.weedem.fr/)
		// +      reimplemented by: Brett Zamir (http://brett-zamir.me)
		// +    bugfixed by: Brett Zamir (http://brett-zamir.me)
		// *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');    // *     returns 1: '<p>this -> &quot;</p>'
		// *     example 2: htmlspecialchars_decode("&amp;quot;");
		// *     returns 2: '&quot;'
		var optTemp = 0, i = 0, noquotes= false;
		if (typeof quote_style === 'undefined') {        quote_style = 2;
		}
		string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
		var OPTS = {
			'ENT_NOQUOTES': 0,        'ENT_HTML_QUOTE_SINGLE' : 1,
			'ENT_HTML_QUOTE_DOUBLE' : 2,
			'ENT_COMPAT': 2,
			'ENT_QUOTES': 3,
			'ENT_IGNORE' : 4    };
		if (quote_style === 0) {
			noquotes = true;
		}
		if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags        quote_style = [].concat(quote_style);
			for (i=0; i < quote_style.length; i++) {
				// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
				if (OPTS[quote_style[i]] === 0) {
					noquotes = true;            }
				else if (OPTS[quote_style[i]]) {
					optTemp = optTemp | OPTS[quote_style[i]];
				}
			}        quote_style = optTemp;
		}
		if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
			string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
			// string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
		}
		if (!noquotes) {
			string = string.replace(/&quot;/g, '"');
		}
		// Put this in last place to avoid escape being double-decoded    string = string.replace(/&amp;/g, '&');
	 
		return string;
	}
	
	function Tweet(tweet) {
	  var html = '<div class="twtr-tweet-wrap"> \
		<div class="twtr-avatar"> \
		  <div class="twtr-img"><a target="_blank" href="http://www.pokertwitter.com/' + tweet.user +'/"><img alt="' + tweet.user + ' profile" src="' + tweet.avatar + '" onerror="this.src=\'http://www.pokertwitter.com/images/user.jpg\'"></a></div> \
		</div> \
		<div class="twtr-tweet-text"> \
		  <p> \
			<a target="_blank" href="http://www.pokertwitter.com/' + tweet.user + '/" class="twtr-user">' + tweet.user + '</a> ' + tweet.tweet + ' \
			<i>\
			' + tweet.created_at + ' \
			</i> \
		  </p> \
		</div> \
	  </div>';

	  var div = document.createElement('div');

	  //div.id = 'tweet-id-' + ++Tweet._tweetCount;
	  div.className = 'twtr-tweet';
	  div.innerHTML = html;
	  this.element = div;
	};
	
	/*(function() {

      var isLoaded = false;
      ptwttr.css = function(rules) {
        var styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        if (browser.ie) {
          styleElement.styleSheet.cssText = rules;
        }
        else {
          var frag = document.createDocumentFragment();
          frag.appendChild(document.createTextNode(rules));
          styleElement.appendChild(frag);
        }
        function append() {
          document.getElementsByTagName('head')[0].appendChild(styleElement);
        }

        // oh IE we love you.
        // this is needed because you can't modify document body when page is loading
        if (!browser.ie || isLoaded) {
          append();
        }
        else {
          window.attachEvent('onload', function() {
            isLoaded = true;
            append();
          });
        }
      };
    })();*/

PTWTR.Widget.jsonP = function(url, callback) {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = url;
  document.getElementsByTagName('head')[0].appendChild(script);
  callback(script);
  return script;
};

PTWTR.Widget.prototype = function() {
	var base = 'http://search.twitter.com/search.';
	var profileBase = 'http://twitter.com/statuses/user_timeline.';
	var favBase = 'http://twitter.com/favorites/';
	var listBase = 'http://twitter.com/';
	var occasionalInterval = 20000; // 20 seconds
	var defaultAvatar = 'http://widgets.twimg.com/j/1/default.gif';
	
	return {
		init: function(opts) {
		  var that = this;
		  
		  PTWTR.Widget['receiveCallback'] = function(resp) {
            that._prePlay.call(that, resp);
          };
		  
		  PTWTR.Widget['receiveCallbackPost'] = function(resp) {
            if(resp.response == "false"){
				alert("Error sending request");
			}
			else if(resp.response == "post_max3_error"){
				alert("Can not post more than 3 tweets per minute");
			}
			else if(resp.response == "corporate_account_error"){
				alert("Can not post more than 7 tweets per minute");
			}
			else if(resp.response == "true"){
				that.start();
				alert ('Your Poker Tweet will be published shortly!');
				document.getElementById("pt_texttweet").value = "";
				//listTweets();
				//alert ('Tweet sent');
			}
          };
		  
		  this.opts = opts;
		  this._base = base;
		  this._isRunning = false;
		
		
		  this.setDimensions(opts.width, opts.height);
		  this.notweets = opts.notweets || 30;
		  this.subject = opts.subject || '';
		  this.title = opts.title || '';
		  //this.setFooterText(opts.footer);
		  this.footerText = 'Post Tweet';
		
		  //this.setSearch(opts.search);
		  //this._setUrl();
		  this.id = 'poktwtr-widget';
		  this.theme = opts.theme ? opts.theme : this._getDefaultTheme();
		  document.write('<div class="twtr-widget twtr-scroll" id="poktwtr-widget"></div>');
		  this.widgetEl = byId("poktwtr-widget");
		
		  /*if (!opts.id) {
			document.write('<div class="twtr-widget" id="' + this.id + '"></div>');
		  }
		  this.widgetEl = byId(this.id);
		  if (opts.id) {
			classes.add(this.widgetEl, 'twtr-widget');
		  }*/
		
		  //if (opts.version >= 2 && !TWTR.Widget.hasLoadedStyleSheet) {
			this.loadStyleSheet('http://www.pokertwitter.com/widget/css/widget.css');
		  //}
		
		  /*this.occasionalJob = new Occasionally(
			function(decay) {
			  that.decay = decay;
			  that._getResults.call(that);
			},
		
			function() {
			  return that._decayDecider.call(that);
			},
		
			occasionalInterval
		  );*/
		
		  this._ready = is.fn(opts.ready) ? opts.ready : function() { };
		
		  // preset features
		  this._avatars = opts.avatars;
		  return this;
		},
		
		setDimensions: function(w, h) {
		  this.wh = (w && h) ? [w, h] : [250, 300]; // default w/h if none provided
		  if (w == 'auto' || w == '100%') {
			this.wh[0] = '100%';
		  } else {
			this.wh[0] = ((this.wh[0] < 150) ? 150 : this.wh[0]) + 'px'; // min width is 150
		  }
		  this.wh[1] = ((this.wh[1] < 100) ? 100 : this.wh[1]) + 'px'; // min height is 100
		  return this;
		},
	
		/*setRpp: function(rpp) {
		  var rpp = parseInt(rpp);
		  this.rpp = (is.number(rpp) && (rpp > 0 && rpp <= 100)) ? rpp : 30;
		  return this;
		},*/
		
		setFooterText: function(s) {
		  return 'Post Tweet';
          /*this.footerText = (is.def(s) && is.string(s)) ? s : 'Join the conversation';
          if (this._rendered) {
            this.byClass('twtr-join-conv', 'a').innerHTML = this.footerText;
          }
          return this;*/
        },
		
		/**
          * @public
          * @param {string}
          * @return self
          * does double time. sets the search terms, and sets the appropriate
          * hyper reference on bottom anchor if widget has been rendered
          */
        setSearch: function(s) {
          /*this.searchString = s || '';
          this.s = this.searchString.replace(' ', '+');
          this.search = encodeURIComponent('-RT ' + this.s);
          this._setUrl();
          if (this._rendered) {
            var anchor = this.byClass('twtr-join-conv', 'a');
            anchor.href = 'http://twitter.com/' + this._getWidgetPath();
          }

          return this;*/
        },
		
		_setUrl: function() {
          /*var that = this;

          function showSince() {
            return (that.sinceId == 1) ? '' : '&since_id=' + that.sinceId + '&refresh=true';
          }

          if (this._isProfileWidget) {
            this.url = this._base + '&callback=' + this._cb +
                       '&count=' + this.rpp + showSince() + '&clientsource=' + this.source;
          }

          else if (this._isFavsWidget || this._isListWidget) {
            this.url = this._base + this.format + '?callback=' + this._cb + showSince() +
                       '&clientsource=' + this.source;
          }

          else {
            this.url = this._base + this.format + '?q=' + this.search +
                       '&callback=' + this._cb +
                       '&rpp=' + this.rpp + showSince() + '&clientsource=' + this.source;
          }

          return this;*/
        },
		
		_getDefaultTheme: function() {
          return {
			shell: {
			  background: '#998395',
			  color: '#420c42'
			},
	
			tweets: {
			  background: '#d9ccd9',
			  color: '#444444',
			  links: '#a339a3'
			}

          };
        },
		
		render: function() {
          var that = this;

          /*if (!TWTR.Widget.hasLoadedStyleSheet) {
            window.setTimeout(function() {
              that.render.call(that);
            }, 50);
            return this;
          }*/

          this.setTheme(this.theme, this._isCreator);

          this.widgetEl.innerHTML = this._getWidgetHtml();
          /*this.spinner = this.byClass('twtr-spinner', 'div');
          var timeline = this.byClass('twtr-timeline', 'div');
          if (this._isLive && !this._isFullScreen) {
            var over = function(e) {
              if (withinElement.call(this, e)) {
                that.pause.call(that);
              }
            };
            var out = function(e) {
              if (withinElement.call(this, e)) {
                that.resume.call(that);
              }
            };

            this.removeEvents = function() {
              events.remove(timeline, 'mouseover', over);
              events.remove(timeline, 'mouseout', out);
            };
            events.add(timeline, 'mouseover', over);
            events.add(timeline, 'mouseout', out);
          }*/
          this._rendered = true;
          // call the ready handler
          this._ready();
          return this;
        },
		
		/**
          * @public
          * @param {string} username - the owner of the list
          * @param {string} listName - the name of the list
          * return self
          */
        setList: function(username, listname) {
          this.listslug = listname.replace(/ /g, '-').toLowerCase();
          this.listname = listname;
		  this.username = username;
          this.url = 'http://www.pokertwitter.com/widget/listtweets.php?callback=PTWTR.Widget.receiveCallback' + '&strtype='+this.listname+'&no_of_records=' + this.opts.notweets;
		  this.setBase(listBase + username + '/lists/' + this.listslug + '/statuses.');
          this.setSearch(' ');
          return this;
        },
		
		setBase: function(b) {
          this._base = b;
          return this;
        },
		
		/**
          * @public
          * @return self
          * starts the cycle
          */
        start: function() {
          var that = this;
          /*if (!this._rendered) {
            setTimeout(function() {
              that.start.call(that);
            }, 50);
            return this;
          }
          if (!this._isLive) {
            this._getResults();
          }
          else {
            this.occasionalJob.start();
          }*/
		  this._getResults();
          this._isRunning = true;
          this._hasOfficiallyStarted = true;
		  setInterval("PTWTR_inst._getResults();",30000);
          return this;
        },
		
		/**
          * @private
          * @param {Function} callback function that receives the results
          * makes a jsonP call to twitter.com
          */
        _getResults: function() {
          var that = this;

          this.timesRequested++;
          this.jsonRequestRunning = true;

          /*this.jsonRequestTimer = window.setTimeout(function() {

            if (that.jsonRequestRunning) {
              clearTimeout(that.jsonRequestTimer);
              classes.add(that.spinner, 'twtr-inactive');
            }

            that.jsonRequestRunning = false;
            removeElement(that.scriptElement);
            that.newResults = false;
            that.decay();
          }, this.jsonMaxRequestTimeOut);*/
          //classes.remove(this.spinner, 'twtr-inactive');
          /*PTWTR.Widget.jsonP(that.url, function(script) {
            that.scriptElement = script;
          });*/
		  //url = 'http://www.pokertwitter.com/widget/listtweets.php' + '&callback=PTWTR.Widget.receiveCallback' + '&no_of_records=' + this.opts.notweets;
		  PTWTR.Widget.jsonP(that.url, function(script) {
            //alert(script);
			//eval()
			that.scriptElement = script;
          });

        },
		
		postPTTweet: function() {
          var that = this;
		  var pt_texttweet = document.getElementById("pt_texttweet").value;
		  if(pt_texttweet == "")
		  	return;

		  //url = 'http://www.pokertwitter.com/widget/listtweets.php' + '&callback=PTWTR.Widget.receiveCallback' + '&no_of_records=' + this.opts.notweets;
		  post_url = 'http://www.pokertwitter.com/widget/posttweet.php' + '?callback=PTWTR.Widget.receiveCallbackPost' + '&txttweet=' + pt_texttweet + '&widgetnumber=' + that.opts.widgetnumber + '&websitename=' + that.username;
		  PTWTR.Widget.jsonP(post_url, function(script) {
            //alert(script);
			//eval()
			that.scriptElement = script;
          });

        },
		
		_getWidgetHtml: function() {
          var that = this;

          function getHeader() {
              return '<div style="float:left; width:50%; overflow:hidden;"><h3>' + that.opts.title + '</h3><h4>' + that.opts.subject + '</h4></div><div style="float:left; width:50%; text-align:right;"><a target="_blank" href="http://www.pokertwitter.com/"><img alt="" src="http://www.pokertwitter.com/images/winter_02.png"></a></div>';
          }

          function isFull() {
            //return that._isFullScreen ? ' twtr-fullscreen' : '';
          }

          var html = '<div class="twtr-doc" style="width: ' + this.wh[0] + '; background-color: '+this.theme.shell.background+'; color: '+this.theme.shell.color+'">\
            <div class="twtr-hd">' + getHeader() + ' \
              <div class="twtr-spinner twtr-inactive"></div><!--<span id="pt_postbutton"><a href="javascript:void(null);" onclick="showpost();">Post Tweet</a></span>-->\
            </div>\
            <div class="twtr-bd">\
	          <!-- <div id="pt_postwidget" class="twtr-timeline" style="display:none; height: ' + this.wh[1] + '; background-color: '+this.theme.tweets.background+';"><textarea name="pt_texttweet" id="pt_texttweet" style="width:'+(parseInt(this.wh[0])-16)+'px; height:'+(parseInt(this.wh[1])-47)+'px; margin:5px 4px;" onkeyup="checkCharacters(this); return false;" onmouseover="return checkCharacters(this);" onblur="return checkCharacters(this);"></textarea><input type="button" value="update" onclick="PTWTR_inst.postPTTweet();">\
			  </div> -->\
              <div id="pt_listwidget" class="twtr-timeline" style="height: ' + this.wh[1] + '; background-color: '+this.theme.tweets.background+';">\
			  	<textarea name="pt_texttweet" id="pt_texttweet" style="width:'+(parseInt(this.wh[0])-34)+'px; height:49px; margin:5px 4px;" onkeyup="checkCharacters(this); return false;" onmouseover="return checkCharacters(this);" onblur="return checkCharacters(this);"></textarea><div align="center" style="border-bottom:1px dotted #DDDDDD;"><input type="button" value="Tweet!" onclick="PTWTR_inst.postPTTweet();"></div>\
                <div id="poker-twtr-tweets" class="twtr-tweets" style="color: '+this.theme.tweets.color+'">\
                  <div class="twtr-reference-tweet" id="twtrdata"></div>\
                  <!-- tweets show here -->\
                </div>\
              </div>\
            </div>\
            <div class="twtr-ft">\
              <div><a target="_blank" class="twtr-join-conv" href="http://www.pokertwitter.com/iphoneapplication.php" style="color:' + this.theme.tweets.links + '; font-size:11px;">Free iPhone app</a>\
                <!-- <span id="pt_postbutton"><a class="twtr-join-conv" style="color:' + this.theme.tweets.links + '" href="javascript:void(null);" onclick="showpost();">' + this.footerText + '</a></span> --><span id="pt_postbutton"><a target="_blank" class="twtr-join-conv" style="color:' + this.theme.tweets.links + '; font-size:11px;" href="http://www.pokertwitter.com/widget.php">Get this widget</a></span>\
              </div>\
            </div>\
          </div>';

          return html;
        },
		

			
		_prePlay: function(resp) {

          var that = this;
		  if (!browser.ie) {
            removeElement(this.scriptElement);
          }

          if (resp.error) {
            this.newResults = false;
          }

          else if (resp.tweets && resp.tweets.length > 0) {
            this.results = resp.tweets;

            this.newResults = true;
            //this.sinceId = resp.max_id;

            // where we do a little magic with the results
            //this._sortByMagic(resp.results);

            var html = '';
			this.results.forEach(function(needle) {
              needle.from_user = needle.username;
              needle.profile_image_url = needle.picture;
			  needle.tweetdetail = ify.clean(needle.tweetdetail);
			  html += '<div class="twtr-tweet"><div class="twtr-tweet-wrap"> \
				<div class="twtr-avatar"'+(that._avatars?'':' style="display:none;"')+'> \
				  <div class="twtr-img">'+(needle.iswidget=="yes"?'':'<a target="_blank" href="http://www.pokertwitter.com/' + needle.from_user + '/">')+'<img alt="' + needle.from_user + ' profile" src="' + needle.profile_image_url + '" onerror="this.src=\'http://www.pokertwitter.com/images/user.jpg\'">'+(needle.iswidget=="yes"?'':'</a>')+'</div> \
				</div> \
				<div class="twtr-tweet-text"'+(that._avatars?'':' style="margin:0px;"')+'> \
				  <p> \
					'+(needle.iswidget=="yes"? '<span style="color:'+that.theme.tweets.links+'">'+needle.from_user+' user</span>' : '<a target="_blank" href="http://www.pokertwitter.com/' + needle.from_user + '/" class="twtr-user">' + needle.from_user + '</a>')+' ' + needle.tweetdetail + ' \
					<i>\
					' + needle.timestamp + ' \
					</i> \
				  </p> \
				</div> \
			  </div></div>';
            });
			byId("poker-twtr-tweets").innerHTML = html;
          }

          else {
            this.newResults = false;
          }

        },
		
		_createTweet: function(o) {
          //o.timestamp = o.created_at;
          //o.created_at = this._isRelativeTime ? timeAgo(o.created_at) : absoluteTime(o.created_at);
          this.tweet = new Tweet(o);
          /*if (this._isLive && this.runOnce) {
            this.tweet.element.style.opacity = 0;
            this.tweet.element.style.filter = 'alpha(opacity:0)';
            this.tweet.element.style.height = '0';
          }*/
          return this;
        },
		
		setTheme: function(o, important) {
          var that = this;
          var imp = ' !important';

          // var onCreator = ((window.location.hostname.match(/twitter\.com/)) && (window.location.pathname.match(/goodies/)));
          // if (important || onCreator) {
          //   imp = '';
          // }
          this.theme = {
            shell: {
              background: function() {
                return o.shell.background || that._getDefaultTheme().shell.background;
              }(),

              color: function() {
                return o.shell.color || that._getDefaultTheme().shell.color;
              }()
            },

            tweets: {
              background: function() {
                return o.tweets.background || that._getDefaultTheme().tweets.background;
              }(),

              color: function() {
                return o.tweets.color || that._getDefaultTheme().tweets.color;
              }(),

              links: function() {
                return o.tweets.links || that._getDefaultTheme().tweets.links;
              }()
            }
          };

          var style = '#' + this.id + ' .twtr-doc, \
                     #' + this.id + ' .twtr-hd a, \
                     #' + this.id + ' h3, \
                     #' + this.id + ' h4 {\
            background: ' + this.theme.shell.background + imp + ';\
            color: ' + this.theme.shell.color + imp + ';\
          }\
          #' + this.id + ' .twtr-tweet a {\
            color: ' + this.theme.tweets.links + imp + ';\
          }\
          #' + this.id + ' .twtr-bd, #' + this.id + ' .twtr-timeline i a, \
          #' + this.id + ' .twtr-bd p {\
            color: ' + this.theme.tweets.color + imp + ';\
          }\
          #' + this.id + ' .twtr-new-results, \
          #' + this.id + ' .twtr-results-inner, \
          #' + this.id + ' .twtr-timeline {\
            background: ' + this.theme.tweets.background + imp + ';\
          }';

          if (browser.ie) {
            style += '#' + this.id + ' .twtr-tweet { background: ' + this.theme.tweets.background + imp + '; }';
          }

          rules = style;
		  var isLoaded = false;
		  var styleElement = document.createElement('style');
			styleElement.type = 'text/css';
			if (browser.ie) {
			  styleElement.styleSheet.cssText = rules;
			}
			else {
			  var frag = document.createDocumentFragment();
			  frag.appendChild(document.createTextNode(rules));
			  styleElement.appendChild(frag);
			}
			function append() {
			  document.getElementsByTagName('head')[0].appendChild(styleElement);
			}
	
			// oh IE we love you.
			// this is needed because you can't modify document body when page is loading
			if (!browser.ie || isLoaded) {
			  append();
			}
			else {
			  window.attachEvent('onload', function() {
				isLoaded = true;
				append();
			  });
			}
		  	
		  //ptwttr.css(style);
          return this;
        },
		
		resume: function() {
          var that = this;

          /*if (!this.isRunning() && this._hasOfficiallyStarted && this.intervalJob) {
            this._resumeTimer = window.setTimeout(function() {
              that.intervalJob.start();
              that._isRunning = true;
              classes.remove(that.widgetEl, 'twtr-paused');
            }, 2000);
          }*/

          return this;
        },
		
		pause: function() {
          /*if (this.isRunning() && this.intervalJob) {
            this.intervalJob.stop();
            classes.add(this.widgetEl, 'twtr-paused');
            this._isRunning = false;
          }

          if (this._resumeTimer) {
            clearTimeout(this._resumeTimer);
          }*/

          return this;
        },
		
		loadStyleSheet : function(url) {
		  var linkElement = document.createElement('link');
		  linkElement.href = url;
		  linkElement.rel = 'stylesheet';
		  linkElement.type = 'text/css';
		  document.getElementsByTagName('head')[0].appendChild(linkElement);
		  /*var timer = setInterval(function() {
			var style = getStyle(widgetEl, 'position');
			if (style == 'relative') {
			  clearInterval(timer);
			  PTWTR.Widget.hasLoadedStyleSheet = true;
			}
		  }, 50);*/
		}
	}
}();

})();

})();

			function showpost() {
				document.getElementById("pt_postwidget").style.display	=	"block";
				document.getElementById("pt_listwidget").style.display	=	"none";
				document.getElementById("pt_postbutton").innerHTML	=	'<a href="javascript:void(null);" onclick="listTweets();">List Tweets</a>';
			}
			function listTweets() {
				document.getElementById("pt_postwidget").style.display	=	"none";
				document.getElementById("pt_listwidget").style.display	=	"block";
				document.getElementById("pt_postbutton").innerHTML	=	'<a href="javascript:void(null);" onclick="showpost();">Post Tweet</a>';
			}
