jQuery(function($){
			$.datepicker.regional['es'] = {
			closeText: 'Cerrar',
			prevText: '',
			nextText: '',
			currentText: 'Hoy',
			monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
			'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
			'Jul','Ago','Sep','Oct','Nov','Dic'],
			dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
			dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
			dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
			weekHeader: 'Sm',
			dateFormat: 'yyy-mm-dd',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
			$.datepicker.setDefaults($.datepicker.regional['es']);
		});
	
		
	
		$(function() {   
			var fechas= new Array();					
			$.ajaxSetup({ cache: false });			
			$.ajax({
				url:"sistema_eventos/datepicker/eventos.php?accion=leer",
				async:false,
				success:function(valores){
					fechas=valores.split("/");
					//alert(valores);
				}
			});		
			
			$('#inicio').datepicker({
										inline: true,
										dateFormat: 'yy-mm-dd',
										beforeShowDay:function(date){
											return [true, "clase2"] 
										}
									});
			$('#termino').datepicker({
									 	inline: true,
										dateFormat: 'yy-mm-dd',
										beforeShowDay:function(date){
											return [true, "clase2"] 
										}
								 });
			
			jQuery('body').append('<div id="caja"><div id="mensaje"></div></div>');
			jQuery('#caja').hide();
			
			$('#datepicker').datepicker({
				inline: false,
				dateFormat: 'yy-mm-dd',
				beforeShowDay: function(date) {					
				date = date.format("yyyy-MM-dd");	
					if ($.inArray(date,fechas)!=-1)
					{ 
						return [true, "clase1 "+ date] 
					}
					else
					{ 
						return [true, "clase2"] 
					} 
				}
			});
			
			
			jQuery("#datepicker").live('mouseout',function(event){
																$(this).find('.divs').stop().animate({
																		'marginLeft':'-220px'
																	},200);
																}).live('mouseleave',function () {
																	$(this).find('.divs').stop().animate({
																		'marginLeft':'-20px'
																	},200);
															});
			
			jQuery("#caja").live('mouseover mouseout',
                    function(event){
                        if (event.type == 'mouseover')
                             jQuery('#caja').show();
                        else
						{
							jQuery('#caja').hide();
						}
                    }
                   );
			
			
			
			
			
			jQuery("#datepicker td").live('mouseover mouseout',
             function(event){
			 	if (event.type == 'mouseover')
				{
					if(jQuery(this).hasClass('clase1'))
					{
						var clase=jQuery(this).attr('class').split(" ");
						var elem;
						var Fecha;
						for(var i=0;i<clase.length;i++)
						{
							if(clase[i]!="")
							{
								elem = clase[i].split("-");
								if(!isNaN(elem[0]))
								{
									Fecha = elem[0]+"-"+elem[1]+"-"+elem[2];
									break;
								}
							}
						}
						
						/*$('#contenido').html('');*/
						var msgfecha = '<div id="contenido"><div id="load"></div></div>';
						$('#mensaje').html(msgfecha);
						$('#caja').show();						
						$.post('sistema_eventos/datepicker/eventos.php',
									{accion:'fecha',fecha:Fecha},
									function(data){
										var eventos=data.split("/");
										var arreglo;
										var lista= '<div style="">Fecha: '+Fecha+' </div><ul>';
										for( x in eventos)
										{
											arreglo=eventos[x].split("%");
											lista+='<li><a  href="http://www.offroad.com.mx/cgi/foro/index.php?action=mostrarEvento;evento='+arreglo[1]+'">'+arreglo[0]+'</a></li>';
										}
										lista+='</ul>';											
										$('#contenido').html(lista);										
									});									
						$('#contenido').html('<img src="images/loading.gif"/>');
						var posicion = $("#rp_list").position();
						var pos=$(this).position();						
					   //alert(posicion.top+pos.top);
						jQuery("#caja").css("left",($(window).width()+pos.left)-170);
						jQuery("#caja").css("top",(posicion.top+pos.top+10));
					    event.stopPropagation();
					}
				}			
				else
				{
					jQuery('#caja').hide();
					event.stopPropagation();
				}
			});
		});
		
		
		jQuery("#contenido ul li a").live("mouseover", function(event){
																 	if(event.type=="mouseover")
																	{
																		/*$("#caja").show();
																		event.stopPropagation();*/
																		//alert("pruebas");
																	}
																 });
	
		Date.prototype.format = function(format)  
		{
			var o = {
				"M+" : this.getMonth()+1,
				"d+" : this.getDate(),
				"h+" : this.getHours(),
				"m+" : this.getMinutes(),
				"s+" : this.getSeconds(),
				"q+" : Math.floor((this.getMonth()+3)/3),
				"S" : this.getMilliseconds()
			}
			if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
			(this.getFullYear()+"").substr(4 - RegExp.$1.length));
			for(var k in o)if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,
			RegExp.$1.length==1 ? o[k] :
			("00"+ o[k]).substr((""+ o[k]).length));
			return format;
		}

