$(document).ready(function() {
    $("#headerBottomLeft").cycle();

    $('#photos a').colorbox();

    //menuLeft dropdown
    $(".dropdown").click(function() {
        $("#menuLeft li").removeClass("menuSelected");
        $("#menuLeft li.menuSelectedLast").addClass("menuLast");
        $("#menuLeft li.menuSelectedLast").removeClass("menuSelectedLast");
        $("#menuLeft > li > ul").slideUp();
        $(this).parent().addClass("menuSelected");
        $(this).parent().children().slideDown();
        return false;
    });


    $("#enews").tooltip({
        position: "bottom center",
        events: {
            def: "click,mouseleave"
        },
        relative: true
    });

    /* submit contact form */
    $("a#btnSend").click(function() {
        $('.obligatory').removeClass('error');
        if ($(".obligatory").val() != "" && isValidEmailAddress($('input.email').val())) {
            $("form#contactForm").submit();
        } else {
            $('.obligatory:[value=""]').addClass('error');
            if (!isValidEmailAddress($('input.email').val())) {
                $('input.email').addClass('error');
            }
        }
        return false;
    });
    
});

function isValidEmailAddress(emailAddress) {
    var pattern = 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);
    return pattern.test(emailAddress);
}
