//function getUrlVars pour récupérer la valeur d'un get
function getUrlVars(url)
{
	var vars = [], hash;
	var hashes = url.slice(url.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

//parser d'url
//@ pos = position non obligatoire si last = dernier, url = url à parser (non obligatoire)
function parseURL(pos, url)
{
	if(url == undefined || url == '')
		url = window.location.href;

	if(url.substr(0, 7) == 'http://')
		url = url.substr(7, url.length);

	var parsed = new Array();
	parsed = url.split(/\//g);

	if(pos == 'last'){
		return parsed[parsed.length - 1];
	}
	else if(isNaN(pos) == false)
		return parsed[pos];
	else
		return parsed;
}

function voidSearchBadChars()
{
	$('#search > fieldset > input').keyup(function(e){
		// check val for % in field (and remove it)
		var content = $(this).val();
		//alert(content);
		var reg = new RegExp("(%)", "g");
		content = content.replace(reg, "");
		$(this).val(content);
	});
}

$(function(){ //ready
	(function(){ //détection du nav + ajout d'une classe en rapport au body
		if($.browser.msie && $.browser.version=="6.0") $('body').addClass('msie6');
		if($.browser.msie && $.browser.version=="7.0") $('body').addClass('msie7');
		if($.browser.msie && $.browser.version=="8.0") $('body').addClass('msie8');
	})();

	//alert(parseURL('last'));
	if($('body').hasClass('msie6')){
	//si c'est la home ou choix de langue
		if(parseURL('last') == "index.php" || parseURL('last') == "fr.medipedia.be" || parseURL('last') == "nl.medipedia.be" || parseURL('last') == "www.medipedia.be" || parseURL('last') == "medipedia.be"){
			var noTitle = '',noSummary = '',noIE6 = '';

			if($('body').hasClass('fre')){
				noTitle = 'Vous utilisez actuellement une version de navigateur dépassée.';
				noSummary = 'Pour un meilleur confort de lisibilité du site Medipedia, nous vous conseillons de le mettre à jour ou de choisir un autre navigateur parmi ceux proposés ci-contre.';
			}
			else if($('body').hasClass('dut')){
				noTitle = 'U gebruik een oude versie van uw Internet navigatie system.';
				noSummary = 'Voor een betere leesbaarheid van de medipedia website raadplegen we u een update maken ofwel een andere Internet navigatie systeem in de lijst hieronder voorgesteld kiezen.';
			}
			else {
				noTitle = '';
				noSummary = '';
			}

			noIE6 = '<div style="border:1px solid #F7941D;background:#FEEFDA;text-align:center;clear:both;height:100px;position:relative;">'
					+'<div style="position:absolute;right:3px;top:3px;font-family:courier new;font-weight:bold;">'
						+'<a href="#" title="Fermer / Sluiten" onclick="javascript:this.parentNode.parentNode.style.display=\'none\';return false;">'
							+'<img src="./img/navClose.jpg" style="border:0;" alt="Fermer / Sluiten"/>'
						+'</a>'
					+'</div>'

					+'<div style="width:720px;margin:0 auto;text-align:left;padding:0;overflow:hidden;color:black;">'
						+'<div style="width:85px;padding:15px 0 0;float:left;">'
							+'<img src="./img/navWarning.png" alt="Warning!"/>'
						+'</div>'

						+'<div style="width:260px;float:left;font-family:Arial,sans-serif;">'
							+'<div style="font-size:14px;font-weight:bold;margin-top:12px;">'
								+noTitle
							+'</div>'
							+'<div style="font-size:12px;margin-top:6px;line-height:12px;">'
								+noSummary
							+'</div>'
						+'</div>'

						+'<div style="width:75px;float:left;">'
							+'<a href="http://www.browserforthebetter.com/download.html" target="_blank">'
								+'<img src="./img/navExplorer.png" alt="Internet Explorer" style="border:0;" />'
							+'</a>'
						+'</div>'
						+'<div style="width:75px;float:left;">'
							+'<a href="http://www.firefox.com" target="_blank">'
								+'<img src="./img/navFirefox.png" alt="Mozilla Firefox" style="border:0;" />'
							+'</a>'
						+'</div>'
						+'<div style="width:75px;float:left;">'
							+'<a href="http://www.google.com/chrome" target="_blank">'
								+'<img src="./img/navChrome.png" alt="Google Chrome" style="border:0;" />'
							+'</a>'
						+'</div>'
						+'<div style="width:75px;float:left;">'
							+'<a href="http://www.apple.com/safari/download/" target="_blank">'
								+'<img src="./img/navSafari.png" alt="Safari" style="border:0;" />'
							+'</a>'
						+'</div>'
						+'<div style="width:75px;float:left;">'
							+'<a href="http://www.opera.com/" target="_blank">'
								+'<img src="./img/navOpera.png" alt="Opera" style="border:0;" />'
							+'</a>'
						+'</div>'
					+'</div>'
				+'</div>';

			$('body').prepend(noIE6);
		}
	}

	if($('ul.dropdown').length){
		// affiche/cache le menu "Les maladies de A à Z"
		$('ul.dropdown').children('li').each(function(n){
			$(this).find('h3').click(function(e){
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					$(this).next().removeClass('open').addClass('close');
				}
				else {
					$('ul.dropdown h3').removeClass('active');
					$('ul.dropdown li ul').removeClass('open').addClass('close');
					$(this).addClass('active');
					$(this).next().removeClass('close').addClass('open');
				}
			});
		});
	}

	if($('form#search fieldset').length){
		var empty = $('form#search fieldset input').val(),
		clicked = false;
		$('#searchTypeBox span').click(function(){
			clicked = true;
		});
		$('form#search fieldset input')
		.focus(function(){
			if($('form#search fieldset input').val() == empty){
				$('form#search fieldset input').val('');
			}
			$('#searchTypeBox').stop(true,false).slideDown();
		})
		.blur(function(){
			if($('form#search fieldset input').val() == ''){
				$('form#search fieldset input').val(empty);
			}
			setTimeout(function(){// console.log(clicked);
				if(clicked){
					$('form#search fieldset input').focus();
				}
				else {
					$('#searchTypeBox').stop(true,false).slideUp();
				}
				clicked = false;
			},1500);
		});
		$('form#search fieldset button[type="submit"]').click(function(e){
			e.preventDefault();
			if($.trim($('form#search fieldset input').attr('value')) != '' && $('form#search fieldset input').attr('value') != empty && $('form#search fieldset input').attr('value').length > 3){
				var searchAction = $('form#search').attr('action')+'/'+$('form#search fieldset input').attr('value');
				if($('#searchTypeBox input:checked').length > 0){
					var searchAction=$('#searchTypeBox input:checked').attr('value')+'/'+$('form#search fieldset input').attr('value');
				}
				$('form#search').attr('action', searchAction);
				$('form#search').submit();
			}
		})
	}

	if($('a[rel~="external"]').length){
		// ouvre tous les liens rel="external" dans une nouvelle fenêtre
		$('a[rel~="external"]').click(function(e){
			e.preventDefault();
			window.open(this.href);
		});
	}

	if($('#summary ul li a[class^="rollOver"]').length){
		$('#summary ul li a[class^="rollOver"]').hover(function(){
			var itemId = $(this).parent('li').attr('id').substr(11);
			$('#summary img[id^="summaryPicture"]').hide();
			if($('#summary img#summaryPicture'+itemId).length){
				$('#summary img#summaryPicture'+itemId).show();
			}
		},
		function(){
			var itemId = $(this).parent('li').attr('id').substr(11);
			$('#summary img#summaryPicture'+itemId).hide();
			if($('#summary img.summaryActivePicture').length){
				$('#summary img.summaryActivePicture').show();
			}
		});
	}

	if($('li.multi-page').length){
		//if(typeof console.log == "function"){
			var multiWidth = $('li.multi-page').css('width','auto').width(),
			parentWidth = $('li.multi-page').parent().width();
			$('li.multi-page')
			.css({
				'margin-left' : -(multiWidth/2)
			});
		//}
	}


	if(/ipad|ipod|iphone|mobile/i.test(navigator.userAgent)){
		$('a.newsletter, a.subscribe, a.modify, a#sitemap').removeAttr('rel').click(function(e){
			e.preventDefault();
			e.stopPropagation();
			window.open( $(this).attr('href') );
		});
	}


	if($('a[rel^="prettyPhoto"]').length){
		// http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

		$('.pp_print').live('click',function(e){
			e.preventDefault();
			var src = this.href + '?src=',
			frameSrc = $('#pp_full_res iframe').attr('src');

			//petite fonction qui va chercher le param src dans l'url ;-)
			if(getUrlVars(frameSrc)['imgsrc'] != undefined)
			{
				//alert(getUrlVars(frameSrc)['imgsrc']);
				src = src + getUrlVars(frameSrc)['imgsrc'];
			}
			else if(getUrlVars(frameSrc)['src'] != undefined)
			{
				//alert(getUrlVars(frameSrc)['src']);
				src = src + getUrlVars(frameSrc)['src'];
			}

			window.open(src);
		});

			$('#see a[rel^="prettyPhoto"]').each(function(){
				$(this).attr('href', this.href.replace(/&amp;/g, "&"));
			});
			$('#see a[rel^="prettyPhoto"]').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: true,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 500,
				default_height: 580,
				deeplinking: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<p class="pp_description"></p> \
												<a class="pp_close" href="#">Close</a> \
												<a class="pp_print" href="printThis.php">Print</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src="{path}" width="{width}" height="430" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
				//if video or swf don't show print
				if($(this).attr('href').match('.flv') || $(this).attr('href').match('.swf'))
				{
					$('.pp_print').css('display','none');
				}
			});


			/*prettyPhoto sans bouton print*/
			$('.newsletter a[rel^="prettyPhoto"],.navigation a[rel^="prettyPhoto"],.share a[rel^="prettyPhoto"]').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: true,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 670,
				default_height: 450,
				deeplinking: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<a class="pp_close" href="#">Close</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});

			$('#legal a[rel^="prettyPhoto"]:not("#formContact,#sendToFriend"),a[rel^="prettyPhoto"].lb').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: true,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 800,
				default_height: 550,
				deeplinking: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<a class="pp_close" href="#">Close</a> \
												<a class="pp_print" href="printThis.php">Print</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});

			$('a.ads_popup_media_link').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 370,
				default_height: 306,
				deeplinking: false,
				allow_resize: false,
				markup: '<div id="pp_ads_popup" class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
												<a class="pp_close pp_special_close" href="#">Close</a> \
												<div class="pp_details clearfix"></div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"><a class="disableAdsPopups" href="#">'+((typeof adsPopupLabel == "undefined")?'Do not show pop up on this site':adsPopupLabel)+'</a></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
					//$('.pp_content').delay(2000).css({'height':'250px','overflow':'hidden'});
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});
			$('a.disableAdsPopups').live("click", function(e){
				e.preventDefault();
				setCookie("ads_popup", "1", 365);
				$.prettyPhoto.close();
				return false;
			});

			//Popup Contact : Special style
			$('a.formContact,a#formContact,a#sendToFriend').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: true,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 580,
				default_height: 380,
				deeplinking: false,
				allow_resize: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<a class="pp_close" href="#">Close</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});

			// ADS_POPUP
			$('a.ads_popup_link').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 302,
				default_height: 280,
				deeplinking: false,
				allow_resize: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
												<a class="pp_close pp_special_close" href="#">Close</a> \
											<div class="pp_details clearfix"></div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
				iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','auto');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});

			$('a#sitemap[rel^="prettyPhoto"]').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: false,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 800,
				default_height: 500,
				deeplinking: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<a class="pp_close" href="#">Close</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
						iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','hidden');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});

			$('a.iframeMe').prettyPhoto({
				theme : 'light_rounded',
				slideshow : 2000,
				allow_resize: false,
				animationSpeed : 'normal',
				overlay_gallery: false,
				default_width: 800,
				default_height: 575,
				deeplinking: false,
				markup: '<div class="pp_pic_holder"> \
							<div class="ppt">&nbsp;</div> \
							<div class="pp_top"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
							<div class="pp_content_container"> \
								<div class="pp_left"> \
								<div class="pp_right"> \
									<div class="pp_content"> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_fade"> \
											<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
											<div class="pp_hoverContainer"> \
												<a class="pp_next" href="#">next</a> \
												<a class="pp_previous" href="#">previous</a> \
											</div> \
											<div id="pp_full_res"></div> \
											<div class="pp_details clearfix"> \
												<a class="pp_close" href="#">Close</a> \
												<div class="pp_nav"> \
													<a href="#" class="pp_arrow_previous">Previous</a> \
													<p class="currentTextHolder">0/0</p> \
													<a href="#" class="pp_arrow_next">Next</a> \
												</div> \
											</div> \
										</div> \
									</div> \
								</div> \
								</div> \
							</div> \
							<div class="pp_bottom"> \
								<div class="pp_left"></div> \
								<div class="pp_middle"></div> \
								<div class="pp_right"></div> \
							</div> \
						</div> \
						<div class="pp_overlay"></div>',
						iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
				callback: function(){
					$('iframe html,body').css('overflow-x','hidden');
				}
			}).click(function(){
				$('iframe html,body').css('overflow-x','hidden');
			});
	}

	$('#see a.prettyPhoto').click(function(e){
		e.preventDefault();
		$(this).parent().parent().find('a[rel^="prettyPhoto"]').click();
	});

	if($('.switchBlock').length){
		$('.switchBlock').switchBlock();
	}

	if($('#links.article ul').length){
		var maxHeight2 = [0,0];

		$('#links.article ul:not(.multi-page) li').each(function(n){
			var current2 = $(this).innerHeight();
			if(n<=2){
				maxHeight2[0] = (maxHeight2[0]<current2)?current2:maxHeight2[0];
				$(this).height(maxHeight2[0]);
			}
			else {
				maxHeight2[1] = (maxHeight2[1]<current2)?current2:maxHeight2[1];
				$(this).height(maxHeight2[1]);
			}
		});
		$('#links.article ul:not(.multi-page) li').each(function(n){
			if(n<=2){
				$(this).height(maxHeight2[0]);
			}
			else {
				$(this).height(maxHeight2[1]);
			}
		});
	}

	$('.pathologies-js-menu').dropdown();

	/*if($('#favorite.article ul').length){
		resizeFavoritesCol();
	}*/

	// add popup behavior
	// comes from inline script in common (needs to be content-dynamic)

	voidSearchBadChars();

});
$(window).load(function(){
});

