/*
 * JavaScript Pretty Date
 * Copyright (c) 2008 John Resig (jquery.com)
 * Licensed under the MIT license.
 */

// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(time){
	
	timeBol = time.split(" ");
	timeYazi = timeBol[0]; 
	saatYazi = timeBol[1]; 
	
	timeTurkBol = timeYazi.split("-"); 
	saatTurkBol = saatYazi.split(":"); 
	timeTurk = timeTurkBol[2]+"."+timeTurkBol[1]+"."+timeTurkBol[0]+" "+saatTurkBol[0]+":"+saatTurkBol[1]; 


	var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
		diff = (((new Date()).getTime() - date.getTime()) / 1000),
		day_diff = Math.floor(diff / 86400);
			
	if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 3100 )
		return;
			
	return day_diff == 0 && (
			diff < 60 && "biraz önce" ||
			diff < 120 && "1 dakika önce" ||
			diff < 3600 && Math.floor( diff / 60 ) + " dakika önce" ||
			diff < 7200 && "1 saat önce" ||
			diff < 86400 && Math.floor( diff / 3600 ) + " saat önce") ||
		day_diff == 1 && "Dün" ||
		day_diff < 7 && day_diff + " gün önce" ||
		day_diff < 31 && Math.ceil( day_diff / 7 )  + " hafta önce" || 
		//day_diff < 365 && Math.ceil( day_diff / 30 ) + " ay önce" || 
		
		day_diff < 3100 && timeTurk + " tarihinde " 
		//day_diff < 3100 && Math.ceil( day_diff / 365 ) - 1 + " yıl önce" 
		;
}

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
	jQuery.fn.prettyDate = function(){
		return this.each(function(){
			var date = prettyDate(this.title);
			if ( date )
				jQuery(this).text( date );
		});
	};

