
function quoobs() {

  // fade out of teaser on click
  //$('#teaser').click(function () {
  //  $('#teaser').fadeOut('slow');
  //});
		
		// randon main image
		function getRandom( min, max ) {
		  if( min > max ) {
		    return( -1 );
		  }
		  if( min == max ) {
		    return( min );
		  }
		  return( min + parseInt( Math.random() * ( max-min+1 ) ) );
		}
		
		// Twitter
		var url = "http://twitter.com/status/user_timeline/Maatzel.json?count=4&callback=?";
  $.getJSON(url,
		function(data){
	   $.each(data, function(i, item) {
		    //$("img#profileImg").attr("src", item.user["profile_image_url"]); 
		    $("#tweets ul").append("<li>" + item.text.linkify() + " <br /><span class='created_at'>" + relative_time(item.created_at) + " via " + item.source + "</span></li>");
	   });
				adjustContentHight();
  });
		// Twitter End
		
		// 4 is current count of main images
  var source = "url(img/berlin_0" + getRandom(1, 4) + ".jpg)";
  document.getElementById("image").style.backgroundImage = source;
}

// Twitter
String.prototype.linkify = function() {
  return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
    return m.link(m);
  });
};

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);
 
  var r = '';
  if (delta < 60) {
    r = 'a minute ago';
  } else if(delta < 120) {
    r = 'couple of minutes ago';
  } else if(delta < (45*60)) {
    r = (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (90*60)) {
    r = 'an hour ago';
  } else if(delta < (24*60*60)) {
    r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    r = '1 day ago';
  } else {
    r = (parseInt(delta / 86400)).toString() + ' days ago';
  }
 
  return r;
}

function adjustContentHight() {
  // css alignment for browser behaviours
		var newsDiv = document.getElementById('news');
		var feedtextDiv = document.getElementById('feedtext');
		var feedsDiv = document.getElementById('feeds');
		if(newsDiv.offsetHeight <= (feedsDiv.offsetHeight)) {
		  newsDiv.style.height = (feedsDiv.offsetHeight).toString() + "px";
		}
		else {
		  //feedtextDiv.style.height = (newsDiv.offsetHeight - 100).toString() + "px";
				feedsDiv.style.height = (newsDiv.offsetHeight).toString() + "px";
		}
		// centric alignment of content area
		var body = document.getElementsByTagName('body')[0];
		var bodyDiv = document.getElementById('body');
		if(bodyDiv.offsetWidth < body.offsetWidth) {
		  bodyDiv.style.marginLeft = ((body.offsetWidth - bodyDiv.offsetWidth)/2).toString() + "px";
		}
}

