// JavaScript Document
function menu_galeria() {
var ruta = "/galeria/";
document.write("<ul>");
	document.write(" <li><a href='" + ruta + "index.html'>Generales</a></li>");
	document.write(" <li><a href='" + ruta + "estudiantes.html'>Estudiantes</a></li>");
	document.write(" <li><a href='" + ruta + "academicos.html'>Acad&eacute;micos</a></li>");
	document.write(" <li><a href='" + ruta + "investigacion.html'>Investigaci&oacute;n</a></li>");
	document.write(" <li><a href='" + ruta + "difusion.html'>Difusi&oacute;n</a></li>");
	document.write(" <li><a href='" + ruta + "espacios.html'>Espacios f&iacute;sicos</a></li>");
	document.write(" <li><a href='" + ruta + "deportes.html'>Deportes</a></li>");
	document.write(" <li class='none'><a href='" + ruta + "vinculacion.html'>Vinculaci&oacute;n</a></li>");
document.write("</ul>");
}
function gallery(){
	/* show first image and information */
	showTime=3000;
	timer=0;
	absLeft=0;
	
	anterior=0;
	currentLarge=0;
	total = $('.thumb img').length;
	$totalImgs = $('.thumb img');
	$('#imageNumber').html('1/' + total);
	thumbWidth = 0;
	/*ancho de thumbails*/
	Width = 47;
	for (x=0; x<total; x++) {
		thumbWidth = thumbWidth + $($totalImgs[x]).outerWidth();
	}
	thumbWidth= thumbWidth + 329;
	$('#innerContainer').css({ width: thumbWidth + 'px'});
	$('#innerContainer img').css({ display: 'inline'});
	
	$('.thumb:hover').css({ cursor: 'pointer'});
	
	firstStr = $('.thumb');
	showStr = firstStr.html();
	showDiv(showStr)
	
	$('#slideLeft')			.hover(function(e){
		$('#innerContainer')	.stop();
		$('#innerContainer')	.animate({"left": "0px"}, 13000 , "swing")
		},function(){
		$('#innerContainer')	.stop();
	});
	$('#slideRight')			.hover(function(e){
		posLeft = $('#thumbnails')	.offset().left;
		absLeft = e.pageX - posLeft;
		hiddenBit = thumbWidth - 500;
		$('#innerContainer')		.stop();
		$('#innerContainer')		.animate({"left": -hiddenBit + "px"}, 13000 , "swing")
		},function(){
		$('#innerContainer')		.stop();
	});
	
	/* monitor mouse clicks */
	$('.thumb').click(function(){
		anterior = currentLarge;
		htmlStr = $(this).html();
		currentLarge = $(this).attr('class').split(' ').slice(-1);
		
		if ("p"+(total) == currentLarge) {
		$('#clickRight').css("backgroundImage", "url(images/blank.gif)")
					.attr("title", "");
		}
		else {
			$('#clickRight').css("backgroundImage", "url(images/next.gif)")
						.attr("title", "Siguiente");
		}
			if ("p1" == currentLarge) {
			$('#clickLeft')	.css("backgroundImage", "url(images/blank.gif)")
						.attr("title", "");
		}
		else {
			$('#clickLeft').css("backgroundImage", "url(images/previous.gif)")
						.attr("title", "Anterior");
		}
		//si es diferente al actual pongo el marco
		if ("p"+(anterior) != currentLarge){
			setmarco();
		}
		/* swap images and information */
		$('#fullSize')	.fadeOut(400, function(){showDiv(htmlStr)});
	});
	
	/* show image and information */
	function showDiv (htmlStr) {
		$('#fullSize')		.html(htmlStr)
							.fadeIn(400);
		currentLarge = $('#fullSize img').attr('class');
		currentLarge = currentLarge.substr(1,3);
		$('#imageNumber').html(currentLarge + '/' + total);	
	}
	
	$('#clickRight').click(function(){
		anterior = currentLarge;
		currentLarge = $('#fullSize img').attr('class');
		/*final*/
		if ("p"+(total-1) == currentLarge) {
		$('#clickRight')	.css("backgroundImage", "url(images/blank.gif)")
						.attr("title", "");
		}
		/*cualquier lugar*/
		if ("p" + total != currentLarge) {
			$('#clickLeft')	.css("backgroundImage", "url(images/previous.gif)")
						.attr("title", "Siguiente");
			htmlStr = $('#innerContainer li.'+currentLarge).next('li').html();
			$('#fullSize')	.fadeOut(400, function(){showDiv(htmlStr)});
			
			m =(Width * currentLarge.substr(1,3));
			//mueve Derecha
			p = currentLarge.substr(1,3);
			limiteMov = total - 6; //limite de movimientos			

			if (total < 15){
				limiteMov = 12;
			}
			if (p < limiteMov){
				mueveR (m);
			}
			//mueveR (m);
			//pone marco al siguiente
			currentLarge = currentLarge.substr(1,3);
			currentLarge ++;
			
			setmarco();
		}
	});
	
	$('#clickLeft')	.click(function(){
		anterior = currentLarge;
		currentLarge = $('#fullSize img').attr('class');
		if ("p2" == currentLarge) {
			$('#clickLeft')	.css("backgroundImage", "url(images/blank.gif)")
						.attr("title", "");
		}
		if ("p1" != currentLarge) {
			$('#clickRight')	.css("backgroundImage", "url(images/next.gif)")
							.attr("title", "Siguiente");
			htmlStr = $('#innerContainer li.'+currentLarge).prev('li').html();
			$('#fullSize')	.fadeOut(400, function(){showDiv(htmlStr)});
			
			p = (currentLarge.substr(1,3) - 1);
			pa = (p - 10)* Width;
			
			if (pa < 0){
				//alert(pa);
				pa = 0;	
			}
			
			m = pa - 15;
			//mueve Izq
			limiteMov = total - 6; //limite de movimientos	
			if (total < 15){
				limiteMov = 12;
			}

			if (p < limiteMov){
				mueveL (m);
			}
	
			//pone marco al anteior
			currentLarge = currentLarge.substr(1,3);
			currentLarge --;
			setmarco();
		}
	});
	
	$('#autoPlay')	.toggle(function(){
		$('#autoPlay')	.css("background-position", "19px -214px")

					.attr("title", "Pausa");
		autoPlay()
	},function(){
		clearTimeout(timer);
		$('#autoPlay')	.css("background-position", "19px -259px")
					.attr("title", "Reproducir");
	});
	
	/*desplazamientos*/
	$('#g1').click(function(){mueveIni();});
	$('#g16').click(function(){mueve16 ();});
	$('#g32').click(function(){mueve32 ();});
	$('#g48').click(function(){mueve48 ();});
	$('#g64').click(function(){mueve64 ();});	
}

