$(document).ready(function() {
    //start
/* Tabs Activiation
================================================== */
    var tabs = $('ul.tabs');

    tabs.each(function(i) {
        //Get all tabs
        var tab = $(this).find('> li > a');
        tab.click(function(e) {

            //Get Location of tab's content
            var contentLocation = $(this).attr('href') + "Tab";

            //Let go if not a hashed one
            if (contentLocation.charAt(0) == "#") {

                e.preventDefault();

                //Make Tab Active
                tab.removeClass('active');
                $(this).addClass('active');

                //Show Tab Content & add active class
                $(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

            }
        });
    }); /* ================================================== */

/* FADE IN FADE OUT
================================================== */
    $(".fademe").hover(function() {
        $(this).stop(true, true).fadeTo("slow", 0.6);
    }, function() {
        $(this).stop(true, true).fadeTo("slow", 1);
    });

/* Open _blank target
================================================== */
    $('a[rel=external]').attr('target', '_blank');

    // ONLY for COLLECTION page
    if ($(".collection").length) { // implies *not* zero
/* Slideshow
================================================== */
        $(window).load(function() {
            $('#featured').orbit({
                hideLeftNav: true
            });
        });

    } // end COLLECTION
    $('#email').focus(function() {
        if ($(this).val() == 'Votre courriel') {
            $(this).val('');
        }
    }).blur(function() {
        if ($(this).attr('value') == '') {
            $(this).val('Votre courriel');
        }
    })

    // SHOW RABAIS
    $("#pop0").fancybox({
        'overlayShow': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });

    // SHOW INFOLETTRE
    $("#pop1").fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'speedIn': '600'
    });

    // SHOW VIDEO
    $("#pop2").fancybox({
        'autoScale': false,
        'width': 352,
        'height': 288,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'type': 'iframe'
    });

    //end READY
});



//


function submit_login() {
    e = window.event;
    if (e.keyCode == 13) {
        document.login.submit();
    }
    return false;
}

function check_day() {
    if (document.getElementById('disponibilite_1').checked == true) {
        document.getElementById('div_day_1').style.display = 'block';
        document.getElementById('div_day_2').style.display = 'block';
    } else {
        document.getElementById('div_day_1').style.display = 'none';
        document.getElementById('div_day_2').style.display = 'none';
        document.getElementById('disponibilite_4').checked = false;
        document.getElementById('disponibilite_7').checked = false;
        document.getElementById('disponibilite_1').checked = false;
    }
}

function check_evening() {
    if (document.getElementById('disponibilite_2').checked == true) {
        document.getElementById('div_evening_1').style.display = 'block';
        document.getElementById('div_evening_2').style.display = 'block';
    } else {
        document.getElementById('div_evening_1').style.display = 'none';
        document.getElementById('div_evening_2').style.display = 'none';
        document.getElementById('disponibilite_5').checked = false;
        document.getElementById('disponibilite_8').checked = false;
    }
}

function check_night() {
    if (document.getElementById('disponibilite_3').checked == true) {
        document.getElementById('div_night_1').style.display = 'block';
        document.getElementById('div_night_2').style.display = 'block';
    } else {
        document.getElementById('div_night_1').style.display = 'none';
        document.getElementById('div_night_2').style.display = 'none';
        document.getElementById('disponibilite_6').checked = false;
        document.getElementById('disponibilite_9').checked = false;
    }
}

function newsletter_inscription() {
    var email = $('#email').val();
    var email_filter = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.) {2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

    if (email == '' || !email_filter.test(email)) {
        $('#email_exists').hide();
        $('#email_success').hide();
        $('#email_error').fadeIn();
    }
    else {
        var data_string = 'email=' + email;
        $.ajax({
            type: 'GET',
            url: 'infolettre_inscription.php',
            data: data_string,

            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },

            success: function(msg) {
                //$('#debug').html(msg);
                if (msg != '') {
                    if (msg == 'WRONG_EMAIL') {
                        $('#email_success').hide();
                        $('#email_exists').hide();
                        $('#email_error').fadeIn();
                    }
                    else if (msg == 'EMAIL_EXISTS') {
                        $('#email_success').hide();
                        $('#email_error').hide();
                        $('#email_exists').fadeIn();
                    }
                    else if (msg == 'OK') {
                        $('#email_error').hide();
                        $('#email_exists').hide();
                        $('#email_success').fadeIn();
                    }
                }
            }
        });
    }
}

