/**
 * Proyecto     : $NombreDelProyecto$
 * Autor        : Juan Pablo Aqueveque - www.juque.cl
 * Fecha        : $Fecha$
 * Version      : $Id: maestra.js 81 2009-03-06 04:52:01Z juque $
 */

$(document).ready(function() { 
        $('#procesando').hide();
		$("#procesando").ajaxStart(function(){
				$(this).show();
		});
		$("#procesando").ajaxStop(function(){
			$(this).hide();
		});
        $('#radioBusqueda').hide();
		var _body = $('body').attr('class');
		var minuaturas = {
			ini:function() {  
				 $('#paginacion a').click(function(){
						var url = $(this).attr("href");
						url = url.replace(/([^0-9])+/,"");
						$.get('_ajax.php',{p:url,ajax:'true'},function(data){  
							var res = eval( '(' + data + ')' ); 
							$('#grid').empty()
							for (i=0;i<res.datos.length;i++) {
							   $('#grid').append('<a href="/foto/'+res.datos[i].mdm_id+'"><img style="display:none" id="foto'+res.datos[i].mdm_id+'" src="/fotos-mdm/miniatura/'+res.datos[i].mdm_id+'.jpg" alt="'+res.datos[i].mdm_titulo+'" /></a>'+"\n");
							   $('#foto'+res.datos[i].mdm_id).fadeIn('slow');
							}   
							var _paginacion = res.paginacion; 
							_paginacion = _paginacion.replace(/(_ajax.php\?p=)/g,"pagina/");
							_paginacion = _paginacion.replace(/&amp;ajax=true/g,"");
							$('#paginacion').empty(); 
							$('#paginacion').append(_paginacion);  
							minuaturas.ini();
						})
						return false;
				   })
			}
		}
		switch ( _body ) {   
			/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			Portada
			- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
			case 'portada':   
		          _cajaBusqueda();
                  minuaturas.ini();
			break;
			
			/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			Detalle de la foto
			- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
			case 'detalleFoto':       
			break;                                                            
			
			/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			Resultado de la Búsqueda
			- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
			case 'rbusqueda':   
				_cajaBusqueda();
			break;
			
			case 'contacto':   
				$('#nombre').focus();
				$("form").submit(function(){

					$('form').find("span").each(function(){
							$(this).attr('class','alerta').remove();
					})     
					
					$.post('valida.php',{
						enviar:true,
						nombre:$('#nombre').val(),
						correo:$('#correo').val(),
						mensaje:$('#mensaje').val(),
						ajax:true},
					function(data){ 
						var res = eval( '(' + data + ')' );
						if ( res.todook )
						{     
							var html = "<h3>Correo Enviado</h3>";
							html += "<p>Gracias por contactarnos, tan pronto leamos tu correo te responderemos.</p>";
							$('form').remove();    
							$('#laZona').remove();
							$('h1').after(html)
						} 
						else
						{	
							if (res.nombre)
							{
								$('#nombre').after('<span class="alerta">'+res.nombre.mensaje+'</span>');
							}
							if (res.correo)
							{
								$('#correo').after('<span class="alerta">'+res.correo.mensaje+'</span>');
							}
							if (res.mensaje)
							{
								$('#mensaje').after('<span class="alerta">'+res.mensaje.mensaje+'</span>');
							}
						}
					});
				 	$('#enviar').after('<span class="ajaxStatus"><img src="../i/ajax-loader.gif" height="16" width="16" /></span>')

				 	$(".ajaxStatus").ajaxStart(function(){
							$(this).show();
					});
					$(".ajaxStatus").ajaxStop(function(){
							$(this).hide();
					});

					return false;
				})
			break; 
			case 'acerca':
				$('#o_mar_mirado').tablesorter(); 
				$('#do_areal_ao_peirao').tablesorter(); 
				$('#con_pes_no_mar').tablesorter();   
				$(".zebra tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
				$(".zebra tr:even").addClass("alt");
				
			break;
		} 
});
   
function _cajaBusqueda()  {
	   		$('#opcionesBusqueda').toggle(function(){
		 	 	 	 $(this).html('<a href="#">Opciones &uarr;</a>')
		 	 	 	 $('#radioBusqueda').show('slow')
	        	},function(){
		 	 	   	 $(this).html('<a href="#">Opciones &darr;</a>')
		 	 	 	 $('#radioBusqueda').hide('slow')
				})
}