$(document).ready(function(){
    

    Cufon.replace('h1:not(.no-cufon), h3:not(.no-cufon), .packs a, .inner-boxes a', {
        hover: true,
        fontFamily: 'Kozuka Gothic Pro R'
    });
    
    Cufon.replace('h2:not(.no-cufon), .btn-big, .inner-boxes p', {
        hover: true,
        fontFamily: 'Kozuka Gothic Pro EL'
    });
    
    
    var d=300;
    $('#navigation a').each(function(){
        $(this).stop().animate({
            'marginTop':'-80px'
        },d+=150);
    });


    $('.button-form').click(function(event){
        event.preventDefault();
        $(this).parent('form').submit();
        return false;
    });
    
    
    $("#acuenta01").click(function() {
        $.fancybox([
            '/images/mtp/slides/reg/reg-01.png',
            '/images/mtp/slides/reg/reg-02.png',
            '/images/mtp/slides/reg/reg-03.png',
            '/images/mtp/slides/reg/reg-04.png',
            '/images/mtp/slides/reg/reg-05.png'
            ], {
                'padding'			: 0,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0
             
            });
        return false;
    });
    
    $("#acuenta02").click(function() {
        $.fancybox([
            '/images/mtp/slides/tar/tar-01.png',
            '/images/mtp/slides/tar/tar-02.png',
            '/images/mtp/slides/tar/tar-03.png',
            '/images/mtp/slides/tar/tar-04.png'
            ], {
                'padding'			: 0,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0
            });
        return false;
    });
    
    $("#acuenta03").click(function() {
        $.fancybox([
            '/images/mtp/slides/pag/pag-01.png',
            '/images/mtp/slides/pag/pag-02.png',
            '/images/mtp/slides/pag/pag-03.png',
            '/images/mtp/slides/pag/pag-04.png'
            ], {
                'padding'			: 0,
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'type'              : 'image',
                'changeFade'        : 0
            });
        return false;

    });
			
    $("#accordion li .a-content").hide();
    activeItem = $("#accordion li:last");
    $(activeItem).addClass('active');
    $(activeItem).find('.a-content').show();
    $("#accordion li").click(function(){
        $('.a-content').hide();
        $(activeItem).animate({
            width: "50px"
        }, {
            duration:300, 
            queue:false
        });
        $(this).find('.a-content').show();
        $(this).animate({
            width: "800px"
        }, {
            duration:300, 
            queue:false
        });
        activeItem = this;
    });
    
    
    $('.detalles .read_more').click(function(){
        var $ref = $(this);
        $(this).parents('div').children('.dhidden').slideToggle('normal', function(){
            var $text = $(this).is(':hidden') ? 'Términos':'Ocultar';
            $ref.html($text);
        });
        return false;
    });
        

    $('input').example(function() {
        return $(this).attr('title');
    });

    $('#slider ul').bxSlider({
        pager: true,
        mode: 'fade',
        controls: false,
        speed: 3000,
        pause: 12000,
        pagerSelector: '.pager_x',
        auto: true
    });

    $('#total_play_contrata_recomendacion_1').click(function(){
        $('#recomendacionToogle').show();
    });
    
    $('#total_play_contrata_recomendacion_0').click(function(){
        $('#recomendacionToogle').hide();
    });
    
    $('#total_play_contrata_hijos_1').click(function(){
        $('#n_hijos').show();
    });
    
    $('#total_play_contrata_hijos_0').click(function(){
        $('#n_hijos').hide();
    });
    
    

    if($('#slider ul').length){
        $('#slider .bx-wrapper').width('100%');
        $('#slider .bx-window').width('100%');
    }

    $('#recent_news').bxSlider({
        pager: false,
        controls: true,
        pause: 4000,
        displaySlideQty: 5,
        nextSelector: '.arrow_rgt',
        prevSelector: '.arrow_lft',
        auto: true
       
    });

    if($('.paquetes_selector').length){
        $('.paquetes_selector').eq(0).addClass('active');
        $('.p_info').hide();
        $('.p_info').eq(0).show();
        $('.paquetes_selector').click(function(){
            var index = $('.stack a').index(this);
            var next = $('.p_info').get(index);
            if(!$(next).is(":visible")){
                $('.paquetes_selector').removeClass('active');
                $(this).addClass('active');
                $('.p_info').hide();
                $(next).fadeIn();
            }
            return false;
        });
    }

    get_nearest = function( args ) {
        var country = 'Mexico';
        var address = [];
        var callback;
        if ( args.callback )
            callback = args.callback;
        if ( args.street )
            address.push( $.trim( args.street ) );
        if ( args.number )
            address.push( $.trim( args.number ) );
        if ( args.city )
            address.push( $.trim( args.city ) );
        if ( !address.length )
            return false;
        address.push( country );
        address = address.join( ', ' );

        geocoder.geocode( {
            'address': address
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                /*var inside = get_inside(
					results[0].geometry.location.lat(),
					results[0].geometry.location.lng(),
					callback
				);*/
                return callback( results[0].geometry.location.lat() + ',' + results[0].geometry.location.lng() );
            } else {
                return callback( -1 );
            }
        } );
    }

    initForm();
    
    $(".tnews a, #landingsPOP").fancybox({
        'overlayColor': '#FFF',
        'autoScale': false
    });
    
    $("#accordion li, #recent_news li").css('cursor','pointer');
    
    $("#recent_news li").click(function(){
        href = $(this).find('a.read_more').attr('href');
        window.location = href;
    });

});


