function validateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email;
    if (reg.test(address) == false) {
        return false;
    }
    return true;
}

function autoRotate() {
    $(".support-scroll").each(function() {
        var left = $(this).scrollLeft() + 480;
        if (left >= $('.support-scroll-content', this).width()) {
            left = 0;
        }
        $(this).animate({
            scrollLeft: left
        }, {
            duration: 550});
    });
    setTimeout("autoRotate()", 10 * 1000);
}


$(document).ready(function() {
    $(".ptv-dropdown .box", this).hide();
    $(".ptv-dropdown").mouseenter(
        function() {
            $(".box", this).slideDown();
        }).mouseleave(function() {
            $(".box", this).hide();
        });
    $(".content form").attr("action", "/form.php");
    $('.storyThumb').prettyPhoto();
    $(".primary-menu a, .secondary-menu a").bind("mouseover",
        function() {
            $(".normal", this).hide();
            $(".hover", this).show();
        }).bind("mouseout", function() {
            $(".hover", this).hide();
            $(".normal", this).show();
        });

    $("form").submit(function() {
        var form = $(this);
        var valid = true;
        var validatorMessage = "Prosim izpolnite vsa polja.";
        $("input[type=\"text\"]", form).each(function(i, elm) {
            if ($(elm).val().length == 0) {
                valid = false;
            }
            if ($(this).hasClass("email")) {
                if (!validateEmail($(this).val())) {
                    valid = false;
                    validatorMessage = "Prosim vnesite pravilen postni naslov.";
                }
            }
        });
        if (!valid) {
            alert(validatorMessage);
        } else {

        }
        return valid;
    });

    $(document).scroll(function() {
        var a = $(".crack").offset().top;
        var move = $(document).scrollTop() * -0.2;
        $(".crack").clearQueue().stop().animate({top: move}, {duration: 5000, easing: "easeOutExpo", queue:false});
        move = $(document).scrollTop() * 0.1;
        $(".people-bg").clearQueue().stop().animate({top: move}, {duration: 5000, easing: "easeOutExpo", queue:false});
    });
    $('.support-scroll').scrollLeft(0);
    setTimeout("autoRotate()", 10 * 1000);
    $("a").each(function(){
        if ($(this).attr("href") != null && $(this).attr("href").indexOf("vozim.si") < 0){
            $(this).attr("target", "_blank");
        }
    });
});

