$(document).ready(function($) {

	// AddClass JS
	$('html').addClass('js');

	// Init Popup links
	(function() {

		$('img.links-ico-langs').each(function() {

			$(this).next('span').wrap('<span class="wrap-popup-link"></span>');
			$(this).appendTo($(this).next('span.wrap-popup-link'));
			$(this).after('<span class="lang-popup-arrow"></span>');
		});

	}());

	$('img.links-ico-langs').live('click', function(e) {
		e.preventDefault();
		if ($(this).parent('span').hasClass('active')) {
			$(this).parent('span').removeClass('active');
		} else {
			$('.wrap-popup-link').removeClass('active');
			$(this).parent('span').addClass('active');
		}
		if ($(this).offset().left > 910) {
			$(this).parent('.wrap-popup-link').addClass('near-right-edge');
		}
	});

	$('body').click(function(event) {
		var	c = event.target.getAttribute("class");
			c = ' ' + c + ' ';
		if (c.indexOf(" " + 'links-popup' + " ") > -1 || c.indexOf(" " + 'links-ico-langs' + " ") > -1 || c.indexOf(" " + 'lang-popup-arrow' + " ") > -1 || c.indexOf(" " + 'wrap-popup-link' + " ") > -1 || c.indexOf(" " + 'alIco' + " ") > -1) {

		} else {
			$('.wrap-popup-link').removeClass('active');
		}
	});

	// Test box shadow support
	(function() {
		var
			_head 	= $('head'),
			_body 	= $('body'),
			_div 	= document.createElement('div');

		_head.append('<style>#css-test { -moz-box-shadow:0px 0px 4px #000; -webkit-box-shadow: 0px 0px 4px #000; box-shadow:0px 0px 4px #000;}</style>');
		$(_div).attr('id', 'css-test');

		_body.append(_div);
		if ($(_div).css('box-shadow') != undefined || $(_div).css('-webkit-box-shadow') != undefined || $(_div).css('-moz-box-shadow') != undefined) {
			$('html').addClass('boxshadow');
		}

	})();

	/***
	* Load Ajax content from a link.
	* If there is an hash tag in the URI, the hash tag is used as the css selector
	***/
	(function() {
		if ($('a.ajax-content')) {
			var i = 0;
			$('a.ajax-content').each(function() {

				var
					_href = $(this).attr('href').split('#'),
					_hash = (_href[1]) ? _href[1] : 'ajax-content',
					_text = $(this).text();

				if ($(this).parents('#sidebar').length > 0) {
					$(this).parent('h2').after('<div id="ajax-' + i +'"></div>');
					$(this).parent('h2').attr('class', 'no-link').html(_text + '<span></span><span class="r"></span>');
				} else {
					$(this).after('<div id="ajax-' + i +'"></div>');
					$(this).remove();
				}

				$('#ajax-' + i).load(_href[0] + ' #' + _hash);

				i++;
			});
		}
	}());

	// Toggle sur les topics dans #nav
	/*$('#nav h2').disableSelection();

	$('#nav h2:not(.active)').live('click', function() {
		$(this).next('ul').children('li').hide();
		$(this).addClass('active');
	});

	$('#nav h2.active').live('click', function() {
		$(this).next('ul').children('li').show();
		$(this).removeClass('active');
	});*/

	// Topics
	$('#topics-button h2 span:not(.hover)').live('click', function(event) {
		event.preventDefault();
		$(this).addClass('hover');
		$('#topics-button #all-topics-list').show();
	});

	$('#topics-button h2 span.hover').live('click', function(event) {
		event.preventDefault();

		$(this).removeClass('hover');
		$('#topics-button #all-topics-list').hide();
	});

	$('#topics-button').hover(function() {
	},
	function() {
		$(this).children('h2').removeClass('hover');
		$('#topics-button #all-topics-list').hide();
	});

	// Newsroom-topic - change topic
	var _innerHtmlTopic = $('#newsroom h2, .newsroom-main #newsroom h2').html();
	$('#newsroom ul, .newsroom-main #newsroom ul').prepend('<li class="no-link">'+_innerHtmlTopic+'</li>');
	$('#newsroom h2, .newsroom-main #newsroom h2').remove();
	$('#newsroom, .newsroom-main #newsroom').append('<span class="arrow" />')

	$('html body #top span.arrow:not(.active)').live('click', function() {
		$(this).addClass('active');
		$('html body #top #newsroom ul').css({
			'overflow': 'visible',
			'height':'auto'
		});
	});

	$('html body #top #newsroom span.arrow.active').live('click', function() {
		$(this).removeClass('active');
		$('html body #top #newsroom ul').css({
			'overflow': 'hidden',
			'height':'25px'
		});
	});

	$('html body #top #newsroom ul').live('click', function() {
		if ($('html body #top #newsroom span.arrow').hasClass('active')) {
			$('html body #top #newsroom ul').css({
				'overflow': 'hidden',
				'height':'25px'
			});
			$('html body #top #newsroom span.arrow').removeClass('active');
		}
		else {
			$('html body #top #newsroom span.arrow').addClass('active');
			$('html body #top #newsroom ul').css({
				'overflow': 'visible',
				'height':'auto'
			});
		}
	});

	// Key Dates
	if ($('body').hasClass('dates')) {

		// Click on Key Dates
		$('#key-dates ul a').live('click', function(event) {
			event.preventDefault();

			$('#key-dates ul li.active').removeClass('active');

			var childLi = $(this).children('li');
			childLi.addClass('active');
			_html = childLi.children('div').children('div.outer').html();

			$('#key-dates-infos').html(_html);

		});

		// Init
		(function() {
			$('#content > div').addClass('div').wrapAll('<div id="key-dates"><ul></ul></div>');
			$('#content #key-dates ul > div').wrap('<li></li>');

			var kd = $('#key-dates');
			kd.before('<div id="key-dates-infos"></div>');
			kd.css('tabindex', '');

			$('#key-dates ul').css('width', ($('#key-dates li').length+0)*132);
			$('#key-dates ul li').wrap('<a href="" tabindex="0"></a>');
			$('#key-dates ul li > div').wrapInner('<div class="outer"></div>');

			//$('#key-dates ul li .outer *:not(h2)').hide();

			$('#key-dates h3').each(function() {
				$(this).replaceWith('<h2>' + $(this).text() + '</h2>');
			});

			$('#key-dates .outer').each(function() {
				//var parent = $(this).parent();
				$(this).children('h2:eq(0)').replaceWith('<span class="date">' + $(this).children('h2:eq(0)').text() + '</span>');
				$(this).children('span.date').prependTo($(this).children('h2:eq(0)'));
			});

			$('#key-dates ul a:first').click();

		}());

	}

	// Click on glossary
	$('#glossary li:not(.active) a').live('click', function(event) {
		event.preventDefault();
		$('#glossary-content .active').removeClass('active');
		$('#glossary li').removeClass('active');
		$(this).parent('li').addClass('active');
		$('#glossary-content ul').hide();
		$('h2#' + $(this).attr('href')).next('ul').show();
	});

	// Init Glossary (patch)
	(function() {
		$('#glossary li:not(.active) a:eq(0)').click();
	}());

	// Toggle
	$('.toggle').live('click', function() {
		$(this).toggleClass('toggle-active');
		$(this).next('.toggle-content').toggleClass('toggle-content-active');
	});

	// Documents tabs
	if (document.getElementById('documents-tabs')) {
		$('#tab-selection').live('change', function() {
			$('#documents-tabs h3.active-document-tab').removeClass('active-document-tab');
			$('#documents-tabs ul.active-document-tab-content').removeClass('active-document-tab-content');
			_hash = $(this).val();
			$('h3' + _hash).addClass('active-document-tab');
			$('h3' + _hash).next('ul:eq(0)').addClass('active-document-tab-content');
		});
	}

	// Documents tabs - selector
	//create an option tag for every menu li
	var selector = '<select id="tab-selection">';
	$('div#documents-tabs ul.summary li').each(function() {
		selector += '<option value="' + $(this).children('a').attr('href') + '">' + $(this).text() + '</option>';
	});
	selector += '</select>';

	$('div#documents-tabs').find('ul.summary').remove().end().prepend(selector);

	$('html body div.no-js').removeClass('no-js');

	// Share
        var contentBodyClass = $('html body').attr('class');
        
        if(contentBodyClass.match(' fr ')){
            $('html body #top #container #fontSize').after('<a id="share">Partager<span /></a>');
        }else if(contentBodyClass.match(' de ')){
            $('html body #top #container #fontSize').after('<a id="share">Weiterempfehlen<span /></a>');
        }else{
            $('html body #top #container #fontSize').after('<a id="share">Share<span /></a>');
        }
	
	iBeginShare.attachLink('share');

	reCenterViewport();

	//PROMO BUTTONS HOOVER EFFECT
	$('#promo-list li a').each(function(){
		var imgSrc= $(this).find('img').attr('src');
		var imgAlt= $(this).find('img').attr('alt');
		var newImgSrc= imgSrc.substr(0, imgSrc.lastIndexOf('/')+1)+'bw-'+imgSrc.substr(imgSrc.lastIndexOf('/')+1, imgSrc.length);	//create the url of black and white image by adding 'bw-'
		$(this).append('<img class="bw" src="'+newImgSrc+'" alt="'+imgAlt+'" />');
	});

	$('#promo-list li').hover(
		function() {
		$(this).find('img[class!="bw"]').show();
	},
		function() {
		$(this).find('img[class!="bw"]').hide();
	}
	);

	/* ALIGNS THE PROMO ICONS TO THE CENTER */
	/*if ($.browser.msie && ($.browser.version == '7.0')) {
		var iconLength = parseInt($('#promo-list li').css('margin-left'))+parseInt($('#promo-list li').css('margin-right'))+$('#promo-list li').width(); //total icon length
		var numberIcons = $('#promo-list li').size(); //number of icons
		var promoLenght = iconLength*numberIcons; //total lenght of promo icons
		$('#promo-list li:first-child').css('margin-left', (960-promoLenght)/2+'px');
	}*/



	// Search
	if (document.getElementById('search-results') && window.location.search) {
		(function ajaxLoadSearchResults(pContainer, pImageLoading){
			/* build the query */
			var poststr = "/archives/veritysearch/resultaction.jsp" + window.location.search;

			/* insert the title and the image before executing the request */
			if(document.getElementById(pContainer)) {
				document.getElementById(pContainer).innerHTML = '<img src="'+pImageLoading+'" />';
				//alert(pContainer);
				/* call the central javascript function to load the content of the page and paste it into the container */
				load_dynamic_panel_v2(poststr, poststr, pContainer, '', '<!-- End Search Form -->', '<!-- BOTTOM TOOLS SECTION -->', '',0, false,'');
			}
		})('search-results', '');
	}

	/* NEWSROOM */

	// Table of content - two column
	$('.toc').each(function() {
		var
			_this 	= $(this),
			li 		= _this.children('li').length
		;

			_this.wrap('<div class="toc-wrap clearfix"></div>');
		if(li>6){
			_this.css("width","170px");
			_this.parent('.toc-wrap').append('<ul class="toc toc-right"></ul>');

			_this.children('li:gt(' + Math.floor(li/2) + ')').appendTo(_this.parent('.toc-wrap').children('.toc-right'));

		}

	});

	// Video - Newsroom
	(function() { // Englobe tout dans une fonction auto exécutante pour avoir des variables avec un plus petit scope
		var url;
		var autostart= false;
		if (url = $('#preview1 a').attr('href')) { // Assigne la variable et la teste en même temps
			var image= $('#preview1 a img').attr('src');
			callVideo(url, autostart, image); // Utilise swfObject via ta fonction callVideo uniquement si il y a un match pour le if

			$('#videos ul li a').click(function(event) {
				event.preventDefault();
				image= $(this).prev('img').attr('src');	//image
				var videoTarget= $(this).attr('href');	//URL de la video ou du lien
				var ext= videoTarget.lastIndexOf('.') > -1 ? videoTarget.substr(videoTarget.lastIndexOf('.')+1, videoTarget.length) : ''; //renvoie l'extension
				if (ext == 'mp4'  || ext == 'flv') {
					autostart= true;	//fait démarrer la vidéo automatiquement au click
					var url2= $(this).attr('href');
					var vTitle= $(this).parent('li').find('h3').html(); //renvoie le titre
					var vDesc= $(this).text(); //renvoie le descriptif
					callVideo(url2, autostart, image);
					$('#video-data h3').html(vTitle);
					$('#video-data p').text(vDesc);
				}
				else {
					window.open(videoTarget);
				}
			});
		}
	}());

	// PAGINATION
	(function() {
		$('ul.paginate').each(function() {
			var
				_this 		= $(this),
				li 			= _this.children('li').length,
				liPerPage 	= 10,
				nbOfPages 	= Math.ceil(li/liPerPage),
				paginHtmlB	= '',
				paginHtmlT	= '',
				paginHtml	= '',
				_class		= '',
				ifNoTitle	= '';

			if (nbOfPages > 1) {

				ifNoTitle = ($('#top ul.notitle').length > 0) ? ' notitle' : '' ;

				paginHtmlB += '<ul class="pagination"><li class="prev disabled"><a tabindex="0" href="">Previous</a></li>';
				paginHtmlT += '<ul class="pagination top' + ifNoTitle +'"><li class="prev disabled"><a tabindex="0" href="">Previous</a></li>';

				for (var i=0; i<nbOfPages; i++) {

					_class = '';

					if (i == 0) {
						_class = ' class="first active"';
					} else if (parseInt(i+1) == nbOfPages) {
						_class = ' class="last"';
					}

					paginHtml += '<li' + _class + '><a tabindex="0" href="">' + parseInt(i+1) + '</a></li>';

				}

				paginHtmlB += paginHtml + '<li class="next"><a tabindex="0" href="">Next</a></li></ul>';
				paginHtmlT += paginHtml + '<li class="next"><a tabindex="0" href="">Next</a></li></ul>';

				_this.after(paginHtmlB);
				_this.before(paginHtmlT);

				_this.children('li').each(function(index) {
					var page = Math.floor((index*nbOfPages)/(nbOfPages*liPerPage)+1);
					$(this).addClass('page-' + page);
				});

				_this.children('li:not(.page-1)').hide();

			}

			$('ul.pagination li a').live('click', function(event) {
				event.preventDefault();
				if (!$(this).parent('li').hasClass('disabled') && !$(this).parent('li').hasClass('active')) {

					var
						_this 				=	$(this),
						page				=	_this.text(),
						_parent				=	_this.parent('li').parent('ul'),
						_ul					=	(_parent.hasClass('top')) ? _parent.next('ul.paginate') : _parent.prev('ul.paginate'),
						_otherPagination	= 	(_parent.hasClass('top')) ? _ul.next('ul.pagination') : _ul.prev('ul.pagination'),
						newActive
					;

					if (_this.parent('li').hasClass('next')) {
						page = parseInt(_parent.children('li.active').children('a').text())+1;
						newActive = _parent.children('li:eq(' + page + ')');
					} else if (_this.parent('li').hasClass('prev')) {
						page = parseInt(_parent.children('li.active').children('a').text())-1;
						newActive = _parent.children('li:eq(' + page + ')');
					} else {
						newActive = _this.parent('li');
					}

					_parent.children('li').removeClass('active');
					newActive.addClass('active');

					_ul.children('li').hide();
					_ul.children('li.page-' + page).show();

					// Enable / disable next/prev button
					_parent.children('li').removeClass('disabled');

					if (page == 1) {
						_parent.children('li.prev').addClass('disabled');
					} else if (page == nbOfPages) {
						_parent.children('li.next').addClass('disabled');
					}

					// Sync the two pager
					_otherPagination.html($(this).parent('li').parent('ul').html());
				}

			});

		});
	}());

	/* Vertical align in left menu */
	$('.home #nav li a').each(function() {
		var _m= ($(this).parent().height()-$(this).height())/2;
		$(this).css('padding-top', _m+'px').css('padding-bottom', _m+'px');
	});

	/*** BUILDS BOTH CAROUSELS ***/
	if ($('body.home').length > 0 ) {
		$('#list-news-ul').jcarousel({
		scroll: 1,
		wrap: 'circular'
	});

	$('#top-stories-ul').jcarousel({
		scroll: 2,
		wrap: 'circular'
	});
	}


	/*** HOVER EFFECT ON SECOND SLIDER  ***/
	$('.home #top-stories li div').each(function () {
		var _h = $(this).children('p:eq(0)').innerHeight();
		$(this).attr('title', _h);
		$(this).css('bottom', '-' + _h + 'px');
		if (_h) {
			$(this).addClass('has-hover');
		}
	});

	$('.home #top-stories li').each(function() {
		var img = $(this).children('div').children('img');
		$(this).css('background', 'url(' + img.attr('src') + ') no-repeat 0 0');
		img.css('opacity', '0');
	});
	/*
	$('.home #top-stories li div').hover(function(){
		$(this).filter(':not(:animated)').animate({ bottom: '0px' });
	}, function() {
		$(this).animate({ bottom: '-' + $(this).attr('data-hauteur') + 'px' });
	});*/


		$('.home #top-stories li div.has-hover').hover(function(){
			if (!$(this).hasClass('animated')) {
				$(this).dequeue().stop().animate({bottom: '0px'});
			}
		}, function() {
			$(this).addClass('animated').animate({bottom: '-' + $(this).attr('title')}, "normal", "linear", function() {
				$(this).removeClass('animated').dequeue();
			});
		});

	/*** CLICK EFFECT ON RIGHT_HAND MENU ***/

	/*$('.home #sidebar > div').click(function(){
			if (!$(this).hasClass('animated')) {
				$(this).dequeue().stop().animate({ height: 106+$(this).find('ul').height() });
			}
		}, function() {
			$(this).addClass('animated').animate({ height: 106 }, "normal", "linear", function() {
				$(this).removeClass('animated').dequeue();
			});
		});*/

	/*$('.home #sidebar > div ul').hide();
	$('.home #sidebar > div h3').click(function(){
		$(this).next().slideToggle();
	});*/

});

