$(document).ready(function(){
   // Carousel slider for partner logos in footer
   $('.carousel').carouFredSel({
	width: 940,
	height: 70,
	padding: [20, 0],
	items: {
		visible: "variable",
		width: "variable",
		height: 70
	},
	scroll: {
		duration: 2000,
		pauseOnHover: true
	},
	auto: {
		pauseDuration: 4000,
		delay: 0
	}
    });
    // Left/Right Arrow buttons
    $("#partners .prev").click(function(){
	$(".carousel").trigger("prev");
    });
    $("#partners .next").click(function(){
	$(".carousel").trigger("next");
    });
    // Scrollable for image gallery page scrolling
    $('.scrollable').scrollable().navigator();
    // Fancybox for opening gallery images
    if ($('#gallery-wrap .page a.group').fancybox != null)
    {
        $('#gallery-wrap .page a.group').fancybox({
        titlePosition: 'inside',
        overlayColor: '#161616',
        overlayOpacity: 0.5
        });
    }

    $('.datepicker').datepicker({
	    dateFormat: 'yy-mm-dd',
	    onClose: function(dateText, inst){
		$(this).blur();
	    }
	},$.datepicker.regional['fr']
    );

    $('#quote_form').ready(function() {
        if (!$('#project_type_1').is(':checked') && !$('#project_type_2').is(':checked'))
        {
            $("#project_type_1").attr("checked", "checked");
        }
        
        if (!$('#window_type_1').is(':checked') && !$('#window_type_2').is(':checked'))
        {
            $("#window_type_1").attr("checked", "checked");
        }

        if ($('#project_type_2').is(':checked'))
        {
            $('#charge_list').slideDown('slow');
        }

        $('#project_type_1').click(function() {
            if ($('#charge_list').css('display') == 'block')
            {
                $('#charge_list').slideUp('slow');
            }
        });

        $('#project_type_2').click(function() {
            if ($('#charge_list').css('display') == 'none')
            {
                $('#charge_list').slideDown('slow');
            }
        });

        $('[id^="charge_"]:input[type="checkbox"]').click(function() {
            var elem_id = $(":input:eq(" + ($(":input").index(this) + 1) + ")").attr('id');

            if ($(this).attr('id') == "charge_5")
            {
                if ($(this).is(':checked'))
                {
                    $('#charge_5_extra').show();
                    $('#charge_5_text').show();
                }
                else
                {
                    $('#charge_5_extra').hide();
                    $('#charge_5_text').hide();
                }
            }
            else if (elem_id.substr((elem_id.length - 5)) == "_text")
            {
                if ($(this).is(':checked'))
                {
                    $('#'+elem_id).show();
                }
                else
                {
                    $('#'+elem_id).hide();
                }
            }
        });
    });
});
