function parserMeta(data) {
	if (data.title != null) {
		$('title').html(data.title);
	}
	if (data.description != null) {
		$('meta[name=description]').html(data.description);
	}
	if (data.keywords != null) {
		$('meta[name=keywords]').html(data.keywords);
	}
}

String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
  return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
  return this.replace(/\s+$/,"");
}

function handleChange(event) {
  var path = event.path;  
  path = path.ltrim('/') + '/seo';
  
	$.ajax({
		url : path,
		success : parserMeta,
		dataType : 'json'
	});
}

$(document).ready(function() {
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
});
