// McGowan

function log(s)
{
  try {console.log(s)} catch (e) {}
  var logEl = $('#anthumLogContent');
  if (logEl.length == 0)
  {
    logEl = $('<div id="anthumLog" ontouchstart="$(this).remove()" style="border-color: #dddddd; border-style: solid; border-width: 1px 1px 0 0; padding: 2px; position: absolute; bottom: 15px; left: 0px;background: black; color: green; font-size: 11px; font-family: arial;">\
               <div style="color: #aaaaaa !important; text-align: right;font-size: 9px"><a style="color: #aaaaaa !important; " href="javascript:void(0)" onclick="$(\'#anthumLog\').remove()">clear</a></div>\
               <div id="anthumLogContent" style="padding: 5px;"></div>\
             </div>');
    $('body').append(logEl);
    logEl = $('#anthumLogContent');
  }
  logEl.append(s+'<br />');
}

function showPreviewTab(i)
{ 
  
  var tds = $('#previewTabRow td');
  var content = $('#previewContentWrapper').children('div');
    tds.removeClass('active');
    $(tds[i]).addClass('active').css('cursor','select');
  $('#previewContentWrapper').fadeOut(100, function() {
    content.hide();
    $(content[i]).show();
    $(this).fadeIn(400);
  });
}

function setTweetsH()
{
  var totalH = 0;
  $('#homeMiddleContent .homePreviewItem').each(function() {
    var h =  $(this).outerHeight(true);
    totalH += h;
  });
  $('#tweetsOuter').css('height',totalH+'px');     
}



function initTwitter()
{
  $.ajax({
    url : "http://twitter.com/statuses/user_timeline/earn.json?callback=?",
    dataType : "json",
    timeout:15000,
    success : function(data)
    {
      var newText ='';
      for (i=0; i< data.length; i++)
      {
        var date = data[i].created_at;
        var text = data[i].text.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i,'<a target="_blank" href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1@<a href="http://www.twitter.com/$2">$2</a>').replace(/(^|\s)#(\w+)/g,'$1<a target="_blank" href="http://twitter.com/search?q=%23$2">#$2</a>');
        newText +=('<div class="tweet">' + text +"</div>");
        newText +=('<div class="tweetDesc">' + prettyDate(date) +" via "+ data[i].source+"</div>");
      }
      $("#tweets").html(newText);
      $('#tweets').hide().fadeIn(800);
    },
    error : function()
    {
      alert("Twitter could not be initialized!");
    }
  });
}  

function getDuplicatesRemoved(array) {
	var r = new Array();
	o:for(var i = 0, n = array.length; i < n; i++)
	{
		for(var x = 0, y = r.length; x < y; x++)
		{
			if(r[x]==array[i])
			{
				continue o;
			}
		}
		r[r.length] = array[i];
	}
	return r;
}

function logGAEvent(category, action, label)
{
  try
  {
    _gaq.push(['_trackEvent', category, action, label]);
    label = (label == null)? '' : (' - ' + label);
    //log(category +' - '+ action +label);
  } catch (e) {}}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function closeHomeTopBanner() {
	$("#home_page_banner").slideUp(function() {$(this).remove();});
}
