/* jQuery */
	function browserLessThanIE7() {
		return (/MSIE ((5\\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");
	}


	$(function() {
		// document ready
		$('<div id="loader"></div>')
			.insertBefore($('#wikiinfo'))
			.ajaxStart(function() {
				$('.colonne250 a').removeClass('currentLink');
				$('#copyright').remove();
				$('#wikiinfo').empty();
				$(this).show();;
			})
			.ajaxStop(function() {
				$(this).hide();;
			});
		// adding 'click' event on <a>
		$('.colonne250 a')
		.click(
			function(event) {
				// get href attribute
				loadingurl = $(this).attr('href');
				// avoid page loading
				event.preventDefault();
				// loading the file
				var ie7 = browserLessThanIE7();
				
				var request = $.post(	'services/services.php',
						{ url: loadingurl },
						function(html) {
							content = $('#content', html);
							// Replacing relative link by absolute link
							if( ie7 )
							{
								$('a[href^="http://"]', content)
								.each(
									function()
									{
										url = $(this).attr('href');
										if( url.indexOf("#", 0) > 0 ) {
											var i = url.indexOf("#", 0);
											$(this).attr({'href': url.substr( i, url.length)});
										}	
										else
											$(this).attr({'href': 'http://en.wikipedia.org' + url.substr( webroot.length, url.length) });
									}
								);
							} else {
								$('a[href^="/"]', content)
								.each(
									function()
									{
										url = $(this).attr('href');
										$(this).attr({'href': 'http://en.wikipedia.org' + url});
									}
								);
							}
							// A little bit of cleaning...
							$('table.navbox', content).remove();
							$('#jump-to-nav', content).remove();
							$('#contentSub', content).remove();
							$('#wikiinfo').append(content);
							// adding Wikipedia required copyright
							var author = loadingurl.substr(29, loadingurl.length-28);
							var html = '<div id="copyright">&copy; Copyright <a href="http://en.wikipedia.org/w/index.php?title=';
								html += author;
								html += '&amp;action=history" class="external text" rel="nofollow">author(s)</a>';
								html += ' - Source&nbsp;: <a href="' + loadingurl + '" class="external text" rel="nofollow">article on Wikipedia</a>';
								html += ' - This article is under <a href="http://creativecommons.org/licenses/by-sa/3.0/deed.fr" class="external text" rel="nofollow">CC-BY-SA</a></div>';
							$(html)
								.insertBefore($('#wikiinfo'));
						},
						"html"
				);
				
				// Adding <strong> tag around the current link
				$(this).addClass('currentLink');
				

			}
		);
	
	
	});