jQuery(document).ready(function() {
    jQuery("a.iframePart").fancybox({
        'width' : 700,
        'height' : 560,
        'overlayOpacity' : 0.4,
        'opacity' : true,
        'scrolling' : 'no',
        'padding'   :   10,
        'hideOnContentClick' : false,
        'autoScale' : false,
        'speedIn' : 600,
        'speedOut' : 200,
        'type' : 'iframe'
    });
    jQuery("a.iframePro").fancybox({
        'width' : 700,
        'height' : 630,
        'overlayOpacity' : 0.4,
        'opacity' : true,
        'scrolling' : 'no',
        'padding'   :   10,
        'hideOnContentClick' : false,
        'autoScale' : false,
        'speedIn' : 600,
        'speedOut' : 200,
        'type' : 'iframe'
    });

    jQuery("a.single_image").fancybox({
        'titleShow' : true,
        'titlePosition' : 'inside',
        'transitionIn':'elastic',
	'transitionOut':'fade'

    });

    jQuery("a[rel=galerie_rdv]").fancybox({
        'transitionIn':'elastic',
        'transitionOut':'fade',
        'titlePosition' : 'over',
        'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Photo ' + (currentIndex + 1) + ' / ' + currentArray.length + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + title + '</span>';
        }
    });

    jQuery("a[rel=galerie_halles]").fancybox({
        'transitionIn':'elastic',
        'transitionOut':'fade',
        'titlePosition' : 'over',
        'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Photo ' + (currentIndex + 1) + ' / ' + currentArray.length + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + title + '</span>';
        }
    });

    /*
     * ACCORDION WITH TOGGLE
     */
    /*
    jQuery(".toggle_container").hide();				// First, Hide all.
    jQuery(".toggle_container:first").slideToggle("slow");	// Then, Toggle the first one.
    jQuery("h2.trigger:first").addClass("active");              // Add Active css class on the first item
     */

    // When toogle accordion check if active css class exists
    // if not close accordion and if open it and change css class
    /*jQuery("h2.trigger").toggle(
        function(){
            if (jQuery(this).hasClass("active")) {
                jQuery(this).removeClass("active");
                jQuery(this).find(".plus-moins-accordion").html("+");
                jQuery(this).find(".plus-moins-accordion").attr("title", "Agrandir");
            } else {
                jQuery(this).addClass("active");
                jQuery(this).find(".plus-moins-accordion").html("-");
                jQuery(this).find(".plus-moins-accordion").attr("title", "Réduire");
            }
        }
    );
    jQuery("h2.trigger").click(function(){
        jQuery(this).next(".toggle_container").slideToggle("slow");
    });
    
    // Display all button
    jQuery("a.triggerAll").click(function(){
        jQuery(".toggle_container").slideDown("slow");
        jQuery("h2.trigger").find(".plus-moins-accordion").html("-");
        jQuery("h2.trigger").addClass("active");
        jQuery("h2.trigger").find(".plus-moins-accordion").attr('title', 'Réduire');
    });
    // Hide all button
    jQuery("a.hideAll").click(function(){
        jQuery(".toggle_container").slideUp("slow");
        jQuery("h2.trigger").find(".plus-moins-accordion").html("+");
        jQuery("h2.trigger").removeClass("active");
        jQuery("h2.trigger").find(".plus-moins-accordion").attr('title', 'Agrandir');
    });*/

    /*
     * ACCORDION JQUERY
     */
    //Set default open/close settings
    jQuery('.toggle_container').hide(); //Hide/close all containers
    jQuery('.trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

    //On Click
    jQuery('.trigger').click(function(){
	if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
		jQuery('.trigger').removeClass('active').next().slideUp();      //Remove all "active" state and slide up the immediate next container
		jQuery(this).toggleClass('active').next().slideDown();          //Add "active" state to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
    });

    // Scroll to top button
    jQuery("a.scrollTop").click(function(){
        jQuery('html, body').animate({scrollTop:0}, 'slow');
    });
});

function initAccordions(idActive) {
    if (idActive != 0) {
        jQuery(document).ready(function() {
            jQuery(".toggle_container").hide();				
            jQuery(".toggle_container[id='"+idActive+"']").slideToggle("slow");
            jQuery("h2.trigger[id='"+idActive+"']").addClass("active");
            jQuery("h2.trigger[id='"+idActive+"']").find(".plus-moins-accordion").html("-");
            jQuery("h2.trigger[id='"+idActive+"']").find(".plus-moins-accordion").attr('title', 'Réduire');

            jQuery.scrollTo(jQuery(".toggle_container[id='"+idActive+"']"), 800, {offset:100});
        });
    } else {
        jQuery(document).ready(function() {
            jQuery(".toggle_container").hide();				// First, Hide all.
            jQuery(".toggle_container:first").slideToggle("slow");	// Then, Toggle the first one.
            jQuery("h2.trigger:first").addClass("active");              // Add Active css class on the first item
            jQuery("h2.trigger:first").find(".plus-moins-accordion").html("-");
            jQuery("h2.trigger:first").find(".plus-moins-accordion").attr('title', 'Réduire');
        });
    }
}

function toogleContactPanel() {
    if (jQuery("#contact-wrap").css("margin-top") == "-150px") {
        jQuery("#contact-wrap").animate({
            marginTop: '0px'
        }, 800);
    }
    else
    {
        jQuery("#contact-wrap").animate({
            marginTop: '-150px'
        }, 800);
    }
}
