// JavaScript Document
$(document).ready(

    function(){
        if($("#oS").length) $("#oS").selectbox();
        $("input[type=text], #message, #message-footer").focus(
            function(){
                $(this).css("color","#929191");
                if($(this).val()=="Name" || $(this).val()=="Email" || $(this).val()=="Phone (Optional)"
                    || $(this).val()=="Phone" || $(this).val()=="Message"
                    || $(this).val()=="Please describe the project")
                    $(this).val("");
            }
            );
        $("input[type=text], #message, #message-footer").blur(

            function(){

                if($(this).val()==""){
                    if(this.id=="name")$(this).val("Name");
                    if(this.id=="email")$(this).val("Email");
                    //
                    if(this.id=="nname")$(this).val("Name");
                    if(this.id=="nemail")$(this).val("Email");
                    //
                    if(this.id=="phone")$(this).val("Phone (Optional)");
                    if(this.id=="phone-footer")$(this).val("Phone");
                    if(this.id=="message")$(this).val("Message");
                    if(this.id=="message-footer")$(this).val("Please describe the project");
                }

            }
            );

        $(".sm").click(
            function(){
                //alert($(this).attr("rel"));
                $("#oS").val($(this).attr("rel"));
                //element=document.get
                $(".jquery-selectbox-currentItem").css("color","#696969");
                $(".jquery-selectbox-currentItem").html($(".value-"+$(this).attr("rel")).html());
                $(".jquery-selectbox").css("background-color","orange");
                $(".jquery-selectbox").animate({
                    backgroundColor: "#f6f6f6"
                }, 1000);
            }
            )

        $("#submit").click(
            function(){
                return validate();
            }
            );
        $(".button").click(
            function(){
                $("#nerr").hide("fast");
                if (nvalidate()){
                    var nname = $("input#nname").val();
                    var nemail = $("input#nemail").val();
                    var dataString = 'cm-name='+ nname + '&cm-beilt-beilt=' + nemail;
                    //alert (dataString);return false;
                    $.ajax({
                        type: "GET",
                        url: "http://divinedesigns.createsend.com/t/r/s/beilt/",
                        data: dataString,
                        //data: ({'cm-name' : nname, 'cm-beilt-beilt' : 'sdf@lsfj.com'}),
                        success: function() {
                            //alert('si---'+nname+'--'+nemail);
                        }
                    });
                    return true
                }
                else{
                    //alert('no---'+nname+'--'+nemail);
                    return false
                }
            }
            );

                $('#btn-what-we-do').hover(
                    function(){$('#what-we-do-hover').fadeIn()},
                    function(){$('#what-we-do-hover').fadeOut()}
                )
                $('#btn-our-work').hover(
                    function(){$('#our-work-hover').fadeIn()},
                    function(){$('#our-work-hover').fadeOut()}
                )
                $('#btn-contact-us').hover(
                    function(){$('#contact-us-hover').fadeIn()},
                    function(){$('#contact-us-hover').fadeOut()}
                )
                $("#animation-2").hide();
                $("#animation-3").hide();
                $("#animation-4").hide();
                $("#btnAnimation-1").children().attr("src","assets/images/images/btn-bullect-active.jpg")
                $(".animation-buttons").children().click(function(){
                    var divId=this.id.substring(13,14);
                    changePicture(divId);
                    nroPictureSelected=parseInt(divId)+1;
                    animation();
                });
                animation();


});



function validate(){
    var ret = true;
    regEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    regPhone = /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/;

    if($("#oS").length && !$("#oS").val()){
        $(".jquery-selectbox-currentItem").css("color","red");
        ret=false;
    }

    if($("#name").val()=="Name"){
        $("#name").css("color","red");
        ret=false;
    }
    else $("#name").css("color","#929191");
    if($("#email").val()=="Email" || !regEmail.test($("#email").val())){
        $("#email").css("color","red");
        ret=false;
    }
    else $("#email").css("color","#929191");

    if($("#phone").length){
        if($("#phone").val()!="Phone (Optional)" && !regPhone.test($("#phone").val())){
            $("#phone").css("color","red");
            ret=false;
        }
        else $("#phone").css("color","#929191");
    }
    if($("#phone-footer").length){
        if(!regPhone.test($("#phone-footer").val())){
            $("#phone-footer").css("color","red");
            ret=false;
        }
        else $("#phone-footer").css("color","#929191");
    }
	
    if($("#message").length){
        if($("#message").val()=="Message"){
            $("#message").css("color","red");
            ret=false;
        }
        else $("#message").css("color","#929191");
    }
    if($("#message-footer").length){
        if($("#message-footer").val()=="Please describe the project"){
            $("#message-footer").css("color","red");
            ret=false;
        }
        else $("#message-footer").css("color","#929191");
    }

    if(!ret){
        $("#err").html("Please ensure all required fields are filled out properly");
        $("#err").show("fast");
    }

    return ret;
}

function nvalidate(){
    var ret = true;
    regEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    regPhone = /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/;

    if($("#oS").length && !$("#oS").val()){
        $(".jquery-selectbox-currentItem").css("color","red");
        ret=false;
    }

    if($("#nname").val()=="Name"){
        $("#nname").css("color","red");
        ret=false;
    }
    else $("#nname").css("color","#929191");
    if($("#nemail").val()=="Email" || !regEmail.test($("#nemail").val())){
        $("#nemail").css("color","red");
        ret=false;
    }
    else $("#nemail").css("color","#929191");
        
    if(!ret){
        $("#nerr").html("Please ensure all required fields are filled out properly");
        $("#nerr").show("fast");
    }
    return ret;
}

function changePicture(divId){
    $(".animation-buttons").children().children().attr("src","assets/images/images/btn-bullet.jpg");
    $("#btnAnimation-"+divId).children().attr("src","assets/images/images/btn-bullect-active.jpg");

    $(".animation").children().hide();
    $("#animation-"+divId).fadeIn(1000);
}
function animation(){

    $(document).everyTime().stopTime(); // detener el movimiento

    $(document).everyTime(7000, function() {
        if(nroPictureSelected>=5){
            nroPictureSelected=1
            }
        changePicture(nroPictureSelected),
        nroPictureSelected +=1;
        if(nroPictureSelected>=5){
            nroPictureSelected=1
            }
    });
}
var nroPictureSelected=2;


