
$(document).ready(function() {
	
	// PETICION
	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('mm=');
	
	// evento minimizar / maximizar thumbs
	$('.js-minThumb').live('click', function (event, minimiza){
		if ($('.js-thumbs').css('display') != 'none') {
			$('.js-thumbs').fadeOut();
			$(this).attr({'href':'#mm=thumbout'}).removeClass('activo');
			$('.menu a').each(function() {
				$(this).attr({'href': $(this).attr('href').replace(/#mm=?[a-z]*/,'#mm=thumbout')});
				});
		} 
		else if ($('.js-thumbs').css('display') == 'none' && minimiza != 'min') {
			$('.js-thumbs').fadeIn();
			$(this).attr({'href':'#mm=thumbin'}).addClass('activo');
			$('.menu a').each(function() {
				$(this).attr({'href': $(this).attr('href').replace(/#mm=?[a-z]*/,'#mm=thumbin')});
				});
			};
			
		// GOOGLE ANALYTICS
		//pageTracker._trackEvent('controles', 'thumbs', document.location );	
		_gaq.push(['_trackEvent', 'controles', 'show-hide_thumbs', document.location]);
		
		});
		
	
	// CUANDO CARGA LA PAGINA
	if (arrQuery[1] == 'max' || arrQuery[1] == 'thumbout') {
		$('#cabecera').fadeIn();
		$('.menu a').each(function() {
			$(this).attr({'href': $(this).attr('href')+'#mm=max'})
			});
		}
	else if (arrQuery[1] == 'thumbin') { //alert('in');
		$('#cabecera').fadeIn();
		$('.js-minThumb').trigger('click'); // arranca con las thumbnails
		$('.menu a').each(function() {
			$(this).attr({'href': $(this).attr('href')+'#mm=thumbin'})
			});
		}
	else {
		$('.menu a').each(function() {
			$(this).attr({'href': $(this).attr('href')+'#mm=min'})
			});
		};
	
	// EVENTO MINIMIZAR
	$('.js-minimiza-cabecera').click(function () {
		
		$('#cabecera').fadeOut();
		$('.js-minThumb').trigger('click',['min']); // arranca con las thumbnails - pasa un parametro con el evento
		
		$('.menu a').each(function() {
			$(this).attr({'href': $(this).attr('href').replace(/#mm=?[a-z]*/,'#mm=min')});
			});
			
		// GOOGLE ANALYTICS
		//pageTracker._trackEvent('controles', 'min-cabecera', document.location );
		_gaq.push(['_trackEvent', 'controles', 'min-cabecera', document.location]);
		
		});

	// EVENTO MAXIMIZAR	
	$('.js-maximiza-cabecera').click(function () {
	
		$('#cabecera').fadeIn();
		
		$('.menu a').each(function() {
			$(this).attr({'href': $(this).attr('href').replace(/#mm=?[a-z]*/,'#mm=max')});
			});
	
		// GOOGLE ANALYTICS
		//pageTracker._trackEvent('controles', 'max-cabecera', document.location );
		_gaq.push(['_trackEvent', 'controles', 'max-cabecera', document.location]);
		
		});
		
		
	

	})
