$(document).ready(function () {
    var classes = ((navigator.userAgent.indexOf('Safari') > -1) && (navigator.userAgent.indexOf('Chrome') == -1) ? 'safari ' : '') + ((navigator.userAgent.indexOf('Chrome') > 0) ? 'chrome ' : '') + ((navigator.userAgent.indexOf('Mac') > -1) ? 'mac' : '');
    $('body').addClass(classes);
    $('.onglets').tabs();
    menu();
    carousel();
});

function carousel() {
    $('.gallery-thumbnails li').eq(0).remove();
    
    if ($('.gallery-thumbnails img').size() > 7) {
        $('.btn_prev').show();
        $('.btn_next').show();
        $(".carouselWrapper").jCarouselLite({
            btnNext: ".btn_next",
            btnPrev: ".btn_prev",
            visible: 8,
            circular: false
        });
    }
    
    $('.gallery-thumbnails a').live('click', function (event) {
        var gallery = $(this).parents('.gallery');
        var index = $('img',this).attr('data');
        var caption = $('.gallery-main-picture-caption', gallery);
        //if (index < $('.gallery-main-picture img', gallery).size()) {
        $('.gallery-thumbnails a.thumb', gallery).removeClass('selected');
        $(this).addClass('selected');
        $('.gallery-main-picture img:visible', gallery).hide();
        $('.gallery-main-picture img', gallery).eq(index).show();
        caption.html($('.gallery-main-picture img', gallery).eq(index).attr('legend'));
        //}
        event.preventDefault();
    });
}

function menu() {
    $('#mainNav ul > li::first-child').addClass('first');
    $('#mainNav ul > li::last-child').addClass('last');
    $('#mainNav ul ul.professional > li::first-child').addClass('first');
    $('#mainNav ul ul.professional > li::last-child').addClass('last');
}

function PageInitialize() {
    for (i = 0; i < itemPerPage; i++) {
        $(".pagination").children().eq(i).show();
    }
}

PageClick = function (pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: nbrePages, buttonClickCallback: PageClick });
    // console.log(pageclickednumber);
    $(".pagination").children().each(function () {
        if (pageclickednumber <= 1) {
            $(".pagination").children().hide();
            for (i = 0; i < itemPerPage; i++) {
                $(".pagination").children().eq(i).show();
            }
        } else {
            $(".pagination").children().hide();
            for (i = itemPerPage * (pageclickednumber - 1); i < (itemPerPage * pageclickednumber); i++) {

                $(".pagination").children().eq(i).show();
            }

        }

    })
}

// Andy Langton's show/hide/mini-accordion - updated 23/11/2009
// Latest version @ http://andylangton.co.uk/jquery-show-hide

// this tells jquery to run the function below once the DOM is ready
$(document).ready(function () {

    itemPerPage = 3;
    pageclickednumber = 0;
    PageInitialize();
    nbrePages = ($(".pagination").children().length / itemPerPage);
    $("#pager").pager({ pagenumber: 1, pagecount: nbrePages, buttonClickCallback: PageClick });

    $("a[rel^='prettyPhoto']").prettyPhoto();


    // choose text for the show/hide link - can contain HTML (e.g. an image)
    var showText = '+';
    var hideText = '-';

    // initialise the visibility check
    var is_visible = false;

    // hide all of the elements with a class of 'toggle'
    $('.toggle').hide();

    // capture clicks on the toggle links
    $('a.toggleLink').click(function () {
        // toggle the display - uncomment the next line for a basic "accordion" style
        $(this).next('.toggle').toggle('slow');

        // return false so any link destination is not followed
        return false;
    });
});



