﻿$.fx.speeds._default = 1000;

$(function () {
    $("#dialog:ui-dialog").dialog("destroy");

    $("#error").dialog({
        autoOpen: false,
        show: "blind",
        hide: "blind"
    });

    $("#dialog_phone").dialog({
        autoOpen: false,
        height: 250,
        width: 350,
        modal: true,
        buttons: {
            "OK": function () {
                var order = "phone_submit=phone_submit";
                order += "&phone_company=" + document.getElementById("phone_company").value;
                order += "&phone_name=" + document.getElementById("phone_name").value;
                order += "&phone_firstname=" + document.getElementById("phone_firstname").value;
                order += "&phone_phone=" + document.getElementById("phone_phone").value;
                order += "&phone_message=" + document.getElementById("phone_message").value;
                $.ajax({
                    url: 'default.aspx',
                    async: true,
                    cache: false,
                    data: order,
                    dataTypeString: 'html',
                    type: 'post'
                });
                $(this).dialog("close");
                $("#confirm").html("Votre demande a été envoyé");
                $("#confirm").dialog({ title: 'OK' });
                $("#confirm").dialog({ width: 400 });
                $("#confirm").dialog("open");
                setTimeout(function () { $("#confirm").dialog("close"); }, 2000);
            },
            "Annuler": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#newsletter").dialog({
        autoOpen: false,
        height: 250,
        width: 350,
        modal: true,
        buttons: {
            "OK": function () {
                var order = "newsletter_submit=newsletter_submit";
                order += "&newsletter_company=" + document.getElementById("newsletter_company").value;
                order += "&newsletter_name=" + document.getElementById("newsletter_name").value;
                order += "&newsletter_firstname=" + document.getElementById("newsletter_firstname").value;
                order += "&newsletter_email=" + document.getElementById("newsletter_email").value;
                $.ajax({
                    url: 'default.aspx',
                    async: true,
                    cache: false,
                    data: order,
                    dataTypeString: 'html',
                    type: 'post'
                });
                $(this).dialog("close");
                $("#confirm").html("Votre demande d&acute;inscription a été envoyé");
                $("#confirm").dialog({ title: 'OK' });
                $("#confirm").dialog({ width: 400 });
                $("#confirm").dialog("open");
                setTimeout(function () { $("#confirm").dialog("close"); }, 2000);
            },
            "Annuler": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#header_contact")
			.click(function () {
			    $("#dialog_phone").dialog("open");
			});

	$("#left_newsletter").click(function () {
	    $("#newsletter").dialog("open");
	});


    $("#confirm").dialog({
        autoOpen: false,
        show: "blind",
        hide: "blind"
    });

    $('#header_carousel').slidy({
        children: 'a',
        menu: true,
        pause: true,
        speed: 400,
        time: 6000,
        animation: 'fade',
        width: 980,
        height: 200
    });

    $('#center_carousel').slidy({
        children: 'a',
        menu: false,
        pause: false,
        speed: 400,
        time: 4000,
        animation: 'fade',
        width: 690,
        height: 235
    });

    $('#left_carousel').slidy({
        children: 'a',
        menu: false,
        pause: false,
        speed: 900,
        time: 4000,
        animation: 'fade',
        width: 160,
        height: 200
    });

    // rajout spé
    $('#header_contact').slidy({
        children: 'a',
        menu: false,
        pause: false,
        speed: 400,
        time: 4000,
        animation: 'slide',
        width: 180,
        height: 175
    });
    
    $('#news').wslide({
	width:690,
	height:300,
	autolink:false,
	horiz:true
    });
    
    $('#offres').wslide({
	width:690,
	height:300,
	autolink:false,
	horiz:true
    });
    
    if($('a.galerie').size() > 0) { $('a.galerie').colorbox(); }
    
    if($('#menusecurite').size() > 0)
    {
	$('#menusecurite').slidy({
	    animation:'fade',
	    children:'a',
	    menu:true,
	    pause:true,
	    speed:400,
	    time:4000,
	    width:690,
	    height:358
	});
    }
    
});

function ajax_loading(url, img) {
    document.getElementById('mod_body').innerHTML = '<img class="ajax_loader" src="' + img + '" alt="loader" />';
    $.ajax({
        url: url,
        async: false,
        cache: false,
        success: function (data) {
            $('#mod_body').html(data);
        }
    });
}

function delete_confirm() {
    $("#error").dialog({
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
            "Delete all items": function () {
                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });
}

function dialog_phone() {
    $("#dialog_phone").dialog("open");
}