// Load the video
function callVideo(urlVideo, start, imagePath) {
		var s1 = new SWFObject('http://ec.europa.eu/wel/players/jwflvplayer/player.swf','player','400','300','9');
		s1.addParam('allowfullscreen','true');
		s1.addParam('allowscriptaccess','always');
		s1.addParam('allownetworking','all');
		s1.addParam('wmode','opaque');
		s1.addParam('flashvars','&file='+urlVideo+'&autostart='+start+'&image='+imagePath+'&skin=http://ec.europa.eu/wel/players/jwflvplayer/skins/mainley.swf');
		s1.write('preview1');
}



// Corrects viewport bug in webkit (document width is odd with centered background)
function reCenterViewport() {
	if ($.browser.webkit)	{
		var html = $('html');
		html.css('margin-left', '0');
		if ($(document).width()%2 > 0) {
			html.css('margin-left', '-1px');
		}
	}
}

$(window).resize(function() {
	reCenterViewport();
})

/***
* Load the content of an external file into a panel
***/
function load_dynamic_panel_v2(url, defaultUrl, panelId, substrAfterStartup, substrAfter, substrBefore, substrBeforeStartup, pLastIndexOfBefore, executeScript, pLoadingImg) {
	if(location.href.indexOf('wcmcom-ec-europa-eu-wip') == -1) {
		if(window.XMLHttpRequest) var xmlHttpReq = new XMLHttpRequest();
		else if (window.ActiveXObject) var xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

		xmlHttpReq.onreadystatechange = function set_dynamic_panel() {
			if (xmlHttpReq.readyState == 4) {
				var problem;
				if (xmlHttpReq.status != 200 && xmlHttpReq.status != 304) {
					/* error getting URL */
					problem = true;
				} else {
					problem = false;
					/* URL reached, search content */
					var response = xmlHttpReq.responseText;

					/* execute a substring-before and substring-after on the response if it's necessary */
					if(substrAfter != '') {
						if(substrAfterStartup != ''){
							if(response.indexOf(substrAfterStartup)>=0){
								response = response.substring(response.indexOf(substrAfterStartup), response.length);
							}
						}
						if(response.indexOf(substrAfter)>=0){
							response = response.substring(response.indexOf(substrAfter), response.length);
						}
						else {
							substrAfter = substrAfter.replace('&gt;', '>');
							substrAfter = substrAfter.replace('&lt;', '<');
							/*try in another format */
							if(response.indexOf(substrAfter, lIndex)>=0){
								response = response.substring(response.indexOf(substrAfter), response.length);
							}
							else {
								response = '';
							}
						}
					}
					if(substrBefore != '') {
						if(substrBeforeStartup != ''){
							if(response.indexOf(substrBeforeStartup)>=0){
								response = response.substring(0, response.lastIndexOf(substrBeforeStartup));
							}
						}

						if(response.indexOf(substrBefore)>=0) {
							if(pLastIndexOfBefore){
								response = response.substring(0, response.lastIndexOf(substrBefore));
							}
							else{
								response = response.substring(0, response.indexOf(substrBefore));
							}
						}
						else {
							substrBefore = substrBefore.replace('&gt;', '>');
							substrBefore = substrBefore.replace('&lt;', '<');
							/*try in another format */
							if(response.indexOf(substrBefore)>=0) {
								response = response.substring(0, response.indexOf(substrBefore));
							}
							else
							{
								response = "";
							}
						}
					}

					var pID = document.getElementById(panelId);
					if(pID) {
						var responseContainer = '<' + pID.tagName.toLowerCase() + ' id="' + panelId + '">';
						if(response.indexOf(responseContainer)!= -1) {
							response = response.replace(responseContainer, '');
							response = response.replace(response.lastIndexOf('</' + pID.tagName.toLowerCase() + '>'), '');
						}
						pID.innerHTML = response;

						if(executeScript){
							/*extract javascript*/
							var lFlagScript = '<script language="JavaScript" type="text/javascript">';
							var lIndexScriptTag = response.lastIndexOf(lFlagScript);
							if(lIndexScriptTag >= 0) {
								/* skip variable declaration 'var' for compatibility with Internet Explorer 6 and ajax evaluation script */
								var localscript = response.substring(lIndexScriptTag+lFlagScript.length, response.lastIndexOf('</script>'));
								if(localscript!='')
									global.eval(localscript);
							}
						}
					}
					adaptFontSize('tab_panel_select');
				}
				if (problem == true) {
					/* do something with problem*/
					//$(panelId).addClassName('dynPanel_notFound');
					document.getElementById(panelId).className = 'dynPanel_notFound';
					/*addClassName(panelId, "dynPanel_notFound");*/

					/* try with the default url */
					if(defaultUrl != '')
						return load_dynamic_panel_v2(defaultUrl, '', panelId, substrAfter, substrBefore);
					else
						return true;
					}
				}
			}
		var myRand=parseInt(Math.random()*99999999); // cache buster
		if(url.indexOf("?")>0){
			url= url + "&rand=" + myRand;
		}else{
			url= url + "?rand=" + myRand;
		}

		var lhtml = xmlHttpReq.open("GET", url, true);
		xmlHttpReq.setRequestHeader("Cache-Control", "no-cache");
		xmlHttpReq.send(null);
	}
}

