$(document).ready(function() { 
	//if($('body').find('.print').length>0){
		//$(".print").click(function(){
		
			//$("#contiene_zona_agenda").jqprint({ printContainer : true});

			//$("div#contiene_zona_agenda").printArea({ popY : 0, popTitle : 'Probando'});
		
		//});
	//}

	/*************************************
	 * Deslizar imagenes portada
	 ************************************/
	 
	$(function() {
			$(".portadaSlider").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				scroll:1,
				auto: 3000,
				speed: 800,
				visible: 1
			});
	});
	$(function(){
		$('img.captify').captify({
			// all of these options are... optional
			// ---
			// speed of the mouseover effect
			speedOver: 'fast',
			// speed of the mouseout effect
			speedOut: 'normal',
			// how long to delay the hiding of the caption after mouseout (ms)
			hideDelay: 500,	
			// 'fade', 'slide', 'always-on'
			animation: 'slide',		
			// text/html to be placed at the beginning of every caption
			prefix: '',		
			// opacity of the caption on mouse over
			opacity: '0.7',					
			// the name of the CSS class to apply to the caption box
			className: 'caption-bottom',	
			// position of the caption (top or bottom)
			position: 'bottom',
			// caption span % of the image
			spanWidth: '100%'
		});
	});
	
	/*************************************
	 * ToolTip para el Calendario
	 ************************************/
	$(function()  
			{  
			   var hideDelay = 500;    
			   var currentID;  
			   var hideTimer = null;  
			   
			   // One instance that's reused to show info for the current person  
			   var container = $('<div id="personPopupContainer">'  
			       + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="personPopupPopup">'  
			       + '<tr>'  
			       + '   <td class="corner topLeft"></td>'  
			       + '   <td class="top"></td>'  
			       + '   <td class="corner topRight"></td>'  
			       + '</tr>'  
			       + '<tr>'  
			       + '   <td class="left">&nbsp;</td>'  
			       + '   <td><div id="personPopupContent"></div></td>'  
			       + '   <td class="right">&nbsp;</td>'  
			       + '</tr>'  
			       + '<tr>'  
			       + '   <td class="corner bottomLeft">&nbsp;</td>'  
			       + '   <td class="bottom">&nbsp;</td>'  
			       + '   <td class="corner bottomRight"></td>'  
			       + '</tr>'  
			       + '</table>'  
			       + '</div>');  
			   
			   	$('body').append(container);  
			   
			   	$('.personPopupTrigger').live('mouseover', function()  
			   	{  
			       	// format of 'rel' tag: pageid,personguid  
			       	var settings = $(this).attr('rel').split(',');  
			       	var pageID = settings[0];  
			       	currentID = settings[1];  

			       	// If no guid in url rel tag, don't popup blank  
			       	if (currentID == '')  
			           return;  
			   
			       	if (hideTimer)  
			           clearTimeout(hideTimer);  
			   
			       	var pos = $(this).offset();  
			       	var width = $(this).width();  
			        var width_pantalla = $(window).width();
			        var posicion = pos.left + width;
			        //alert( (width_pantalla - (pos.left + width)) );
			        if((width_pantalla - (pos.left + width)) <= 300){
			        	posicion =  pos.left - width - 250;
			        	//alert('left de enlace->'+pos.left+' left nueva->'+posicion);
			        }
			        //alert(posicion) 
			       	
			       	container.css({  
			           left: posicion + 'px',  
			           top: pos.top - 5 + 'px'  
			       	});  
			   
			       	$('#personPopupContent').html('&nbsp;');  
			   
					$.ajax({  
			           type: 'GET',  
			           url: 'ajax/evento_tooltip.php',  
			           data: 'fecha=' + pageID + '&guid=' + currentID,  
			           success: function(data)  
			           {  
			               // Verify that we're pointed to a page that returned the expected results.  
			               	/*if (data.indexOf('personPopupResult') < 0)  
			               	{  
			                	$('#personPopupContent').html('<span >Page ' + pageID + ' did not return a valid result for person ' + currentID + '.Please have your administrator check the error log.</span>');  
							}  
					     
						 	// Verify requested person is this person since we could have multiple ajax  
						  	// requests out if the server is taking a while.  
						  	if (data.indexOf(currentID) > 0)  
						  	{                    
						  		var text = $(data).find('.personPopupResult').html();  
						  		$('#personPopupContent').html(text);  
								
						  	}  */
							$('#personPopupContent').html(data);  
					  	}  
					});  
					   
					container.css('display', 'block');  
				});  
			   
				$('.personPopupTrigger').live('mouseout', function()  
				{  
					if (hideTimer)  
						clearTimeout(hideTimer);  
					  hideTimer = setTimeout(function()  
					{  
						container.css('display', 'none');  
					}, hideDelay);  
				});  
			   
				// Allow mouse over of details without hiding details  
				$('#personPopupContainer').mouseover(function()  
				{  
					if (hideTimer)  
						clearTimeout(hideTimer);  
					});  
			   		// Hide after mouseout  
					$('#personPopupContainer').mouseout(function()  
					{  
						if (hideTimer)  
							clearTimeout(hideTimer);  
						hideTimer = setTimeout(function()  
						{  
							container.css('display', 'none');  
						}, hideDelay);  
					});  
				}); 
	
	$('#mensajes').css('display', 'none');  
	$('#enviar_condolencias').css('display', 'none');  
	$('#condolencias').css('display', 'none');
	
	$('.ver_condolencias').click(function(){
		$('#enviar_condolencias').fadeOut(200);
		$('#condolencias').fadeIn(200);
	});
	$('.enviar_condolencias').click(function(){
		$('#condolencias').fadeOut(200);
		$('#enviar_condolencias').fadeIn(200);
	});
	
	$('#btnEnviarCon').click(function(){
		$.ajax({  
	        type: 'GET',  
	        url: 'ajax/guardarCondolencia.php',  
	        data: 'id=' + $('#id').val() + '&nombre=' + $('#nombre').val() + '&texto=' + $('#texto').val() + '&publicar=' + $('#publicar').val(),  
	        success: function(data)  
	        {  
	        	$('#enviar_condolencias').fadeOut(200);
				if(data == 'ok'){
		        	$('#mensajes').html('<p>Su condolencia ha sido guardada correctamente.</p>');
										
				}else{
					$('#mensajes').html('<p>Su condolencia ya ha sido guardada anteriormente.</p>');
							
				}	
				setTimeout(function(){ $("#mensajes").fadeIn(3000).fadeOut(6500)}, 500);
				$.ajax({  type: 'GET', url: 'ajax/verCondolencias.php', data: 'id=' + $('#id').val(), success: function(data){ $('#condolencias').html(data); $('#condolencias').fadeIn(200);} });
	        }	
		});
	});		
	
	/*
	 * GEOLOCALIZACION (API GOOGLE)
	 */
	if($('#mapCentros').length>0){
		var map = new GMap2(document.getElementById('mapCentros')); 
		
		//Se define la latitud / longitud inicial: 
		latitud = 42.227542;
		longitud = -2.100413;
		if($('#latitud').val() != '' && $('#latitud').val() != '0.999999999999999')
			latitud = $('#latitud').val()
		if($('#longitud').val() != '' && $('#longitud').val() != '-0.999999999999999')
			longitud = $('#longitud').val();
		
		var posArnedo = new GLatLng(latitud,longitud); 
		map.setCenter(posArnedo, 15); 
		marker = new GMarker(posArnedo, {draggable:false} );
	    
		map.addOverlay(marker);
		map.addControl(new GSmallMapControl());
	}
	
	if($('#mapComercios').length>0){
		
		var map = new GMap2(document.getElementById('mapComercios')); 
		var posArnedo = new GLatLng(42.227542,-2.100413); 
		map.setCenter(posArnedo, 15);
		
		$.ajax({  
	        type: 'GET',  
	        url: 'ajax/puntosComercios.php',
	        dataType: 'json',
	        data: '',  
	        success: function(data)  
	        {  
				$.each(data, function(i,item){
					
					var posArnedo = new GLatLng(item['lat'],item['lng']);
					//map.setCenter(posArnedo, 15); 
					
					//marker = new GMarker(posArnedo, {draggable:false} );
					
					var iconoMarca = new GIcon(G_DEFAULT_ICON);
					iconoMarca.image = "iconos/arnedo20-23-A.png";
					var tamanoIcono = new GSize(20,23);
					iconoMarca.iconSize = tamanoIcono; 
					iconoMarca.iconAnchor = new GPoint(20, 23);
					
					iconoMarca.shadow = "iconos/arnedo20-23-B.png"; 
					var tamanoSombra = new GSize(20,23);
					iconoMarca.shadowSize = tamanoSombra;
					
					var marker = new GMarker(posArnedo,iconoMarca);
					
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(item['text']);
					});
						
				    map.addOverlay(marker);
	                
	            });				
				map.addControl(new GSmallMapControl());

	        }	
		});
	}
	
	$('#sltTipoComercio').change(function(){
		var map = new GMap2(document.getElementById('mapComercios')); 
		var posArnedo = new GLatLng(42.227542,-2.100413); 
		map.setCenter(posArnedo, 15);
		
		$.ajax({  
	        type: 'GET',  
	        url: 'ajax/puntosComercios.php?grupo='+$(this).val(),
	        dataType: 'json',
	        data: '',  
	        success: function(data)  
	        {  
				$.each(data, function(i,item){
					
					var posArnedo = new GLatLng(item['lat'],item['lng']);
					//map.setCenter(posArnedo, 15); 
					
					//marker = new GMarker(posArnedo, {draggable:false} );
					
					var iconoMarca = new GIcon(G_DEFAULT_ICON);
					iconoMarca.image = "iconos/arnedo20-23-A.png";
					var tamanoIcono = new GSize(20,23);
					iconoMarca.iconSize = tamanoIcono; 
					iconoMarca.iconAnchor = new GPoint(20, 23);
					
					iconoMarca.shadow = "iconos/arnedo20-23-B.png"; 
					var tamanoSombra = new GSize(20,23);
					iconoMarca.shadowSize = tamanoSombra;
					
					var marker = new GMarker(posArnedo,iconoMarca);
					
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(item['text']);
					});
						
				    map.addOverlay(marker);
	                
	            });				
				map.addControl(new GSmallMapControl());

	        }	
		});
		
	});
	
	var visible = 0;
	$('#verCapaCuaderno').click(function(){
		
		var pos = $(this).offset(); 
		$('#capaCuaderno').css({  
			'background-image' : 'url("../images/globo.png")',
			'background-repeat':'repeat-y',
			//'background-color': '#FFFFFF',
			//'box-shadow': '5px 5px 5px #999',
			//'-webkit-box-shadow': '5px 5px 5px #999',
			//'-moz-box-shadow': '5px 5px 5px #999',
			top: '75px' 
		});  
		if(visible == 0){
			$('#capaCuaderno').animate({
				opacity:1,
			    //top: '+=20',
			    height: 'toggle'
			  }, 1000, function() {
			    // Animation complete.
			  });
			visible = 1;
		}else{
			$('#capaCuaderno').animate({
				opacity:0,
			    //top: '-=20',
			    height: 'toggle'
			  }, 1000, function() {
			    // Animation complete.
			  });
			visible = 0;
		}

	});

	$('#guardarEnCuaderno').click(function(){
		$.ajax({  
			type: 'GET',  
			url: 'ajax/guardarEnCuaderno.php',  
			data: '',  
			success: function(data)  
			{  
				$('#capaCuaderno').animate({
					opacity:0,
				    //top: '-=20',
				    height: 'toggle'
				  }, 1000, function() {
				    // Animation complete.
				  });
				visible = 0;
				
				if(data == 'OK'){
					$('#mensaje').html('Se ha guardado la seccion en tu cuaderno de viaje.');
														
				}else{
					$('#mensaje').html('Ya tienes esta seccion en tu cuaderno de viaje.');
										
				}	
				
				$('#mensaje').css({'color':'#FFFFFF',
									'background-color':'#AC0404',
									'text-align':'center',
									'border':'1px solid black',
									'width':'310px',
									'margin-left':'290px',
									'padding-top':'5px',
									'padding-bottom':'5px',
									'margin-bottom':'10px'									
									});				


				setTimeout(function(){ $("#mensaje").fadeIn(1000).fadeOut(6500)}, 300);
			}
		});
	});
	
	$('#cerrarCuaderno').click(function(){
		//Necesario para ocultar la capa del Cuaderno de Viaje en TURISMO
		$('#capaCuaderno').animate({
			opacity:0,
		    //top: '-=20',
		    height: 'toggle'
		  }, 1000, function() {
		    // Animation complete.
		  });
		visible = 0;
	});
	
	$('#borrarCuadernoViaje').click(function(){
		if(confirm('\u00BFConfirma que desea eliminar su Cuaderno de Viaje?')){
			$.ajax({  
				type: 'GET',  
				url: 'ajax/borrarCuadernoViaje.php',  
				data: '',  
				success: function(data)  
				{  
					alert('Su cuaderno de viaje ha sido eliminado');
					document.location.href='index.php?submenu=425';
				}
			});
		}
	});

	$('#printCuadernoViaje').click(function(){
		
		GB_showCenter('Cuaderno de Viaje', 'http://www.arnedo.com/imprimir.php');
		//$('#iframeCuadernoViaje').attr('src', 'imprimir.php');
		//$('#iframeCuadernoViaje').imprimir();
	});
	
	
		
});

