var geocoder = null;
var map = null;

$(document).ready(function(){
	
	// Acordeon Quienes Somos	
	/*if($("#institucionalidad-quienes-somos ul li").length > 0){

		$("#institucionalidad-quienes-somos ul li span").click(function(){
			$(this).parent().children("div").slideToggle('normal');
			});
	}*/
	

	// SUBIR
	$('#subir_top').click( function(){
		$.scrollTo('#header',700);
		return false;
	});
	// CAROUSEL AGENDA
	
	if ($("#content-columna-agenda").length) {
		$("#content-columna-agenda").jCarouselLite({
		    btnNext: ".nexts",
		    btnPrev: ".prevs",
		    visible: 1
		});
	}
	
	// CAROUSEL DESTACADOS_BLOG
	
	if ($("#carousel-destacados-blog").length) {
		$("#carousel-destacados-blog").jCarouselLite({
		    btnNext: ".next",
		    btnPrev: ".prev",
		    visible: 1
		});
	}
	
	// CAROUSEL ROCKERO
	if ($("#directorio-rockero-quienes-somos").length) {
		$("#directorio-rockero-quienes-somos").jCarouselLite({
		    btnNext: ".btn_right",
		    btnPrev: ".btn_left",
		    visible: 1
		});
	}
	// CAROUSEL insitucional
	if ($("#institucionalidad-quienes-somos .contenidoinstitucional").length) {
		$("#institucionalidad-quienes-somos .contenidoinstitucional").jCarouselLite({
		    btnNext: ".btn_right4",
		    btnPrev: ".btn_left4",
		    visible: 1
		});
	}
	
	// CAROUSEL
	if($("#content-columna-auspician").length) {
		$("#content-columna-auspician").jCarouselLite({
	    	btnNext: ".next",
	    	btnPrev: ".prev",
	    	visible: 1
		});
	}
	// CAROUSEL HOMENAJES
	if($("#carousel-homenajes").length) {
		$("#carousel-homenajes").jCarouselLite({
		    btnNext: ".next",
		    btnPrev: ".prev",
		    visible: 3
		});
	} 
	// CONTENT VIDEOS
	
	/*$("#cat-videos").idTabs(function(id,list,set){ 
	    $("a",set).removeClass("selected") 
	    .filter("[href='"+id+"']",set).addClass("selected"); 
	    for(i in list) 
	      $(list[i]).hide(); 
	    $(id).fadeIn(); 
	    return false; 
	  }); 
	*/
	if($("#cat-videos").length) { 
		$("#cat-videos").idTabs(function(id) {
			
			$("#testimonios-video").hide(); 
			$("#spots-video").hide();
			$("#animaciones-video").hide();
			
			$(id + "-video").show();
			
		   	return true;
		});
	}
  	
	// Grilla
	$("#preview").fancybox({
		'transitionIn'	 :	'elastic',
		'transitionOut'	 :	'elastic',
		'speedIn'		 :	600, 
		'speedOut'		 :	200, 
		'overlayShow'	 :	true,
		'autoDimensions' : true,
		'width'			 : 400,
		'overlayColor'	 : '#005371',
		'overlayOpacity' : 0.8,
		'onClosed': function() {
   			$('.ingreso-homenaje').slideUp();
        }
	});
	$("#preview-charla").fancybox({
		'speedIn'		 :	600, 
		'speedOut'		 :	200, 
		'overlayShow'	 :	true,
		'autoDimensions' : false,
		'width'			 : 670,
		'height'		 : 320,
		'overlayColor'	 : '#005371',
		'overlayOpacity' : 0.8,
		'onClosed': function() {
            $('#submit').attr('src','/i/boton-charla.png');
		}
	});


	$('#boton_login').click(function(){
		if ($('.login').is(':visible'))
			$('.login').fadeOut('slow');
		else
			$('.login').fadeIn('slow');
		return false;
		
	})
	$('div#grilla').mouseenter(function() {
		$(this).find("a.content").each(function(i) {
			$(this).mouseenter(function() {
				var tooltip = $(this).attr('rel').split(";");
				$('div#grilla a').removeClass('relativo');
				$(this).addClass('relativo');
			    var posicion = {
					'top' : tooltip[1] + 'px',
					'left' : tooltip[2] + 'px'
				}
				$('div#tooltip-'+tooltip[0]).css(posicion);
				$('.velo').fadeIn(300);
				$('div#tooltip-'+tooltip[0]).fadeIn(300);
			}).mouseleave(function() {
				var tooltip = $(this).attr('rel').split(";");
				$('div.velo').fadeOut(300);
				$('div.tooltip-left').fadeOut(300);
				$('div.tooltip-right').fadeOut(300);
			});
		});
	});
	$('.velo').click(function() {
		$('div.velo').fadeOut(300);
		$('.tooltip-left').fadeOut(300);
		$('.tooltip-right').fadeOut(300);
	});
	
	$('#multimedia-right').click(function() {
		the_margin = parseInt($('.interior_conte').css('marginLeft')) - 310;
		if (the_margin < (0 - parseInt($('div.interior_conte div.video').size()) * 310)) the_margin = (0 - parseInt($('div.interior_conte div.video').size()) * 310);		
		$('.interior_conte').animate({
			marginLeft: the_margin + 'px'
		}, 300, function() {
		});
	});
	
	$('#multimedia-left').click(function() {
		the_margin = parseInt($('.interior_conte').css('marginLeft')) + 310;
		if (the_margin >= 275) the_margin = 20;
		$('.interior_conte').animate({
			marginLeft: the_margin + 'px'
		}, 300, function() {
		});
	});

	$('#btn_instituciones').toggle(function () {
		$('#listado-instituciones').slideDown();		
	}, function () {
		$('#listado-instituciones').slideUp();
	});
	
	
	$('.ingreso-homenaje').hide();
	$('.btn_homenajes_right').toggle(function () {
   	window.scroll(0,1000); // horizontal and vertical scroll targets
		$('.ingreso-homenaje').slideDown();		
	}, function () {
		$('.ingreso-homenaje').slideUp();
	});
	
	/**
	 * Handler de los select de las bœsquedas de la secci—n donde estudiar
	 */
	$('.cont_left_int').find("select").each(function(i) {
		$(this).change(function() {
			$('#resultado_busqueda').load( wpurl + "/donde-estudiar/donde-estudiaruniversidades/", { 'choices': [$('#especialidad').val(), $('#lugar').val(), $('#rango-arancel').val()] } );
		});
	});
	
	// Deep linking Donde Estudiar
	$.historyInit(showcarreras);
	
	$("a[rel='universidad']").click(function(){
	    var hash = this.href;
	    hash = hash.replace(/^.*#/, '');
	    $.historyLoad(hash);
	    return false;
	});
	
  	$('#sbt-button').click(function() {
  		var valida = true;
  		
  		$('#fm_registro').find(".valida").each(function(i) {
  			field_value = $(this).val();
			if (!field_value) valida = false;
		});
		
		if ($('#clave').val() != $('#clave_confirma').val()) valida = false;
		
		if (!valida) {
			$('html,body').animate({scrollTop: 0}, 300);
			$('div.fail').fadeIn('slow');
		} else {
			$('#fm_registro').submit();
		}
	});

});

function showcarreras (hash) {
		$('.result_uni').load( wpurl + "/donde-estudiar/donde-estudiar-carreras/", { 'id_universidad': hash }, function() {	$('#content-universidad').slideDown(); });
}

function showdetalle (hash) {
	$('.cont_uni').load( wpurl + "/donde-estudiar/donde-estudiar-carreras/donde-estudiar-carreras-detalle/", { 'id_universidad': hash, 'especialidad': $('#especialidad').val() } );
}