$(window).load(function(){
	//alert("window loaded");
	if($('#favorite.article ul').length){
		resizeFavoritesCol();
	}
	//prolonge la colonne de gauche et la colonne de droite en fonction du contenu centrale
	if($('#main .navigation').height()<=$('#content').outerHeight()){
		var substract = 10;
		if(/msie|MSIE 7/.test(navigator.userAgent)){ //if IE
			substract = 20;
		}
		$('#main .navigation').height($('#content').outerHeight() - substract);
	}
	if($('#sidebar').height()<=$('#section').outerHeight()){
		$('#sidebar').height($('#section').outerHeight());
	}

	/*alert($('#main .navigation').outerHeight());
	alert($('#sidebar').outerHeight() + $('#banner').outerHeight());

	setTimeout(function(){
		alert($('#main .navigation').outerHeight());
	alert($('#sidebar').outerHeight() + $('#banner').outerHeight());
	},3000);*/
	//showForm

	//Au chargement vérifie s'il faut ouvrir une popup ou pas
	if(getUrlVars(document.location.href) && getUrlVars(document.location.href)['showPopup'] != undefined){
		//alert(getUrlVars(document.location.href)['showPopup']);
		var showPopup = getUrlVars(document.location.href)['showPopup'];
		if( showPopup == "newsletter" )
		{
			//alert("show popup : "+showPopup);
			$('#header a.newsletter').click();
		}

		else if( showPopup == "editMember" )
		{
			$('#editMember').click();
		}

		else
		{
			//alert(showPopup);
			$("#legal a:eq("+showPopup+")").click();
		}
	}

	//Au chargement vérifie s'il faut ouvrir une popup ou pas
	if(getUrlVars(document.location.href) && getUrlVars(document.location.href)['showIframe'] != undefined){
		//alert($('.iframeMe').attr('href'));
		$('.iframeMe').click();
		//alert(showIframe);
	}
	if(getUrlVars(document.location.href)['showIframe'] != undefined){
		//alert(getUrlVars(document.location.href)['showIframe']);
		var showIframe = getUrlVars(document.location.href)['showIframe'];
		var idFrame = showIframe.substring(showIframe.length-6,showIframe.length);
		if($('#see a[rel^="prettyPhoto"][href*="'+idFrame+'"]').length){
			var x = setTimeout(function(){$('#see a[rel^="prettyPhoto"][href*="'+idFrame+'"]').click()},100);
		}
		else{
			$('<a class="iframeMe" href="'+showIframe+'&amp;width=670&amp;height=420&amp;iframe=true" rel="prettyPhoto[gallery]" style="display:none"><img src="#" alt="" /></a>').appendTo("#see");
			//on va chercher l'info titre de l'image
			$.ajax({
				url: showIframe+'?getTitle',
				success: function(data) {
					//alert(data);
					 $('.iframeMe img').attr('alt',data);
				}
			});
		}
		//alert(showIframe);
	}

	if(getUrlVars(document.location.href) && getUrlVars(document.location.href)['showMe'] != undefined){
		//alert($('.iframeMe').attr('href'));
		$('.iframeMe').click();
		//alert(showIframe);
	}

	if(getUrlVars(document.location.href)['showMe'] != undefined){
		//alert(getUrlVars(document.location.href)['showIframe']);
		var showMe = getUrlVars(document.location.href)['showMe'];
		//$('<a class="iframeMe" href="'+showMe+'?&amp;width=670&amp;height=420&amp;iframe=true" style="display:none"><img src="#" alt="" /></a>').appendTo("#legal");

		//$('#legal a.iframeMe').delay(1000).click();


		$.prettyPhoto.open(showMe+'?iframe=true&amp;width=670&amp;height=700&amp;allow_resize=false');
	}

	checkCookieForPopup();

});

