$(document).ready(function(){
    var slider = $('#rSlider').bxSlider({controls:false,auto:true});
    var total = $("#tblSlider .tblSlider").length - 1;
    $("#slideIndex").val(0);
    $("#tblSlider a").click(function(e){
        e.preventDefault();
        var index = $("#tblSlider a").index(this);
        var dparent = $(this).parent().parent();
        $("#tblSlider .tblSlider").removeClass("active");
        $(dparent).addClass("active");
        $("#slideIndex").val(index);
        $("#rSlider").animate({opacity:0},500, function(){
                        slider.goToSlide(index, false, true, function(){
                                        $("#rSlider").animate({opacity:1},500);
                        });
        });
        clearInterval(interval_home);
    });
    $("#leftSliderHeader").click(function(e){
        e.preventDefault();
        slider.goToPreviousSlide();
        $("#tblSlider .tblSlider").removeClass("active");
        var slideIndex = parseInt($("#slideIndex").val());
        slideIndex = ((slideIndex - 1) < 0)?total:(slideIndex - 1);
        $("#slideIndex").val(slideIndex);
        $("#tblSlider .tblSlider:eq(" + slideIndex + ")").addClass("active");
    });
    $("#rightSliderHeader").click(function(e){
        e.preventDefault();
        slider.goToNextSlide();
        $("#tblSlider .tblSlider").removeClass("active");
        var slideIndex = parseInt($("#slideIndex").val());
        slideIndex = ((slideIndex + 1) > total)?0:(slideIndex + 1);
        $("#slideIndex").val(slideIndex);
        $("#tblSlider .tblSlider:eq(" + slideIndex + ")").addClass("active");
    });
    $("#boxContentMini .boxPagination a").click(function(e){
        e.preventDefault();
        $("#boxContentMini .boxPagination a").removeClass("active");
        $(this).addClass("active");
        var index = parseInt($(this).text());
        $("#boxContentNoticias").animate({
            top:(-115 * (index -1))
        }, 700, "easeOutCubic");
    });
     $("#boxContent3 .boxPagination a").click(function(e){
        e.preventDefault();
        $("#boxContent3 .boxPagination a").removeClass("active");
        $(this).addClass("active");
        var index = parseInt($(this).text());
        $("#boxContentCursos").animate({
            top:(-272 * (index -1))
        }, 700, "easeOutCubic");
    });
    $("#boxSProgramasCenter p:not(.active)").mouseover(function(e){
        $(this).addClass("active");
    }).mouseout(function(e){
        $(this).removeClass("active");
    });
    $("#boxDataClientes .boxDataClientesCenter h3 a").click(function(e){
        e.preventDefault();
        var obj =  $(this).parent();
        obj.toggleClass("active");
        obj.parent().find(".contentLinks").slideToggle(300, "easeOutCubic");
    });
    $("#pagLetras .enabled").click(function(e){
        e.preventDefault();
        $("#pagLetras a").removeClass("active");
        $(this).addClass("active");
        var id = $(this).attr("id").split("-");
        $(".boxListAlumnos:visible").fadeOut("fast", function(){
            $("#boxListAlumnos-" + id[1]).fadeIn("slow", "jswing");
        });
    });
    $("#pagLetras .disabled").click(function(e){
        e.preventDefault();
    });
    var total_testimonios = $(".dataTestimonios").length;
    var aux_testimonios = 1;
    $("#leftTestimonio").click(function(e){
        e.preventDefault();
        if(aux_testimonios != 1){
            $("#dataTestimonios").animate({
                left: "+=635"
            }, 500, "easeOutCubic");
            aux_testimonios--;
        }
    });
    $("#rightTestimonio").click(function(e){
        e.preventDefault();
        if((aux_testimonios + 1) <= total_testimonios){
            $("#dataTestimonios").animate({
                left: "-=635"
            }, 500, "easeOutCubic");
            aux_testimonios++;
        }else{
             $("#dataTestimonios").animate({
                left: "0"
            }, 500, "easeOutCubic");
             aux_testimonios = 1;
        }
    });
    
    $("#plnk_youtube").fancybox({
        'width'               : 680,
         'height'              : 495,
        'autoScale': false,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type': 'iframe',
        'overlayColor' : '#000'
    });
    $("#send_comment").click(function(e){
        e.preventDefault();
        var name = $("#name").val();
        var email = $("#email").val();
        var phone = $("#phone").val();
        var msg = $("#msg").val();
        $.ajax({
            type: "POST",
            url: "request/send_contact.php",
            data: {name: name, email: email, phone: phone, msg: msg},
            success:function(resp){
                var json = eval(resp);
                if(json.error == 1){
                    $("#msg_contact").html("<div style='background:#900;color:#f0f0f0;padding:10px;font-size:14px;width:250px'>" + json.code + "</div>");
                        $.fancybox({
                            'href'		: '#msg_contact',
                            'transitionIn'	: 'elastic',
                            'transitionOut'	: 'elastic',
                            'type' : 'inline',
                            'overlayColor' : '#000'
                        });
                }else{
                        $("#msg_contact").html("<div style='background:#076BA0;color:#f0f0f0;padding:10px;font-size:14px;width:250px'>Su Mensaje ha Sido Enviado</div>");
                        $.fancybox({
                            'href'		: '#msg_contact',
                            'transitionIn'	: 'elastic',
                            'transitionOut'	: 'elastic',
                            'type' : 'inline',
                            'overlayColor' : '#000'
                        });
                        $("#name,#email,#phone,#msg").val("");
                }
            }
        });
    });
    Cufon.replace(".cufonM", {fontFamily: "myriad"});
    Cufon.replace(".cufonE", {fontFamily: "eurostile"}); 
});
