
$.fn.hint = function (blurClass) {
		    if (!blurClass) blurClass = 'blur';
		    
		    return this.each(function () {
		        var $input = $(this),
		            title = $input.attr('title'),
		            $form = $(this.form),
		            $win = $(window);
		
		        function remove() {
		            if (this.value === title && $input.hasClass(blurClass)) {
		                $input.val('').removeClass(blurClass);
		            }
		        }
		
		        
		        if (title) { 
		            
		            $input.blur(function () {
		                if (this.value === '') {
		                    $input.val(title).addClass(blurClass);
		                }
		            }).focus(remove).blur(); 
		            
		            
		            $form.submit(remove);
		            $win.unload(remove); 
		        }
		    });
		};

$(document).ready(function(){


	$(".menu > li").click(function(e){
		switch(e.target.id){
			case "news":
				//change status & style menu
				$("#news").addClass("active");
				$("#tutorials").removeClass("active");
				$("#links").removeClass("active");
				$("#busqueda").removeClass("active");
				//display selected division, hide others
				$("div.news").fadeIn();
				$("div.tutorials").css("display", "none");
				$("div.links").css("display", "none");
				$("div.busqueda").css("display", "none");
			break;
			case "tutorials":
				//change status & style menu
				$("#news").removeClass("active");
				$("#tutorials").addClass("active");
				$("#links").removeClass("active");
				$("#busqueda").removeClass("active");
				//display selected division, hide others
				$("div.tutorials").fadeIn();
				$("div.news").css("display", "none");
				$("div.links").css("display", "none");
				$("div.busqueda").css("display", "none");
			break;
			case "links":
				//change status & style menu
				$("#news").removeClass("active");
				$("#tutorials").removeClass("active");
				$("#links").addClass("active");
				$("#busqueda").removeClass("active");
				//display selected division, hide others
				$("div.links").fadeIn();
				$("div.news").css("display", "none");
				$("div.tutorials").css("display", "none");
				$("div.busqueda").css("display", "none");
				
				if(!$(".demo5").hasClass('jPaginate')){
				
						counter = $("#totalPages").text();
						$(".demo5").paginate({
							count 		: counter,
							miclase		: 'demo5',
							start 		: 1,
							display     : 10,
							images		: false,
							mizquierdo	: 35,
							border					: false,
							text_color  			: '#999999',
							background_color    	: '#EEE',	
							text_hover_color  		: '#ffffff',
							background_hover_color	: '#333333',
							onChange     			: function(page,oactual){
														$('._current','#paginationdemo').removeClass('_current').hide();
														$('#p'+page).addClass('_current').show();
														
														idactual = $(oactual).parent().parent().parent().attr('id');
												
														if(idactual.search("top") == -1 ){
															idotro = idactual.replace('bottom','top');
														}else{
															idotro = idactual.replace('top','bottom');
														}
														
														$("li","#"+idotro).eq(page-1).click();
														
													  }
							});
			
					
				}
				
				
				break;
				
				
				case "busqueda":
				//change status & style menu
				$("#news").removeClass("active");
				$("#tutorials").removeClass("active");
				$("#links").removeClass("active");
				$("#busqueda").addClass("active");
				//display selected division, hide others
				$("div.busqueda").fadeIn();
				$("div.news").css("display", "none");
				$("div.tutorials").css("display", "none");
				$("div.links").css("display", "none");
			break;
				
		}
		//alert(e.target.id);
		return false;
	});
	
	
	
	$.datepicker.regional['es'] = {
		clearText: 'Limpiar', clearStatus: '',
		closeText: 'Cerrar', closeStatus: '',
		prevText: '&lt;Ant', prevStatus: '',
		nextText: 'Sig&gt;', nextStatus: '',
		currentText: 'Hoy', currentStatus: '',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthStatus: '', 
		yearStatus: '',
		weekHeader: 'Sm', 
		weekStatus: '',
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;dabo'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Dom','Lun','Mar','Mie','Jue','Vie','S&aacute;b'],
		dayStatus: 'DD', dateStatus: 'D, M d',
		dateFormat: 'yy-mm-dd', firstDay: 0, 
		initStatus: '', 
		isRTL: false
	};
	$.datepicker.setDefaults($.datepicker.regional['es']);
	
	getvars = window.location.search.substring(1);
	gy = getvars.split("&");
	
	
		
	
	var parametrosget = new Object;
	parametrosget.format = 'html';
	parametrosget.portal = 4;
	var buscara = false;
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		
		if (ft[0] == 'id_ev') {
			miInteger = parseInt(ft[1])
			if(!isNaN(miInteger)) 
				$('#content_evento').load('event_desc2.php?id_ev='+miInteger);
			
			break;
		}
		
		if(ft[0] == 'pclave'){
			parametrosget.q = ft[1];
			buscara = true;
		}
		
		if(ft[0] == 'f_start'){
			parametrosget.f_start = ft[1];
			buscara = true;
		}
		
		if(ft[0] == 'f_end'){
			parametrosget.f_end = ft[1];
			buscara = true;
		}
	}
	
		
		if(buscara){
		
			$('#content_busqueda').html('<div id="gfi-events-carousel"><img src="imgs/ajax_loader.gif" class="gfi-loader-carousel"/></div><br />');
			$("#news").removeClass("active");
			$("#tutorials").removeClass("active");
			$("#links").removeClass("active");
			$("#busqueda").addClass("active");
			$("div.busqueda").fadeIn();
			$("div.news").css("display", "none");
			$("div.tutorials").css("display", "none");
			$("div.links").css("display", "none");
			$('#content_busqueda').load('indexcargainfoeventos/resultados',parametrosget);

		}
	
		var dates = $( "#from, #to" ).datepicker({
			//defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			showAnim:'drop',
			showOn: "button",
			buttonImage: "imgs/calendar.jpg",
			buttonText: "calendario",
			buttonImageOnly: true,
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	
	
		$('#gfi-events-carousel').agile_carousel({
						first_last_buttons: "no",
						hover_next_prev_buttons: "no",
						next_prev_buttons: "yes",	
						number_slides_visible: 2,
						pause_button: "yes",
						slide_buttons: "yes",
						slide_captions: "no",
						slide_directory: "slides",
						slide_number_display: "yes",
						timer_length: "7000",
						transition_duration: 1000,
						transition_easing: "easeOutBack",
						transition_type: "carousel",
						water_mark: "Eventos destacados"
				});
	
		
		
		$.post('indexcargainfoeventos/anual',{format:'html',portal:'4'},function(data){
			$("#eventosAnuales").html(data);
		});
		
		
		$.post('indexcargainfoeventos/mensual',{format:'html',portal:'4'},function(data){
			$("#eventosMensuales").html(data);
			$('#gfi-tabs-vertical-list').tabs();  
		});
		
		$('input[title!=""]').hint();	


	
});