function resizeFavoritesCol(){
	var maxHeight = [0, 0];

	$('#favorite.article ul li:not(.clear)').each(function(n){
		$(this).height('auto');
		var current = $(this).outerHeight();
		if(n<=2){
			maxHeight[0] = (maxHeight[0]<current)?current:maxHeight[0];
			$(this).height(maxHeight[0]);
		}
		else {
			maxHeight[1] = (maxHeight[1]<current)?current:maxHeight[1];
			$(this).height(maxHeight[1]);
		}
	});
	$('#favorite.article ul li:not(.clear)').each(function(n){
		if(n<=2){
			$(this).height(maxHeight[0]);
			if($(this).find('img').length){
				$(this).find('div').height($(this).find('div').outerHeight()-$(this).find('img').height() - 10);
			}
		}
		else {
			$(this).height(maxHeight[1]);
			if($(this).find('img').length){
				$(this).find('div').height($(this).find('div').outerHeight()-$(this).find('img').height());
			}
		}
	});
}
// switchBlock Plugin
(function($){
	$.fn.switchBlock = function(options){
		var opts = $.extend({},$.fn.switchBlock.defaults,options);

		return this.each(function(){
			init($(this));
			if(opts.autoPlay){
				autoPlay($(this));
			}
		});

		function init(o){
			opts.totalItem = o.find(opts.item).length;

			o.find(opts.nav).find('a').each(function(){
				$(this).removeClass('active');
			});
			o.find(opts.item).each(function(n){
				$(this).removeClass('open').addClass('close').hide();

				if(opts.ajax){
					if(opts.ajaxSrc != ''){
						$(this).load($(this).find(opts.ajaxSrc).attr('href'));
					}
					else {
						$(this).load(o.find(opts.nav).find('a:eq('+n+')').attr('href'));
					}
				}
			});
			showItem(o);
			if(opts.change){
				o.find(opts.nav).find('a').each(function(n){
					$(this).click(function(e){
						if(!$(this).hasClass('active')){
							e.preventDefault();

							clearInterval(opts.interval);

							hideItem(o);
							opts.currentPosition = n;
							showItem(o);
						}
					});
				});
			}
		}

		function hideItem(o){
			o.find(opts.nav+' a:eq('+opts.currentPosition+')').removeClass('active');
			o.find(opts.item+':eq('+opts.currentPosition+')')
				.stop(true,true)
				.fadeTo('slow',0,function(){
					$(this)
					.removeClass('open')
					.addClass('close')
					.hide();
				});
		}

		function showItem(o){
			o.find(opts.nav+' a:eq('+opts.currentPosition+')').addClass('active');
			o.find(opts.item+':eq('+opts.currentPosition+')')
				.stop(true,true)
				.fadeTo('slow',1,function(){
					$(this)
					.removeClass('close')
					.addClass('open');
				});
		}

		function autoPlay(o){
			opts.interval = setInterval(function(){
				hideItem(o);
				if(opts.totalItem > opts.currentPosition+1){
					opts.currentPosition++;
				}
				else {
					opts.currentPosition = 0;
				}
				showItem(o);
			},opts.delay);
		}
	};
	$.fn.switchBlock.defaults = {
		autoPlay : true,
		animSpeed : 500,
		change : false,
		currentPosition : 0,
		totalItem : 0,
		item : '.slide',
		nav : '.menu',
		interval : null,
		ajax : true,
		ajaxSrc : 'a',
		delay : 10000
	};
})(jQuery);
// dropdown Plugin
(function($){
	$.fn.dropdown = function(options){
		var opts = $.extend({},$.fn.dropdown.defaults,options);

		return this.each(function(){
			init($(this));
		});

		function init(o){
			var menu = $(o.attr('href'));
			menu.hide().addClass('close');

			o.click(function(e){
				e.preventDefault();
				e.stopPropagation();

				if(menu.hasClass('close'))
					showMenu(menu);
				else
					hideMenu(menu);
			});

			menu.bind("mouseleave",function(){
				setTimeout(function(){
					hideMenu(menu);
				},500);
			});

			$(window).click(function(){
				hideMenu(menu);
			});
		}

		function hideMenu(o){
			o.fadeOut('fast').removeClass('open').addClass('close');
		}

		function showMenu(o){
			o.fadeIn('fast').removeClass('close').addClass('open');
		}
	};
	$.fn.dropdown.defaults = {};
})(jQuery);