function autoPlay () {
	currentLarge = $('#fullSize img').attr('class');
	if ("p"+(total-1) == currentLarge) {
		$('#clickRight')	.css("backgroundImage", "url(images/blank.gif)")
							.attr("title", "");
	}
	if ("p" + total != currentLarge) {
		$('#clickLeft')		.css("backgroundImage", "url(images/previous.gif)")
							.attr("title", "Anterior");
		htmlStr = $('#innerContainer li.'+currentLarge).next('li').html();
		$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
	}
	if ("p"+(total) == currentLarge) {
		$('#clickLeft')		.css("backgroundImage", "url(images/blank.gif)")
							.attr("title", "");
		$('#clickRight')	.css("backgroundImage", "url(images/next.gif)")
							.attr("title", "Siguiente");
		htmlStr = $('#innerContainer li.p1').html();
		$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
	}
	timer = setTimeout ("autoPlay()", showTime);
}

function playDiv (htmlStr) {
	anterior = currentLarge;	
	$('#fullSize')		.html(htmlStr)
						.fadeIn(400);
	currentLarge = $('#fullSize img').attr('class');
	m =(Width * currentLarge.substr(1,3)) - 45;
	currentLarge = currentLarge.substr(1,3);
	setmarco();
	//mueve Derecha
	p = currentLarge;
	limiteMov = total - 6; //limite de movimientos		

	if (total < 15){
		limiteMov = 12;
	}
	if (p < limiteMov){
		mueveR (m);
	}
	//mueveR (m);
	$('#imageNumber').html(currentLarge + '/' + total);
}

function  mueveIni (){
	$('#clickLeft').css("backgroundImage", "url(images/blank.gif)")
				   .attr("title", "");

	$('#innerContainer').animate({"left": "0px"}, 500, "swing");	
	htmlStr = $('#innerContainer li.p1').html();
	$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
}

function  mueve16 (){
	$('#clickLeft').css("backgroundImage", "url(images/previous.gif)")
				   .attr("title", "Anterior");
	
	$('#innerContainer').animate({"left": -705+"px"}, 500, "swing");		
	htmlStr = $('#innerContainer li.p16').html();
	$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
}

function  mueve32 (){
	$('#clickLeft').css("backgroundImage", "url(images/previous.gif)")
				   .attr("title", "Anterior");
	
	$('#innerContainer').animate({"left": -1457+"px"}, 500, "swing");
	htmlStr = $('#innerContainer li.p32').html();
	$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
}
function  mueve48 (){
	$('#clickLeft').css("backgroundImage", "url(images/previous.gif)")
				   .attr("title", "Anterior");
	
	$('#innerContainer').animate({"left": -2209+"px"}, 500, "swing");
	htmlStr = $('#innerContainer li.p48').html();
	$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
}

function  mueve64 (){
	$('#clickLeft').css("backgroundImage", "url(images/previous.gif)")
				   .attr("title", "Anterior");
	
	$('#innerContainer').animate({"left": -2961+"px"}, 500, "swing");
	htmlStr = $('#innerContainer li.p64').html();
	$('#fullSize')		.fadeOut(400, function(){playDiv(htmlStr)});
}


function  mueveR (m){
	$('#innerContainer').animate({"left": -m+"px"}, 500, "swing");	
}
function  mueveL (m){
	$('#innerContainer').animate({"left": -m+"px"}, 500, "swing");	
}
function setmarco() {
	//pone el activo
	$('#thumbnails ul li img.'+ currentLarge).css({ border: '2px #0066CC solid'});
	$('#thumbnails ul li img.p'+ anterior).css({ border: '2px #FFF solid'});

	//para play
	$('#thumbnails ul li img.p'+ currentLarge).css({ border: '2px #0066CC solid'});
	$('#thumbnails ul li img.'+ anterior).css({ border: '2px #FFF solid'});
}

/*Administrador de onload para html*/
function addLoadEvent (func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
			window.onload = func; 
		
		} 
		else { 
			window.onload = function() { 
				if (oldonload) { 
					oldonload(); 
				} 
					func(); 
			} 
	} 
}

function GAnalytics() {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
		var pageTracker = _gat._getTracker("UA-4613180-2");
		pageTracker._trackPageview();
	}
	catch(err){}
}