function imprime(evento){

	$.get('event_desc2.php',{id_ev:evento,format:'ajax'},function(data){
		var ventana = window.open("", "", "");
    	ventana.document.open();
    	ventana.document.write(data);
    	ventana.document.close();
		ventana.print();
		ventana.close();
	});
	
	
}


function irEvento(evento){
	$('#content_evento').html('<div id="gfi-events-carousel"><img src="imgs/ajax_loader.gif" class="gfi-loader-carousel"/></div><br />');
	$("#news").addClass("active");
	$("#tutorials").removeClass("active");
	$("#links").removeClass("active");
	$("#busqueda").removeClass("active");
	$("div.news").fadeIn();
	$("div.tutorials").css("display", "none");
	$("div.links").css("display", "none");
	$("div.busqueda").css("display", "none");
	$('#content_evento').load('indexcargainfoeventos/descripcion',{format:'html',id:evento});
}



function busquedaAvanzada(form){
	
	try{
		
		if(form.f_start.value.length == 0 && form.f_end.value.length != 0){
			alert("Por favor indique la fecha de inicio");
			return false;
		}
		
		if(form.f_start.value.length == 0 && form.q.value.length == 0){
			alert("Por favor indique la fecha de inicio o el nombre del evento");
			return false;
		}
		
		
		fi = form.f_start.value.split('-');
		ff = form.f_end.value.split('-');
		
		fechaInicio = new Date(fi[0],fi[1],fi[2]);
		fechaFin = new Date(ff[0],ff[1],ff[2]);
		
		if(fechaInicio > fechaFin){
			alert("La fecha de inicio debe ser mayor que la fecha final");
		}else{
			
			$('#content_busqueda').html('<div id="gfi-events-carousel"><img src="imgs/ajax_loader.gif" class="gfi-loader-carousel"/></div><br />');
			$("#news").removeClass("active");
			$("#tutorials").removeClass("active");
			$("#links").removeClass("active");
			$("#busqueda").addClass("active");
			$("div.busqueda").fadeIn();
			$("div.news").css("display", "none");
			$("div.tutorials").css("display", "none");
			$("div.links").css("display", "none");
			$('#content_busqueda').load('indexcargainfoeventos/resultados',{f_start:form.f_start.value,f_end:form.f_end.value,q:form.q.value,format:'html',portal:4});
			
			
		}
	
	}catch(e){
		console.log(e);
		return false;
	}
	return false;
	
	
}


function limpiar(element){
	$(element).val('');
}

function enter(event){
	if (null == event)
        event = window.event ;
	
	var unicode=event.keyCode? event.keyCode : event.charCode	
		
    if (unicode == 13)  {
        document.getElementById("searchButton").click();
    }

}

