	function initializeCatamarca() {
	var map; 
	var ubicacionCatamarca = new google.maps.LatLng(-37.995588,-57.550721);
	var stylez = [{ stylers: [ { saturation: -90 } ] },{ featureType: "road.arterial", elementType: "geometry", stylers: [ { visibility: "simplified" } ] } ];	
	
	var mapOptions = { zoom: 16,center: ubicacionCatamarca,disableDefaultUI: true,mapTypeId: 'smart'};
	map = new google.maps.Map(document.getElementById("mapa"),mapOptions);
	var jayzMapType = new google.maps.StyledMapType(stylez, {name: "smart"});
	map.mapTypes.set('smart', jayzMapType);
	new google.maps.Marker({position: ubicacionCatamarca,map: map,draggable: false,animation: google.maps.Animation.DROP,title:"Catamarca 1542"
})
	}  
	
	
	function initializeBA() {
	var map; 
	var ubicacionBA = new google.maps.LatLng(-38.008858,-57.547386);
	var stylez = [{ stylers: [ { saturation: -90 } ] },{ featureType: "road.arterial", elementType: "geometry", stylers: [ { visibility: "simplified" } ] } ];	
	
	var mapOptions = { zoom: 16,center: ubicacionBA,disableDefaultUI: true,mapTypeId: 'smart'};
	map = new google.maps.Map(document.getElementById("mapa"),mapOptions);
	var jayzMapType = new google.maps.StyledMapType(stylez, {name: "smart"});
	map.mapTypes.set('smart', jayzMapType);
	new google.maps.Marker({position: ubicacionBA,map: map,draggable: false,animation: google.maps.Animation.DROP,title:"Buenos Aires 2551"});
	}  	

function setup_mapa(){
	$('#cerrarmapa').click(function(){
		$('#contenedormapa').fadeOut('slow');
	});
	$('#vermapacatamarca').click(function(){
		$('#contenedormapa').fadeIn('slow');
		initializeCatamarca();
	});
	$('#vermapabuenosaires').click(function(){
		$('#contenedormapa').fadeIn('slow');
		initializeBA();		
	});	
}


// JavaScript Document
var estudioActual,estudioAnterior=-1;
var filaActual,filaAnterior=-1;
var inMotionProfesional=false;
var inMotionEstudio=false;
var cerrado=true;

var novedadInMotionAbrir=false;
var novedadInMotionCerrar=false;

