function cache_img_home(id) {
  jQuery('#hover_' + id).show();
}
function affiche_img_home(id) {
  jQuery('#hover_' + id).hide();
}
var scrolling = function() {
    var speed = 1000;
    jQuery('a[href^="#"]').bind('click', function() {
        var id = jQuery(this).attr('href');
        (id=="#")?goTo("body"):goTo(id);
        return (false);
    });
    function goTo(ancre) {
        jQuery('html,body').animate({
            scrollTop: jQuery(ancre).offset().top
        },
        speed, 'swing',
        function() {
            if (ancre != 'body')
            window.location.hash = ancre;
            else
            window.location.hash = '#';
            jQuery(ancre).attr('tabindex', '-1');
            jQuery(ancre).focus();
            jQuery(ancre).removeAttr('tabindex');
        });
    }
};

function changegauche() {
  jQuery("#content-scroll ").animate({ scrollLeft: '-=200' }, 'slow');
}
function changedroite() {
  jQuery("#content-scroll ").animate({ scrollLeft: '+=200' }, 'slow');
}
function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre) {
  window.open(nom_de_la_page, "PopUp ", "width = 600, height = 550, location = no, status = no, toolbar = no, scrollbars = no ");
}
function fermerimage() {
    jQuery(".transpa_bottom ").css("display ", "hidden ");
    jQuery('#image_uptexte').slideUp(500);
}
function affichephoto(image) {
    if (jQuery("#image_uptexte ").css("display ") == "none ") {
        jQuery("#fond_fiche_catalogue ").css("height ", 1100);
        jQuery("#fond_fiche_catalogue ").css("overflow ", "hidden ");
        jQuery(".transpa_bottom ").css("display ", "block ");
        var html = jQuery('#image_uptexte').html();
        jQuery('#image_uptexte').html('<img src="' + image + '" alt="" width="750px " height="498px " /><img src="/wp-content/themes/advitam/images/bouton_fermer.png " alt="fermer " class="image_fermer " onclick="fermerimage();" />');
        jQuery('#image_uptexte').slideDown(1000);
    } else {
        jQuery("#image_uptexte ").css("display ", "none ");
        jQuery("#image_uptexte ").fadeIn(1000);
        var html = jQuery('#image_uptexte').html();
        jQuery('#image_uptexte').html('<img src="' + image + '" alt="" width="750px "  height="498px " /><img src="/wp-content/themes/advitam/images/bouton_fermer.png " alt="fermer " class="image_fermer " onclick="fermerimage();" />');
    }
}

jQuery(function() {
    scrolling();

    //change the main div to overflow-hidden as we can use the slider now
    jQuery('#scroll-pane').css('overflow', 'hidden');

    //compare the height of the scroll content to the scroll pane to see if we need a scrollbar
    var difference = jQuery('#scroll-content').height() - jQuery('#scroll-pane').height();
    //eg it's 200px longer
    //if the scrollbar is needed, set it up...
    if (difference > 0) {
        var proportion = difference / jQuery('#scroll-content').height();
        //eg 200px/500px
        var handleHeight = Math.round((1 - proportion) * jQuery('#scroll-pane').height());
        //set the proportional height - round it to make sure everything adds up correctly later on
        handleHeight -= handleHeight % 2;

        jQuery("#scroll-pane ").after('<div id="slider - wrap "><div id="slider - vertical "></div></div>');
        //append the necessary divs so they're only there if needed
        jQuery("#slider-wrap ").height(jQuery("#scroll - pane ").height());
        //set the height of the slider bar to that of the scroll pane
        //set up the slider
        jQuery('#slider-vertical').slider({
            orientation: 'vertical',
            min: 0,
            max: 100,
            value: 100,
            slide: function(event, ui) {
                //used so the content scrolls when the slider is dragged
                var topValue = -((100 - ui.value) * difference / 100);
                jQuery('#scroll-content').css({
                    top: topValue
                });
                //move the top up (negative value) by the percentage the slider has been moved times the difference in height
            },
            change: function(event, ui) {
                //used so the content scrolls when the slider is changed by a click outside the handle or by the mousewheel
                var topValue = -((100 - ui.value) * difference / 100);
                jQuery('#scroll-content').css({
                    top: topValue
                });
                //move the top up (negative value) by the percentage the slider has been moved times the difference in height
            }
        });

        //set the handle height and bottom margin so the middle of the handle is in line with the slider
        jQuery(".ui-slider-handle ").css({
            height: handleHeight,
            'margin-bottom': -0.5 * handleHeight
        });

        var origSliderHeight = jQuery("#slider-vertical ").height();
        //read the original slider height
        var sliderHeight = origSliderHeight - handleHeight;
        //the height through which the handle can move needs to be the original height minus the handle height
        var sliderMargin = (origSliderHeight - sliderHeight) * 0.5;
        //so the slider needs to have both top and bottom margins equal to half the difference
        jQuery(".ui-slider ").css({
            height: sliderHeight,
            'margin-top': sliderMargin
        });
        //set the slider height and margins
    }
    //end if
    //code to handle clicks outside the slider handle
    jQuery(".ui-slider ").click(function(event) {
        //stop any clicks on the slider propagating through to the code below
        event.stopPropagation();
    });

    jQuery("#slider-wrap ").click(function(event) {
        //clicks on the wrap outside the slider range
        var offsetTop = jQuery(this).offset().top;
        //read the offset of the scroll pane
        var clickValue = (event.pageY - offsetTop) * 100 / jQuery(this).height();
        //find the click point, subtract the offset, and calculate percentage of the slider clicked
        jQuery("#slider-vertical ").slider("value ", 100 - clickValue);
        //set the new value of the slider
    });

    //additional code for mousewheel
    jQuery("#scroll-pane, #slider-wrap ").mousewheel(function(event, delta) {
        var speed = 5;
        var sliderVal = jQuery("#slider-vertical ").slider("value ");
        //read current value of the slider
        sliderVal += (delta * speed);
        //increment the current value
        jQuery("#slider-vertical ").slider("value ", sliderVal);
        //and set the new value of the slider
        event.preventDefault();
        //stop any default behaviour
    });
    jQuery('#lightbox').lightBox();
});

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 2
    });
    var img = new Image();
    img.src = "http://advitam.unity.fr/wp-content/themes/advitam/images/patienter.gif";
    // ajax pagination
    jQuery('#wp_page_numbers a').live('click',
    function() {
        // if not using wp-page-numbers, change this to correct ID
        var link = jQuery(this).attr('href');
        // #main is the ID of the outer div wrapping your posts
        jQuery('#main').html('<div class="titre_fiche_news cufon_titre"></div><div class="fond_fiche_catalogue pagibas2" id="fond_fiche_catalogue"><div class="loading"><img src="http://advitam.unity.fr/wp-content/themes/advitam/images/patienter.gif" alt="" /></div></div>');
        /*jQuery('#main').html('<div id="container" class="one-column">
        <div class="titre_fiche_news"></div>
        <div class="fond_fiche_catalogue pagibas" id="fond_fiche_catalogue">
        <div class="loading"><h2>Loading...</h2></div>      </div>
        </div>');*/

        // #entries is the ID of the inner div wrapping your posts
        jQuery('#main').load(link + ' #entries')
    });

});