// PAGINATION
	if ($('#news-list').length > 0) {
		alert('test');

		var
			MAX_ART = ($('#news-list').attr('rel') == undefined) ? '10' : $('#news-list').attr('rel'),
			LI = '',
			pagination,
			nb = Math.ceil(($('#news-list > li').length / MAX_ART)),
			s = 0,
			page = 1;

		if (nb>1) {

			for (i=1; i<=nb; i++) {
				LI += '<li';

				if (i==1)  {LI += ' class="on"';}
				if (i==nb) {LI += ' class="last"';}

				LI += '><a href="#">' + i + '</a></li>';

			}

			$('#news-list > li').each(function(){

				if (s < MAX_ART) {

					$(this).attr('rel', page);

				} else if (s == MAX_ART) {
					s = 0;
					page++;
					$(this).attr('rel', page);
				}
				s++;
			});

			pagination = '<div id="pagination"><a class="ctrl prev disabled" href="#">&lt;&lt;</a><ul>'+LI+'</ul><a class="ctrl next" href="#">&gt;&gt;</a></div>';

			$('#content').append(pagination);

			centerPagination();

			$('#pagination a').live('click', function(event) {
				event.preventDefault();
			});

			$('#pagination li:not(.on) a, #pagination > a').live('click', function() {

				var current = $('#pagination li.on').index()+1;

				if(!$(this).hasClass('disabled') && !$(this).parent().hasClass('on')) {

					if($(this).hasClass('ctrl')) {

						if($(this).hasClass('prev')) {
							showPage(current-1, i-1);
							_hash = 'page-' + parseInt(current-1);

						} else {
							showPage(current+1, i-1);
							_hash = 'page-' + parseInt(current+1);
						}
					} else {
						showPage($(this).parent().index()+1, i-1);
						_hash = 'page-' + parseInt($(this).parent().index()+1);
					}

				}

				window.location.hash = _hash;

			});

			// Display the current page according to the hash
			updatePage();

			$(window).hashchange(function(){
				if(window.location.hash.split('#page-').length > 1) {
					updatePage();
				}
			});

		}

		//focus on the 'more' link when mouse is over article abstract
		$('#news-list .text p').mouseover(function() {
			$(this).parent().next().focus();
		});

		$('#news-list .text p').mouseout(function(){
			$(this).parent().next().blur();
		});

	}

	function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

