(function($) {
    
    /*IE6 PNG FIX*/
	if($.browser.msie && $.browser.version < 7){
		$.getScript("/fileadmin/templates/tv/js/DD_belatedPNG_0.0.8a-min.js", function() {
			DD_belatedPNG.fix('.imgInfoIcon,.imgHdIcon,.imgFacebookIcon,.imgShow .news');
			DD_belatedPNG.fix('.thumb-list-left,.thumb-list-right,.content-prev-image,.content-next-image');
				setTimeout(function () {
					DD_belatedPNG.fix('.wrapper-next,.wrapper-prev');
				},2000)
		});
	}

    
    $.fn.mediatheque = function (options) {
        var defaults = {
            width: false,
            heitht: false
        };

        var settings = $.extend(true, defaults, options);

        return this.each(function() {
            var mediatheque = $(this);
            var mediathequeContent = $('.content', this);
            var mediathequeBottom = $('.bottom', this);
            var mediathequeThumbList = $('.thumb-list', mediathequeBottom);
            var mediathequeThumbListContent = $('.list-content', mediathequeThumbList);
            var rubriqueList = $('.rubrique-list', this);
            var sousRubriqueList = $('.sous-rubrique-list', this);
            var thumbList = $('.thumb-list', this);
            var lastSelectedRubrique = null;
            var bottomHeight = mediathequeBottom.height();
            var bottomShrinkHeight = $('.shrink', mediathequeBottom).height();
            var currentlyMoving = false;
            var hasMoved = false;
	    	var currentPid = $("#currentPid");
	    	var currentLanguage = $("#currentLanguage");
            var IE6 = /msie|MSIE 6/.test(navigator.userAgent);
            var currentVisuelIdx = 0;

            initComponents();

            function initComponents()
            {
            	if( currentLanguage.html() == 1 ) {
            		currentLanguage = 'en';
            		$("div.enlarge").html("Enlarge");
            		$("div.reduce").html("Reduce");
            		$(".open-rubrique-list a").html("Gallery");
            	} else {
            		currentLanguage = 'fr';	
            		$("div.enlarge").html("Afficher");
            		$("div.reduce").html("Réduire");
            	}
				
                rubriqueList.css({
                    top: 0,
                    left: 0,
                    height: mediathequeContent.height() - mediathequeThumbList.height()
                });

                $.get(currentLanguage+'/presse/mediatheque/mediatheque_ajax/categorie/?uid='+currentPid.html(), loadRubriqueMenu);

                //load default gallerie
                $.get(currentLanguage+'/presse/mediatheque/mediatheque_ajax/galerie/?uid='+currentPid.html(), function(data){
                    loadGallerie(data);
		    var currentVisuel = $('li[id="gid-'+currentPid.html()+'"]', mediathequeThumbListContent);
		    if (currentVisuel.size() == 0)
			currentVisuel = $('li[class!="sous-rubrique"]:first', mediathequeThumbListContent);
		    else
			currentVisuel = $('li:eq(' + parseInt(currentVisuel.index() + 1) +')', mediathequeThumbListContent);
		    displayVisuel(currentVisuel, true);
		    //chargement image spécifique
		    var urlCurrent = jQuery(location);
			var parametresURL = getUrlVars();
			if(parametresURL['imgsrc'])
			{
				var img = parametresURL['imgsrc'].replaceAll("%2F","/");
				
				if($.browser.msie && $.browser.version <8){
					if($(".image a[href='http://"+window.location.hostname+img+"']").length>0){
						displayVisuel($(".image a[href='http://"+window.location.hostname+img+"']").parent().parent(),true);
					}
				}else{
					if($(".image a[href='"+img+"']").length>0){
						displayVisuel($('.image a[href="'+img+'"]').parent().parent(),true);
					}
				}

			}
			
            });
			

                $('.open-rubrique-list', thumbList).click(function() {
                    if ($(rubriqueList).is(':visible'))
                        closeSousRubrique(closeRubriqueList);
                    else
                        openRubriqueList();
                        
                    return (false);
                });

                $('.thumb-list-left', mediathequeThumbList).click(function(){
                    scrollThumbListLeft();
                    return (false);
                });

                $('.thumb-list-right', mediathequeThumbList).click(function(){
                    scrollThumbListRight();
                    return (false);
                });

                $('.shrink', mediathequeBottom).click(function() {
                    closeSousRubrique(function() {
			   closeRubriqueList(shrinkMediathequeBottom);
			});
                    return (false);
                });

                $('.contentInfo .contentLinks .info a', mediatheque).click(function() {
                    $('.image-details', mediathequeContent).fadeIn();
                    return (false);
                });

				if ( !$.browser.msie || parseInt($.browser.version, 10) > 8 )
                {
                    $('.contentInfo', mediatheque).hover(function mIn(){
                        $('.contentLinks', this).fadeIn('fast');
                    }, function mOut() {
                        $('.contentLinks', this).fadeOut('fast');
                    });

                    $('.contentInfo .content-next', mediatheque).hover(function mIn(){
                        $('.content-next-image', this).fadeIn('fast');
                    }, function mOut(){
                        $('.content-next-image', this).fadeOut('fast');
                    });

                    $('.contentInfo .content-prev', mediatheque).hover(function mIn(){
                        $('.content-prev-image', this).fadeIn('fast');
                    }, function mOut(){
                        $('.content-prev-image', this).fadeOut('fast');
                    });
                }
               else
               {
               		$('.content', mediatheque).mouseenter(function() {
               			$('.contentLinks', mediatheque).fadeIn('fast');
                        $('.content-next-image', mediatheque).fadeIn('fast');
                        $('.content-prev-image', mediatheque).fadeIn('fast');
               		});
               		
               		mediatheque.children(':not(.content, .contentInfo)').mouseenter(function() {
                        $('.contentLinks', mediatheque).fadeOut('fast');
                        $('.content-next-image', mediatheque).fadeOut('fast');
                        $('.content-prev-image', mediatheque).fadeOut('fast');
               		});
               		
               		mediatheque.mouseleave(function() {
                        $('.contentLinks', mediatheque).fadeOut('fast');
                        $('.content-next-image', mediatheque).fadeOut('fast');
                        $('.content-prev-image', mediatheque).fadeOut('fast');
               		});
               		
                    $('.content', mediatheque).hover(function mIn(){
                        
                    }, function mOut() {
                    });
               }

               $('.contentInfo .content-prev', mediatheque).click(displayPrevVisuel);

               $('.contentInfo .content-next', mediatheque).click(displayNextVisuel);
            }

	    function shrinkMediathequeBottom()
	    {
		if (mediathequeBottom.height() != bottomShrinkHeight){
			mediathequeBottom.animate({
                            height: bottomShrinkHeight,
                            marginTop: -bottomShrinkHeight
                        }, 'fast');
			$('.shrink .reduce', mediathequeBottom).hide();
			$('.shrink .enlarge', mediathequeBottom).show();
                    } else {
                        mediathequeBottom.animate({
                            height: bottomHeight,
                            marginTop: -bottomHeight
                        }, 'fast');
			$('.shrink .enlarge', mediathequeBottom).hide();
			$('.shrink .reduce', mediathequeBottom).show();
		    }
	    }

            function dragAndDrop(event)
            {
                var slider = $(this);
                if (!currentlyMoving)
                {
                    var start = event.pageX;
                    var waitingForEffect = false;

                    $('html').bind('mousemove', function (event) {
                        if (!waitingForEffect)
                        {
                            waitingForEffect = true;
                            var effectTimer = setInterval(function() {
                                waitingForEffect = false;
                                clearInterval(effectTimer);
                            }, 50);
                            if (parseInt(event.pageX - start) != 0)
                            {
                                currentlyMoving = true;
                                slider.animate({
                                    marginLeft: parseInt(slider.css('margin-left')) + parseInt(event.pageX - start)
                                    },
                                50, function() {
                                    currentlyMoving = false;
                                });
                                hasMoved = true;
                            }
                            start = event.pageX;
                            return ;
                        }
                    });

                    $('html').bind('mouseup', function () {
                        $('html').unbind('mouseup');
                        $('html').unbind('mousemove');
                        if (!hasMoved)
                            return ;
                        var tempTimer = setInterval(function () {
                            if (!currentlyMoving)
                            {
                                currentlyMoving = true;
                                var currentIndex = 0;
                                var currentPosition = 0;
                                var sliderLi = $('li', slider);
                                var sliderPosition = -parseInt(slider.css('margin-left'));

                                if (sliderPosition < 0) sliderPosition = 0;
                                for (; currentIndex < sliderLi.size(); ++currentIndex)
                                {
                                    currentPosition += $(sliderLi[currentIndex]).outerWidth();
                                    if (currentPosition > sliderPosition)
                                        break;
                                }
                                if (currentPosition + mediathequeThumbListContent.width() > slider.width())
                                    slider.animate({
                                        marginLeft: -(slider.width() - mediathequeThumbListContent.width())
                                        }, 50, function() {
                                        currentlyMoving = false;
                                        clearInterval(tempTimer);
                                    });
                                else
                                {
                                    var positionOnLi = sliderPosition - (currentPosition - $(sliderLi[currentIndex]).outerWidth());
                                    if (positionOnLi > ($(sliderLi[currentIndex]).outerWidth() / 2))
                                        slider.animate({
                                            marginLeft: -currentPosition
                                            }, 50, function() {
                                            currentlyMoving = false;
                                            clearInterval(tempTimer);
                                        });
                                    else
                                        slider.animate({
                                            marginLeft: -(currentPosition - $(sliderLi[currentIndex]).outerWidth())
                                            }, 50, function() {
                                            currentlyMoving = false;
                                            clearInterval(tempTimer);
                                        });
                                }
                            }
                        }, 100);
                    });
                }
                return (false);
            }
			
			function showLoader (loader){
				loader.fadeTo(300,0.7);

			}
			
			function hideLoader (loader){
				loader.fadeOut(300);
			}
			
			
            function loadSousRubriqueMenu(data, rubriqueWidth)
            {
                sousRubriqueList.css({
                    top: 0,
                    left: 0 + rubriqueWidth,
                    height: mediathequeContent.height() - mediathequeThumbList.height()
                });
                var sousRubriqueListUp = $('<div class=\"sous-rubrique-list-up\"></div>');
                var sousRubriqueListDown = $('<div class=\"sous-rubrique-list-down\"></div>');
				var sousRubriqueListLoader = $('<div class=\"sous-rubrique-list-loader\"><div class=\"loader\"></div></div>');
                var sousRubriqueListContent = $('<div class=\"sous-rubrique-list-container\">' + data + '</div>');
                sousRubriqueList.html('').append(sousRubriqueListUp).append(sousRubriqueListContent).append(sousRubriqueListDown).append(sousRubriqueListLoader);
                sousRubriqueListContent.css({
                    height: sousRubriqueList.height() - (sousRubriqueListUp.height() + sousRubriqueListDown.height()),
                    width: rubriqueWidth
                });

                $('.sous-rubrique-list-up', sousRubriqueList).click(function(){
                    scrollUpSousRubriqueList();
                    return (false);
                });

                $('.sous-rubrique-list-down', sousRubriqueList).click(function(){
                    scrollDownSousRubriqueList();
                    return (false);
                });

                $('li a', sousRubriqueListContent).click(function() {
                	currentPid.html($(this).parent().parent().find('.loadGalerieUid').html());
                	$("h1").html( $(this).parent().parent().find('.text').find('a').html() );
					
					$("<div class='content-loader'><div class='loader'></div></div>").appendTo($("#mediaTheque .content"));
                	closeSousRubrique(closeRubriqueList);
					showLoader($(".content-loader"));
					
                    $.get(currentLanguage+'/presse/mediatheque/mediatheque_ajax/galerie/?uid='+currentPid.html(), function(data){
						loadGallerie(data);
						var currentVisuel = $('li[id="gid-'+currentPid.html()+'"]', mediathequeThumbListContent);
						if (currentVisuel.size() == 0)
						currentVisuel = $('li[class!="sous-rubrique"]:first', mediathequeThumbListContent);
						else
						currentVisuel = $('li:eq(' + parseInt(currentVisuel.index() + 1) +')', mediathequeThumbListContent);
						displayVisuel(currentVisuel, true);
						
						hideLoader($(".content-loader"));
					});
                    	return (false);
                });

                if (sousRubriqueList.is(':visible') === false)
                    openSousRubriqueList();
            }

            function loadRubriqueMenu(data)
            {
                var rubriqueListContent = $('<div class=\"rubrique-list-container\">' + data + '</div>');
                var rubriqueListUp = $('<div class=\"rubrique-list-up\"></div>');
                var rubriqueListDown = $('<div class=\"rubrique-list-down\"></div>');
				
                rubriqueList.html('').append(rubriqueListUp).append(rubriqueListContent).append(rubriqueListDown);
                rubriqueListContent.css({
                    height: rubriqueList.height() - (rubriqueListUp.height() + rubriqueListDown.height())
                });
                $('.rubrique-list-up', rubriqueList).click(function(){
                    scrollUpRubriqueList();
                    return (false);
                });

                $('.rubrique-list-down', rubriqueList).click(function(){
                    scrollDownRubriqueList();
                    return (false);
                });

                var rubriqueWidth = rubriqueList.width();
                rubriqueList.css({
                    display: 'none'
                });

				 if($('li', rubriqueList).length==0){
					$(".open-rubrique-list").unbind();
					$(".open-rubrique-list a").text("");
					$(".open-rubrique-list a").click(function(){
						return false;
					});
				 }
				
                $('li a', rubriqueList).click(function() {
				
					if (sousRubriqueList.is(':visible') === false){
						var sousRubriqueListLoader = $('<div class=\"sous-rubrique-list-loader\"><div class=\"loader\"></div></div>');
						sousRubriqueList.append(sousRubriqueListLoader);
						sousRubriqueList.show();
						openSousRubriqueList();
					}
					showLoader($(".sous-rubrique-list-loader"));
					
					
                    if (lastSelectedRubrique !== null)
                        $('a', lastSelectedRubrique).css({
                            'text-decoration': '',
                            'font-weight': ''
                        });
                    lastSelectedRubrique = $(this).parent().parent();
                    $('a', lastSelectedRubrique).css({
                        'text-decoration': 'underline',
                        'font-weight': 'bold'
                    });
                    var index = (lastSelectedRubrique.index() % 2) + 1;

                    $.get(lastSelectedRubrique.find('a').attr('href'), function success(data){
                        loadSousRubriqueMenu(data, rubriqueWidth);
						hideLoader($(".sous-rubrique-list-loader"));
                    });
                    return (false);
                });
            }

            function loadGallerie(data)
            {
                mediathequeThumbListContent.html('').append(data);
                var mediathequeUl = $('ul', mediathequeThumbListContent);
                var mediathequeUlLi = $('li', mediathequeUl);
                var ulWidth = 0;

                for (var i = 0; i < mediathequeUlLi.size() ; i++)
                    ulWidth += parseInt($(mediathequeUlLi[i]).outerWidth(true));
                mediathequeUl.css('width', ulWidth);

                mediathequeUl.bind('mousedown', dragAndDrop);

                $('.image a', mediathequeUlLi).click(function() {
                    if (!hasMoved)
                        displayVisuel($(this).parent().parent());
                    hasMoved = false;
                    return (false);
                });
            }
			
			function addFacebookLink (link) {
				var isLink = $(".fdbk a").length>0;
				if(!isLink){
					$(".fdbk img").wrap('<a href="'+link+'" target="_blank"></a>');
				}else{
					$(".fdbk a").attr("href",link)
				}
			}
	
			function shareOnFacebook(title,url,desc,image) {
				t=encodeURIComponent(title);
				d=encodeURIComponent(desc);
				u=encodeURIComponent(url);
				i=encodeURIComponent(image);
				share_url='http://www.facebook.com/sharer.php';
				share_url+='?s=100&p[title]='+t+'&p[url]='+u;
				share_url+='&p[images][0]='+i;
				share_url+='&t='+t;
				return share_url;

			//http://www.facebook.com/sharer/sharer.php?s=100&p[title]=Arriv%E9e+de+l%27+A380+%E0+Montr%E9al+%3A+A380+%E0+Montr%E9al&p[url]=http://client.projet.afcorporate.noven-dev.net/fr/presse/mediatheque/photos/la-flotte-air-france/airbus-a318/&p[images][0]=http%3A%2F%2Fclient.projet.afcorporate.noven-dev.net%2Ftypo3temp%2Fpics%2FAir_France_-9285_01_980x600_bg_w.JPG&t=Arriv%E9e+de+l%27+A380+%E0+Montr%E9al+%3A+A380+%E0+Montr%E9al
				
			}

	
            function displayVisuel(visuel, ignoreAnimation)
            {
                if (!currentlyMoving || (ignoreAnimation === true))
                {
                    var lastVisuel = $('li.displayed:first', mediathequeThumbListContent);
                    if (lastVisuel.size() > 0)
                        lastVisuel.removeClass('displayed');
                    visuel.addClass('displayed');
					
					var facebookMetaTitle = $("meta[property='og:title']");
					var facebookMetaImage = $("meta[property='og:image']");
					var facebookLink = visuel.find(".urlImage").text();
					
                    currentVisuelIdx = visuel.index();
                    currentlyMoving = true;
					
                    var content = $('<div class="image-details">' + $('.image-details', visuel).html() + '</div><img class="currentimage" width="980px" height="600px" src="' + $('.image a', visuel).attr('href') + '"></img>');
					var title = $('.image a img', visuel).attr('rubTitle') +" : "+ $('.image a img', visuel).attr('alt');

					//maj info FB
					facebookMetaTitle.attr("content",title);
					facebookMetaImage.attr("content", "http://"+window.location.hostname+$('.image a', visuel).attr('href'));
					//important
					var url = "http://"+window.location.hostname+"/"+facebookLink;
					if($.browser.msie && $.browser.version <8){
						var urlImage = $('.image a', visuel).attr('href');
					}else{
						var urlImage = "http://"+window.location.hostname+$('.image a', visuel).attr('href');
					}

					addFacebookLink(shareOnFacebook(title,url,"",urlImage));

					$("h1").html( title );
                    $('.contentInfo .hd a', mediatheque).attr('href', $('.image a img', visuel).attr('hd'));
                    $('.contentInfo .hd a', mediatheque).attr('target', '_blank');
                    mediathequeContent.fadeOut('fast', function() {
                        $(this).html(content).fadeIn('fast', function(){
                            currentlyMoving = false;
                        });
                    });


                    centerThumbList();
                }
            }

            function displayNextVisuel()
            {
                var visuelIdx = currentVisuelIdx + 1;
                var currentVisuel;
                while ((currentVisuel = $('li:eq(' + visuelIdx + ')', mediathequeThumbListContent)).hasClass('sous-rubrique'))
                    visuelIdx += 1;
                if (currentVisuel.size() > 0)
                    displayVisuel(currentVisuel);
            }

            function displayPrevVisuel()
            {
                var visuelIdx = currentVisuelIdx - 1;
                var currentVisuel;
                while ((currentVisuel = $('li:eq(' + visuelIdx + ')', mediathequeThumbListContent)).hasClass('sous-rubrique'))
                    visuelIdx -= 1;
                if (currentVisuel.size() > 0)
                    displayVisuel(currentVisuel);
            }

            function centerThumbList()
            {
                var thumbListUl = $('ul', mediathequeThumbListContent);
                var thumbListUlLi = $('li', thumbListUl);
                var currentOffset = 0;
                var i;
                var liSize = $('li[class!="sous-rubrique"]:first', mediathequeThumbListContent).outerWidth(true);
                var center = parseInt((mediathequeThumbListContent.width() / 2) / liSize) * liSize;

                for (i = 0; i < currentVisuelIdx; ++i){
                    currentOffset += $(thumbListUlLi[i]).outerWidth(true);
                }
                currentOffset -= center;
                while ((currentOffset + mediathequeThumbListContent.width() > thumbListUl.width()))
                    currentOffset = thumbListUl.width() - mediathequeThumbListContent.width();
                if (currentOffset < 0)
                    currentOffset = 0;
                thumbListUl.animate({marginLeft: -currentOffset});
            }

            function scrollThumbListLeft()
            {
                if (currentlyMoving)
                    return ;
                var thumbListUl = $('ul', mediathequeThumbListContent);
                var thumbListUlLi = $('li', thumbListUl);
                var thumbListUlLiSize = thumbListUlLi.size();
                var currentMargin = - parseInt(thumbListUl.css('margin-left'));
                var currentOffset = 0;
                var firstLiIndex;

                for (firstLiIndex = 0; firstLiIndex < thumbListUlLiSize; firstLiIndex++) {
                    currentOffset += $(thumbListUlLi[firstLiIndex]).outerWidth(true);
                    if (currentOffset > currentMargin)
                        break;
                }
                if (firstLiIndex > 0)
                {
                    currentlyMoving = true;
		    currentOffset -= $(thumbListUlLi[firstLiIndex]).outerWidth(true);
		    if (currentOffset == currentMargin)
                    	currentOffset -= $(thumbListUlLi[firstLiIndex - 1]).outerWidth(true); 
                    thumbListUl.animate({
                        'margin-left': -currentOffset
                        }, 'fast', function() {
                            currentlyMoving = false;
                        });
                }
            }

            function scrollThumbListRight()
            {
                if (currentlyMoving)
                    return;
                var thumbListUl = $('ul', mediathequeThumbListContent);
                var thumbListUlLi = $('li', thumbListUl);
                var thumbListUlLiSize = thumbListUlLi.size();
                var currentMargin = - parseInt(thumbListUl.css('margin-left'));
                var currentOffset = 0;
                var firstLiIndex;

                for (firstLiIndex = 0; firstLiIndex < thumbListUlLiSize; firstLiIndex++) {
                    currentOffset += $(thumbListUlLi[firstLiIndex]).outerWidth(true);
                    if (currentOffset > currentMargin)
                        break;
                }
		if (currentOffset + mediathequeThumbListContent.width() > thumbListUl.width())
		    currentOffset = thumbListUl.width() - mediathequeThumbListContent.width();
    	        currentlyMoving = true;
	        thumbListUl.animate({
		    'margin-left': -currentOffset
		    }, 'fast', function(){
		        currentlyMoving = false;
		    });
            }

            function openSousRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                sousRubriqueList.css({
                    left: 0,
                    display: 'block'
                });

                sousRubriqueList.animate({
                    left: 310
                }, 'fast', function() {
                    currentlyMoving = false;
                });
            }

            function closeSousRubrique(callback)
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                sousRubriqueList.animate({
                    left: 0
                }, 'fast', function(){
                    sousRubriqueList.hide();
                    currentlyMoving = false;
                    callback();
                });
            }

            function scrollDownSousRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                var sousRubriqueListContainer = $('.sous-rubrique-list-container', sousRubriqueList);
                var sousRubriqueListUl = $('ul', sousRubriqueListContainer);
                var sousRubriqueListUlLiSize = $('li:first', sousRubriqueListUl).outerHeight();
                var newMarginTop = -parseInt(sousRubriqueListUl.css('margin-top')) + sousRubriqueListContainer.height();
                newMarginTop = parseInt(newMarginTop / sousRubriqueListUlLiSize) * sousRubriqueListUlLiSize;

                if ((newMarginTop + sousRubriqueListContainer.height()) > sousRubriqueListUl.height())
                    newMarginTop = sousRubriqueListUl.height() - sousRubriqueListContainer.height();
                sousRubriqueListUl.animate({
                    marginTop: -newMarginTop
                    }, 'slow', function() {
                        currentlyMoving = false;
                    });
            }

            function scrollUpSousRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                var sousRubriqueListContainer = $('.sous-rubrique-list-container', sousRubriqueList);
                var sousRubriqueListUl = $('ul', sousRubriqueListContainer);
                var sousRubriqueListUlLiSize = $('li:first', sousRubriqueListUl).outerHeight();
                var newMarginTop = -parseInt(sousRubriqueListUl.css('margin-top')) - sousRubriqueListContainer.height();
                newMarginTop = parseInt(newMarginTop / sousRubriqueListUlLiSize) * sousRubriqueListUlLiSize;

                if (newMarginTop < 0)
                    newMarginTop = 0;
                sousRubriqueListUl.animate({
                    marginTop: -newMarginTop
                }, 'slow', function() {
                    currentlyMoving = false;
                });
            }

            function scrollDownRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                var rubriqueListContainer = $('.rubrique-list-container', rubriqueList);
                var rubriqueListUl = $('ul', rubriqueListContainer);
                var rubriqueListUlLiSize = $('li:first', rubriqueListUl).outerHeight();

                var newMarginTop = -parseInt(rubriqueListUl.css('margin-top')) + rubriqueListContainer.height();
                newMarginTop = parseInt(newMarginTop / rubriqueListUlLiSize) * rubriqueListUlLiSize;
                if ((newMarginTop + rubriqueListContainer.height()) > rubriqueListUl.height())
                    newMarginTop = rubriqueListUl.height() - rubriqueListContainer.height();
                rubriqueListUl.animate({
                    marginTop: -newMarginTop
                    }, 'slow', function() {
                        currentlyMoving = false;
                    });
            }

            function scrollUpRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                var rubriqueListContainer = $('.rubrique-list-container', rubriqueList);
                var rubriqueListUl = $('ul', rubriqueListContainer);
                var rubriqueListUlLiSize = $('li:first', rubriqueListUl).outerHeight();

                var newMarginTop = -parseInt(rubriqueListUl.css('margin-top')) - rubriqueListContainer.height();
                newMarginTop = parseInt(newMarginTop / rubriqueListUlLiSize) * rubriqueListUlLiSize;
                if (newMarginTop < 0)
                    newMarginTop = 0;
                rubriqueListUl.animate({
                    marginTop: -newMarginTop
                }, 'slow', function() {
                    currentlyMoving = false;
                });
            }

            function openRubriqueList()
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                rubriqueList.css({
                    left: 0,
                    top: mediathequeContent.height() - mediathequeThumbList.height(),
                    height: 0,
                    display: 'block'
                });

                rubriqueList.animate({
                    height: (mediathequeContent.height() - mediathequeThumbList.height()),
                    top: 0
                }, 'fast', function() {
                    currentlyMoving = false;
                });
            }

            function closeRubriqueList(callback)
            {
                if (currentlyMoving)
                    return;
                currentlyMoving = true;
                rubriqueList.animate({
                    height: 0,
                    top: mediathequeContent.height() - mediathequeThumbList.height()
                }, 'fast', function(){
                    rubriqueList.css('display', 'none');
                    if (lastSelectedRubrique !== null)
                        $('a', lastSelectedRubrique).css({
                            'text-decoration': '',
                            'font-weight': ''
                        });
		    if (typeof(callback) !== "undefined")
			callback();
                    currentlyMoving = false;
                });
            }
            
            function getUrlVars() {
            var vars = {};
            window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                    vars[key] = value;
            });
            return vars;
    }
        });

        
    }
})(jQuery);


// replaceAllInString function
String.prototype.replaceAll = function(s1, s2) { return this.split(s1).join(s2)}






