

// MENSAGES
var msg = new Array();
var host = 'http://novembro.net';

$(document).ready(function() {
	//PETICIONES
	var str = document.location + ''
	var query_1 = String(str.match('#[a-z]*[\_|\-]?[a-z]*[\_|\-]?[a-z]*[\_|\-]?[a-z]*[\_|\-]?[a-z]*[\=]?[a-z]*[0-9]*[a-z]*')).replace(/#/,'')
	var arrQuery = query_1.split('=')
	
	var lg = $('meta[name="language"]').attr('content');
	
	// TAMANIO FUENTE
	var fontSize = parseInt(arrQuery[1]);
	
	$('.centrado').prepend('<label  class="acess opaco"><label class="mas"></label><label class="menos"></label></label><br/><br/>').addClass('acess-text');
	$('.acess').addClass('acess-control');
	
	function MM(mm) {
		if (!mm) mm = 0; var v = 3;
		$('.acess-text').each( function () {
			var fs = parseInt($(this).css('font-size').replace('px',''));
			var lh = parseInt($(this).css('line-height').replace('px',''));
			if (fontSize > 0 && mm == '-') $(this).css({'font-size': (fs - v) +'px','line-height':(lh-v)+'px'});
			if (mm == '+') $(this).css({'font-size': (fs + v) +'px','line-height':(lh+v)+'px'});
			});
		}
	
	$('.mas').append('A +').click(function() {
		if (fontSize && fontSize <= 2) {fontSize = fontSize + 1;MM('+');}
		else if (fontSize == 3) {}
		else {fontSize = 1;MM('+');}
		document.location.href = '#font='+fontSize;
		pasarFont();		
		});
		
	$('.menos').append('a -').click(function() {
		MM('-');
		if (fontSize) {
			fontSize = fontSize - 1;
			document.location.href = '#font='+fontSize;
			pasarFont();
			}
		});
	
	function pasarFont() {
		$('a').each(function() {
			var href =  $(this).attr('href');
			href = href.split('#');
			$(this).attr({'href': href[0] + '#font='+fontSize});
			})
		}
		
	if (arrQuery[0]=='font'){if (fontSize <= 3) {for (i = 0; i < fontSize; i++) {MM('+')};pasarFont();}};
	

	// NAVEGACION
	$('body').keydown(function(event) {
	
		// PRIMER: MENU PRINCIPAL
		 
		// encontrar activo
		var activo = $('#menu').find('a:last[class*="activo"]');
		// todos para el array
		var arMenu = $('#menu').find('a');
		
		// el repaso
		$(arMenu).each(function(i,el) {
			// encuentro el activo
			if ($(activo).text()==$(el).text()) {
				// parriba
				if (event.keyCode == 38) {
					//excepciones
					if ((i==2) && (arMenu.length > 4)) {i=1} // taquio -> diseño | home
					else if (i==0) {i=arMenu.length;}; // home -> ultimo (dar la vuelta)
					document.location.href= $(arMenu[i-1]).attr('href');
					}
				// pabajo
				else if (event.keyCode == 40) {
					//excepciones
					if (i==arMenu.length-1) {i=-1;}; // ultimo -> home (dar la vuelta)
					document.location.href= $(arMenu[i+1]).attr('href');
					}
				};
				
			// fin repaso	
			}) 
		// super excepcion lISTA WEBS NO HAY MENU
		if ($('meta[name="marcador"]').attr('content') == 'lista') {
			// parriba
			if (event.keyCode == 38) {document.location.href= host + '/' +lg +'/diseno/incanor';}
			// pabajo
			else if (event.keyCode == 40) {document.location.href= host + '/' +lg +'/contacto';};
			
			return false;
			}
		
		// SECONDO: IMAGENES
		
		var arImg = $('.js-imagen');
		var ia = $('.js-imagen[class*="js-activo"]');

		
		// si existe ia
		if ($(ia).is('a')) {
			// el juego
			$(arImg).each( function (i,el){
				if ($(ia).attr('alt') == $(el).attr('alt') ) {
					// paderecha
					if (event.keyCode == 39) {
						$(arImg[i+1]).trigger('click');
						// cerrar 
						if (i == arImg.length-1) $('.js-close').trigger('click');
						}
					// palizquerda
					else if (event.keyCode == 37) {
						$(arImg[i-1]).trigger('click');
						if (i == 0) $('.js-close').trigger('click');
						};
					};
				});
			// esc cerrar imagenes
			if (event.keyCode == 27) { $('.js-close').trigger('click');};

			// fin existe "ia"
			return false;
			}
		// si no hay "ia" voy palprimer o palultimo
		else if (arImg.length > 0) {
			// palprimer
			if (event.keyCode == 39) {
				$('.js-imagen:first').trigger('click');
				return false;
				}
			else if (event.keyCode == 37) {
				$('.js-imagen:last').trigger('click');
				return false;
				};
			}
			
		// primera pagina
		else if (arImg.length == 0) {
			// palprimer
			if (event.keyCode == 39) {
				document.location.href = host + '/' +lg + '/diseno/taquio';
				}
			}
		
		// FIN window key"tal"
     		//event.preventDefault();
   		});
   		
	// FIN JQUERY
	});