var geocoder;
var get_nearest = function() {};

function initForm(){
    //    if($("#contrata_form").length){
    //        $("#contrata_form").validate({
    //            //set the rules for the field names
    //            rules: {
    //                "total_play_contrata[nombre]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[apellido_paterno]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[apellido_materno]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[email]": {
    //                    required: true,
    //                    email: true
    //                },
    //                "total_play_contrata[apellido_telefono]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[calle]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[telefono]": {
    //                    required: true,
    //                    minlength: 7,
    //                    maxlength: 15
    //                },
    //                "total_play_contrata[numero_exterior]": {
    //                    required: true,
    //                    minlength: 1
    //                },
    //                "total_play_contrata[colonia]": {
    //                    required: true,
    //                    minlength: 3
    //                },
    //                "total_play_contrata[cp]": {
    //                    required: true,
    //                    minlength: 5
    //                }
    //            },
    //            //set messages to appear inline
    //            messages: {
    //                name: {
    //                    required:"Este campo es obligatorio.",
    //                    minlength:"Introduce al menos 2 caracteres."
    //                },
    //                email: {
    //                    required:"Este campo es obligatorio.",
    //                    email:"Introduce una direccion de e-mail válida"
    //                },
    //                comment: {
    //                    required:"Este campo es obligatorio.",
    //                    minlength:"Introduce al menos 5 caracteres."
    //                }
    //            },
    //
    //            //hide errors forever. We just need element highlighting
    //            errorPlacement: function(error, element) {
    //                error.hide();
    //            },
    //
    //            //Submit the Form
    //            submitHandler: function() {
    //                //Post the form values via ajax post
    //                $.post($("#contrata_form").attr('action'), $("#contrata_form").serialize()+'&ajax=1', function(result){
    //                    $('#contrata_form').remove();		//hide comment form
    //                    $('#contrata_success').fadeIn(500);	//Show mail success div
    //                    conversionSuccess();
    //                });
    //            }
    //        
    //        });
    //    }


    if($('.wh').length){
        img = $('.wh').children('img');
        if(img){
            var src = $(img).attr("src");
            var  cssObj = {
                'background-image' : 'url('+ src + ')',
                'background-repeat' : 'no-repeat',
                'background-position': 'center',
                'height': $(img).height()+'px'
            }
            $('.wh').css(cssObj);
            $(img).remove()
        }
    }

    if($("#distribuidoresFORM").length){
        $("#distribuidoresFORM").validate({
            //set the rules for the field names
            rules: {
                "total_play_distribuidores[nombre]": {
                    required: true,
                    minlength: 3
                },
                "total_play_distribuidores[email]": {
                    required: true,
                    email: true
                },
                "total_play_distribuidores[telefono_lada]": {
                    required: true,
                    minlength: 2
                },
                "total_play_distribuidores[telefono]": {
                    required: true,
                    minlength: 6
                },
                "total_play_distribuidores[celular]": {
                    required: true,
                    minlength: 2
                },
                "total_play_distribuidores[celular_lada]": {
                    required: true,
                    minlength: 6
                },
                
                "total_play_distribuidores[ciudad]": {
                    required: true,
                    minlength: 3
                },
                "total_play_distribuidores[municipio]": {
                    required: true,
                    minlength: 3
                },
                "total_play_distribuidores[negocio]": {
                    required: true
                },
                "total_play_distribuidores[local_comercial]": {
                    required: true
                },
                "total_play_distribuidores[vendedores]": {
                    required: true
                },
                "total_play_distribuidores[tipo_negocio]": {
                    required: true
                },
                "total_play_distribuidores[ventas]": {
                    required: true
                },
                "total_play_distribuidores[file]":{
                    required: true
                },
                
                "total_play_distribuidores[tipo_venta]": {
                    required: true
                }
                
            },
            errorPlacement: function(error, element) {
                error.hide();
            }
           
        });
    }
}



