$(document).ready(function(){
    
    if($("#moduloCursosPrincipal").length>0){
        $("#moduloCursosPrincipal .curso").click (function(){
            var anterior = $("#moduloCursosPrincipal .selected").attr("rel");
            if(anterior!=$(this).attr("rel")){
              $("#moduloCursosPrincipal .selected").removeClass('selected');
              $(this).addClass('selected');

              var multiplicador = -(parseInt($(this).attr("rel")))*415+"px";

              $("#moduloCursosPrincipalItems").animate({
                marginTop: multiplicador
              }, 500 );
            }
        });
    }
    
    $("#cerrar-compartir-mail").click(function(e){
    	$("#velo").fadeOut();
    	$("#compartirmail").hide();
	    e.preventDefault();
    });

    $('.popupmail').click(function(e){
	    $("#velo").css('height', $("body").height());
	    $("#velo").fadeIn();
	    $("#compartirmail").show();	    
	    var top = ($(window).height() / 2 - 404 / 2)+getScrollY();
	    $("#compartirmail").css('top', top);
	    var left = ($(window).width() / 2 - 320 / 2);
	    $("#compartirmail").css('left', left);	    
	    
    	e.preventDefault();
    });

    $('#compartirmail form').submit(function(e){
		$.ajax({type: "POST", url: "/iou",data: $(this).serialize()})      
		$("#velo").fadeOut();
		$("#compartirmail").hide();
    	e.preventDefault();
    });
    
    $('#form-contacto').html5form({
        allBrowsers : true,
        method : 'POST',
        responseDiv : '.error-msg-text',
        submit: '#submit-form',
        id_modalidad: 'La modalidad es obligatoria.',
        id_forma_pago: 'La forma de pago es obligatoria.',
        id_nombre: 'Tu nombre es obligatorio.',
        id_email: 'Tu email es obligatorio.',
        id_email_email: 'Email inválido.',
        id_tfno: 'Tu teléfono es obligatorio.',
        go: '#error',
        showDiv: '#error',
        async: false,
        onSuccess: function(){
            return xt_form($(this),'F', $("#codigos").attr('xtn2'), $("#codigos").attr('descripcion'),'A',true);
        },
        onError: function() {
            return xt_form($(this),'F', $("#codigos").attr('xtn2'), $("#codigos").attr('descripcion'),'A',false);
        }
    });
    
    if($('.temarioFormat').length>0){
        $('.detallecursoContent .moduleType04 .p2').click(function(){
            if($(this).hasClass('open-temario')){
                $(this).parent().parent().next('.temarioFormat').fadeOut();
                $(this).removeClass('open-temario');
            }else{
                $(this).parent().parent().next('.temarioFormat').fadeIn();
                $(this).addClass('open-temario');
            }
        });
    }
    
    if ($('#pdf-download').length > 0) {
        download_pdf_assignEventHandlers();
    }
    
});

var download_pdf_assignEventHandlers = function() {
    
    $("#pdf-download").live('click', function(e){
        _gaq.push(['_trackEvent', 'PDF', 'Descargas', $("#codigos").attr('code_gAnalitycs')]);
        return xt_click($(this), 'F', $("#codigos").attr('xtn2'), $("#codigos").attr('descripcion'),'T');
    });
};


getScrollY = function() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
	scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	//DOM compliant
	scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	//IE6 standards compliant mode
	scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}	