(function ($) {
	$.fn.exists = function(){return $(this).length>0;};
/*--------------------------------------------------------------------------------------------
*
* Setup Cycle
*
*--------------------------------------------------------------------------------------------*/
function setup_cycle(){
	$('.cycle').cycle({fx: 'fade',speed:1200,timeout:600} ); 
	$('.cycleb').cycle({fx: 'fade',speed:1200,timeout:600,delay:600} ); 
	$('.cyclec').cycle({fx: 'fade',speed:1200,timeout:600,delay:1200} ); 	
}
/*--------------------------------------------------------------------------------------------
*
* Setup Labelify
*
*--------------------------------------------------------------------------------------------*/
function setup_labelify(){
	$(".labelify").labelify();
}
/*--------------------------------------------------------------------------------------------
*
* Setup Nav
*
*--------------------------------------------------------------------------------------------*/

function setup_nav(){
	if(selected!='home'){
		$(selected).addClass('selected');	
		$('#line').css({width: jQuery('#menu ul li.selected').width(),left: jQuery('#menu ul li.selected').position().left});
		$('#line').fadeIn('slow');
	}
}
/*--------------------------------------------------------------------------------------------
*
* Setup Start
*
*--------------------------------------------------------------------------------------------*/
function setup_start(){
	$("#content,#pie").fadeIn('slow');
}

//funciones para colorear botones.
function colorear(elemento){
	elemento.stop(true).animate({backgroundColor: "#fcb0ba"}, 600 );
	elemento.children('.aparecer').not('.leer-mas').stop().animate({opacity:1}, 'slow');
	elemento.addClass('selected');
}

function decolorar(elemento){
		elemento.children('.aparecer').stop().animate({opacity:0}, 'slow');
		elemento.animate({backgroundColor: "#dcd4d1"}, 1000 );
		elemento.removeClass('selected');		
}

/*--------------------------------------------------------------------------------------------
*
* Setup color-animation
*
*--------------------------------------------------------------------------------------------*/
function setup_colorear(){
$('.colorear').hover(
	function() {
		if(!$(this).hasClass('selected')){
			$(this).stop(true).animate({backgroundColor: "#bdb0a7"}, 1000 );$(this).children('.aparecer').animate({opacity:1}, 'slow');
		}
	}, 
	function() {
		if(!$(this).hasClass('selected')){
			$(this).stop(true).animate({backgroundColor: "#dcd4d1"}, 1000 );$(this).children('.aparecer').stop().animate({opacity:0}, 'slow');
		}
	});
}
/*--------------------------------------------------------------------------------------------
*
* Setup Estudios
*
*--------------------------------------------------------------------------------------------*/

function abrir_contenedor(elemento){
	filaAnterior=(elemento.parent().parent().index());
	elemento.parent().slideDown('slow',function(){
		elemento.parent().addClass('cerrar');
		mostrar_estudio(elemento);
		cerrado=false;
	});
}
function mostrar_estudio(elemento){
	$('.estudio.actual').removeClass('actual');	
	elemento.addClass('actual');
	elemento.show();
	elemento.find('.mostrar-1').fadeIn('slow',function(){
			elemento.find('.mostrar-2').fadeIn( 'slow',function(){
				elemento.find('.mostrar-3').fadeIn('slow', function(){
					inMotionEstudio=false;
					
				});
			});
	});
}


function intercambiar_estudio(elemento){
	$('.estudio.actual').fadeOut('slow', function(){
		$('.estudio.actual').find('.mostrar-1,.mostrar-2,.mostrar-3').hide();
		$('.estudio.actual').find('.mostrar-1,.mostrar-2,.mostrar-3').removeAttr('style');		
		mostrar_estudio(elemento);
	});
};


function cerrar_contenedor(elemento){
	elemento.fadeOut('slow',function(){
		elemento.parent().slideUp('slow',function(){
			elemento.parent().removeClass('cerrar');
			elemento.parent().removeClass('actual');			
			estudioAnterior=-1;
			elemento.find('.mostrar-1,.mostrar-2,.mostrar-3').hide();
			elemento.find('.mostrar-1,.mostrar-2,.mostrar-3').removeAttr('style');
			
//			$('.sombra-vertical').slideUp('fast');
		});
	
	});
}

function mostrarProfesional(elemento){
	if(!inMotionProfesional){
		inMotionProfesional=true;
		$('.estudio.actual .ficha.display').hide();
		$('.estudio.actual .ficha.display').removeClass('display');		
		elemento.fadeIn('slow',function(){
			elemento.addClass('display');   
			inMotionProfesional=false; });
		}
}

function setup_cuerpoMedico(){
$('#cuerpoMedico .fila div .colorear').click (function () {
	
if(!inMotionEstudio){
	inMotionEstudio=true;
	if(!$(this).hasClass('selected')){
		var $this=$(this);
		estudioActual=$(this).index();
		estudioAnterior=$('.estudio.actual').index();
		decolorar($('.colorear'));		
		filaActual=$(this).parent().parent().index();
		var elemento=$(this).parent().next().children('.estudio').eq(estudioActual);
		if(cerrado){
			colorear($this);
			abrir_contenedor(elemento);
		}
		else{
			if(filaAnterior!=filaActual && filaAnterior!=-1){
				cerrar_contenedor($('.fila').eq(filaAnterior).find('.estudio.actual'));
				window.setTimeout(function() {
					colorear($this);
					abrir_contenedor(elemento);
				}, 1000);
				estudioAnterior=-1;
			}
			else{
				if(estudioAnterior!=-1){
					var elemento=$(this).parent().next().children('.estudio').eq(estudioActual);				
					colorear($this);
					intercambiar_estudio(elemento);
				}
			}
		}
	}
}
});

$('#cuerpoMedico .estudio .btn-cerrar').click(function(){
	cerrar_contenedor($(this).parent());
	decolorar($('.colorear.selected'));
	cerrado=true;
});

$('#cuerpoMedico .profesional').click(function(event){
	event.preventDefault();
	elemento=$($(this).attr('href'));
	mostrarProfesional(elemento);
});

}

function setup_estudios(){
$('#estudios .fila .botones .colorear:not(.fake)').click (function () {
	if(!$(this).hasClass('selected')){	
		decolorar($('.colorear'));
		var $this=$(this);
		estudioActual=$(this).index();
		estudioAnterior=$('.estudio.actual').index();
		var elemento=$(this).parent().next().children('.estudio').eq(estudioActual);		
		filaActual=$(this).parent().parent().index();
		if(filaAnterior!=filaActual && filaAnterior!=-1){
			cerrar_contenedor($('.fila').eq(filaAnterior).find('.estudio.actual'));
			window.setTimeout(function() {
					colorear($this);
					abrir_contenedor(elemento);
				}, 1000);
			estudioAnterior=-1;
		}
		else{
			if(estudioAnterior!=-1){
				colorear($this);
				intercambiar_estudio(elemento);
			}
			else{
				colorear($this);
				abrir_contenedor(elemento);
			}
		}
	}
});

$('#estudios .estudio .btn-cerrar').click(function(){
	cerrar_contenedor($(this).parent());
	decolorar($('.colorear.selected'));
});

}


/*------------------------------*/



function abrir_novedad(elemento){
	novedadInMotionAbrir=true;	
	elemento.addClass('cerrar');	
	elemento.slideDown('slow',function(){
		elemento.find('.mostrar-1').animate({opacity:1}, 'slow',function(){
			elemento.find('.mostrar-2').animate({opacity:1}, 'slow',function(){
				elemento.find('.mostrar-3').animate({opacity:1}, 'slow');
			})
		})
	});
	window.setTimeout(function() {novedadInMotionAbrir=false;}, 2500);
}
function cerrar_novedad(elemento){
	novedadInMotionCerrar=true;
	elemento.removeClass('cerrar');
	elemento.find('.mostrar-3,.mostrar-2,.mostrar-1').animate({opacity:0}, 'slow',function(){
		elemento.slideUp('slow');
	});
	window.setTimeout(function() {novedadInMotionCerrar=false;}, 2500);	
}


function setup_novedades(){
$('.novedad .colorear').click (function () {
		var $this=$(this);
		if(!novedadInMotionCerrar && !novedadInMotionAbrir && !$this.hasClass('selected')){
			if($('.cerrar').length){
				cerrar_novedad($('.cerrar'));
				window.setTimeout(function() {
					decolorar($('.colorear'));
					colorear($this);
					abrir_novedad($this.parent().children('.abrir'));
					$this.children('.leer-mas').animate({opacity:0}, 'slow');
				}, 1200);
			}
			else{
				decolorar($('.colorear'));
				colorear($this);
				abrir_novedad($this.parent().children('.abrir'));
				$this.children('.leer-mas').animate({opacity:0}, 'slow');
			}
		}
});

$('.novedad .btn-cerrar').click(function(){
	cerrar_novedad($('.cerrar'));
	decolorar($('.colorear.selected'));
	$('.cerrar').removeClass('cerrar');
});
}
/*----------------------------*/

function animardecada(index){
	alinearFotoActivo();
	$('#decadas .in a.selected').removeClass('selected');
	$('#decadas .in a:eq('+index+')').addClass('selected');
	var tam;
	for(i=1;i<7;i++){
		switch(Math.abs(index-i)){
			case 0:tam=26;break;
			case 1:tam=16;break;
			case 2:tam=12;break;
			default: tam=8;break;
		}
		$('#decadas .in a:eq('+i+')').stop(true).animate({fontSize:tam}, 500 );
	}
}
/*--------------Setup Decada--------------*/
function actualizarFoto(){
	decolorarFoto( $('.modulofoto'));	
	var i=$('.historia .modulo.activo').index();
	
	$('.historia-imagenes .modulofoto.activo').removeClass('activo');
	$('.historia-imagenes .modulofoto').eq(i).addClass('activo');
	if($('.historia-imagenes .modulofoto.activo').hasClass('no-se-ve')){alinearFotoActivo();}
}
function alinearFotoActivo(){$('.historia-imagenes-in').scrollTo($('.historia-imagenes .modulofoto.activo'),1000,{offset:-250});}


function iraDecada(index){
	var activo=$('#i'+index);
	$('.historia .modulo.activo').removeClass('activo');
	activo.addClass('activo');
	$('.historia-in').scrollTo(activo,1000);
	actualizarFoto();
	animardecada(index);
}

function atras(){
	siguiente=$('.historia .modulo.activo').prev();
	if(siguiente.hasClass('findedecada')){
		decada=$('#decadas .in a.selected').index()-1;
		animardecada(decada);
	}
	$('.historia-in').scrollTo(siguiente,1000);
	$('.historia .modulo.activo').removeClass('activo');	
	siguiente.addClass('activo');
	actualizarFoto();
}
function adelante(){
	siguiente=$('.historia .modulo.activo').next();
	if(siguiente.hasClass('iniciodecada')){
		decada=$('#decadas .in a.selected').index()+1;
		animardecada(decada);
	}	
	$('.historia-in').scrollTo(siguiente,1000);
	$('.historia .modulo.activo').removeClass('activo');
	siguiente.addClass('activo');
	actualizarFoto();
}

function colorearFoto(elemento){
	elemento.stop(true).animate({backgroundColor: "#fcb0ba"}, 600 );
	elemento.children('img').stop().animate({opacity:1}, 'slow');
	elemento.addClass('activo');
}

function decolorarFoto(elemento){
		elemento.children('img').stop().animate({opacity:.7}, 'slow');
		elemento.animate({backgroundColor: "#dcd4d1"}, 1000 );
		elemento.removeClass('activo');		
}
function setup_historia(){

 $('.historia-imagenes .modulofoto').bind('inview', function(event, visible) {
      if (visible) {
        $(this).removeClass('no-se-ve');
      } else {
        $(this).addClass('no-se-ve');
      }
    });	
	
	ancho=$(document).width();
	if(ancho<1100){ $('#flechas').hide();}
	
	$('.historia-imagenes-in').css({'width': ancho});
	$('.historia-imagenes-in').scrollTo($('.historia-imagenes .modulofoto.activo'),1000);
	$('.historia-in').scrollTo($('.historia .modulo.activo'),1000);
	$('#decadas .in a:not(.anterior,.siguiente)').click(function() {
		var index=$(this).index();
		iraDecada(index);

	});
	$('#decadas .in a.anterior').click(function() {
		var i=$('#decadas .in a.selected').prev().index();
		if(i>0) iraDecada(i);
	});
	$('#decadas .in a.siguiente').click(function() {
		var i=$('#decadas .in a.selected').next().index();
		if(i<7) iraDecada(i);
	});

$('#flechaizquierda').click(function(){atras();});
$('#flechaderecha').click(function(){adelante();});

//color de las imagnes
$('.modulofoto').hover(
	function() {
		if(!$(this).hasClass('activo')){
			$(this).stop(true).animate({backgroundColor: "#bdb0a7"}, 1000 );$(this).children('img').animate({opacity:1}, 'slow');
		}
	}, 
	function() {
		if(!$(this).hasClass('activo')){
			$(this).stop(true).animate({backgroundColor: "#dcd4d1"}, 1000 );$(this).children('img').stop().animate({opacity:.7}, 'slow');
		}
});

$('.modulofoto').click(function(){
	decolorarFoto( $('.modulofoto'));	
	colorearFoto($(this));
	
	var i=$(this).index();
	
	$('.historia .modulo.activo').removeClass('activo');
	$('.historia .modulo').eq(i).addClass('activo');
	$('.historia-in').scrollTo('.historia .modulo.activo',1000);
	
	if ($(this).hasClass('decada1'))animardecada(1);
	if ($(this).hasClass('decada2'))animardecada(2);
	if ($(this).hasClass('decada3'))animardecada(3);
	if ($(this).hasClass('decada4'))animardecada(4);
	if ($(this).hasClass('decada5'))animardecada(5);
	if ($(this).hasClass('decada6'))animardecada(6);				
	
})
}
/*--------------------------------------------------------------------------------------------
*
* Document Ready
*
*--------------------------------------------------------------------------------------------*/
$(document).ready(function()
{
setup_labelify();
setup_start();
setup_colorear();
setup_novedades();
setup_cuerpoMedico();
setup_estudios();
setup_nav();
//setup_busqueda();
//if(seccion=='cuerpo-medico')setup_autocompletar();
if(seccion=='autoridades' ||seccion=='filosofia' || seccion=='normas-iso' || seccion=='home')setup_cycle();
if(seccion=='historia') setup_historia();
if(seccion=='sedes')setup_mapa()

if(seccion=='rrhh' || seccion=='contacto'){
	$("#form1").validate({
		invalidHandler: function() {$("#error").show('fast');return false;},
		rules: {archivo: {required: true,accept: "pdf|doc|docx"}}
	}); 
}

if(seccion=='rrhh'){
	$('#botonenviarcv').click(function(){
		$('#moduloenviarcv').slideDown('slow',function(){$('#enviarinterno').fadeIn('slow');});
	});
	
	$('#cerrarModuloEnviar').click(function(){
		$('#enviarinterno').fadeOut('slow',function(){
			$('#moduloenviarcv').slideUp('slow');
		});
	});
}
});
/*--------------------------------------------------------------------------------------------
Window load
--------------------------------------------------------------------------------------------*/
$(window).load(function(){
	$("#content").css({'min-height': $(document).height()-$("#content").position().top-114});	
});
})(jQuery);