/*  search */

function ajaxSearch(pContainer, pImageLoading){
  /* build the query */
  var poststr = "/archives/veritysearch/resultaction.jsp" + window.location.search;

 /* insert the title and the image before executing the request */
 if(document.getElementById(pContainer)){
	 document.getElementById(pContainer).innerHTML = '<img src="'+pImageLoading+'" />';

	 /* call the central javascript function to load the content of the page and paste it into the container */
	 load_dynamic_panel_v2(poststr, poststr, pContainer, '', '<!-- End Search Form -->', '<!-- BOTTOM TOOLS SECTION-->', '',0, false,'');
 }
}

/* load the content of an external file into a panel */
function load_dynamic_panel_v2(url, defaultUrl, panelId, substrAfterStartup, substrAfter, substrBefore, substrBeforeStartup, pLastIndexOfBefore, executeScript, pLoadingImg) {
	if(location.href.indexOf('wcmcom-ec-europa-eu-wip') == -1) {

		if(window.XMLHttpRequest) var xmlHttpReq = new XMLHttpRequest();
		else if (window.ActiveXObject) var xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

		xmlHttpReq.onreadystatechange = function set_dynamic_panel() {
			if (xmlHttpReq.readyState == 4) {
				var problem;
				if (xmlHttpReq.status != 200 && xmlHttpReq.status != 304) {
					/* error getting URL */
					problem = true;
				} else {
					problem = false;
					/* URL reached, search content */
					var response = xmlHttpReq.responseText;

					/* execute a substring-before and substring-after on the response if it's necessary */
					if(substrAfter != '') {
						if(substrAfterStartup != ''){
							if(response.indexOf(substrAfterStartup)>=0){
								response = response.substring(response.indexOf(substrAfterStartup), response.length);
							}
						}

						if(response.indexOf(substrAfter)>=0){
							response = response.substring(response.indexOf(substrAfter), response.length);
						}
						else {
							substrAfter = substrAfter.replace('&gt;', '>');
							substrAfter = substrAfter.replace('&lt;', '<');
							/*try in another format */
							if(response.indexOf(substrAfter, lIndex)>=0){
								response = response.substring(response.indexOf(substrAfter), response.length);
							}
							else
							{
								response = "";
							}
						}
					}
					if(substrBefore != '') {
						if(substrBeforeStartup != ''){
							if(response.indexOf(substrBeforeStartup)>=0){
								response = response.substring(0, response.lastIndexOf(substrBeforeStartup));
							}
						}

						if(response.indexOf(substrBefore)>=0) {
							if(pLastIndexOfBefore){
								response = response.substring(0, response.lastIndexOf(substrBefore));
							}
							else{
								response = response.substring(0, response.indexOf(substrBefore));
							}
						}
						else {
							substrBefore = substrBefore.replace('&gt;', '>');
							substrBefore = substrBefore.replace('&lt;', '<');
							/*try in another format */
							if(response.indexOf(substrBefore)>=0) {
								response = response.substring(0, response.indexOf(substrBefore));
							}
							else
							{
								response = "";
							}
						}
					}

					var pID = document.getElementById(panelId);
					if(pID) {
						var responseContainer = '<' + pID.tagName.toLowerCase() + ' id="' + panelId + '">';
						if(response.indexOf(responseContainer)!= -1) {
							response = response.replace(responseContainer, '');
							response = response.replace(response.lastIndexOf('</' + pID.tagName.toLowerCase() + '>'), '');
						}
						pID.innerHTML = response;

						if(executeScript){
							/*extract javascript*/
							var lFlagScript = '<script language="JavaScript" type="text/javascript">';
							var lIndexScriptTag = response.lastIndexOf(lFlagScript);
							if(lIndexScriptTag >= 0) {
								/* skip variable declaration 'var' for compatibility with Internet Explorer 6 and ajax evaluation script */
								var localscript = response.substring(lIndexScriptTag+lFlagScript.length, response.lastIndexOf('</script>'));
								if(localscript!='')
									global.eval(localscript);
							}
						}
					}
					adaptFontSize('tab_panel_select');
				}
				if (problem == true) {
					/* do something with problem*/
					$(panelId).addClassName('dynPanel_notFound')
					/*addClassName(panelId, "dynPanel_notFound");*/

					/* try with the default url */
					if(defaultUrl != '')
						return load_dynamic_panel_v2(defaultUrl, '', panelId, substrAfter, substrBefore);
					else
						return true;
					}
				}
			}
		var myRand=parseInt(Math.random()*99999999); // cache buster
		if(url.indexOf("?")>0){
			url= url + "&rand=" + myRand;
		}else{
			url= url + "?rand=" + myRand;
		}

		var lhtml = xmlHttpReq.open("GET", url, true);
		xmlHttpReq.setRequestHeader("Cache-Control", "no-cache");
		xmlHttpReq.send(null);
	}
}

/* fin search */

