$(document).ready(function() {
	
	// 10.06.2010, Tomi -- Get Google Statistics with AJAX, because fetching the data can take some time and therefore slows page load
	getGAStatistics();

	// 19.10.2010, Tomi -- TinyMCE has a bug and doesn't understand clear urls (it seems them as directories)
	fixAnchors();
	
	function getGAStatistics() {
		if(document.getElementById('gastatistics')) {
			$.post('ajax_actions.php', {act: 'getGAStatistics'},
				function(returned_data) {
					if(returned_data != '') {
						$("div#gastatistics").html(returned_data);
					}
					else {
						$("div#gastatistics").html('Google Analytics -tilastoja ei ole t&auml;ll&auml; hetkell&auml; tarjolla.');
					}
				}
			);
		}
	}
	
	// 19.10.2010, Tomi -- Fixes TinyMCE bug with anchors
	// Tested with Firefox 3.6, IE 6,7,8,9, Opera 10.6, Safari 5, Google Chrome 6
	function fixAnchors() {
		var url = window.location.href.split('#')[0];
		$("div#pagetext a[href^='#']").each(
			function() {
				//var newurl = url + $(this).attr('href');
				$(this).attr('href', url + $(this).attr('href'));
			}
		);
	}
	
	
});



