var total=5;
var actual;
var mostrar;
var rota;

function open_vista(url,contenedor){	
	if(url==''){
		document.getElementById(contenedor).innerHTML="";
	}
	else{
		new Ajax.Updater(contenedor, url,
					{
						evalScripts:true,
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><img src="../imagenes/load.gif"/></center>';
						}
					});
	}
}

//Envia forma y recarga vista permite tambien cargar editor y date picker
function enviar_forma(forma,accion,contenedor,editor,fecha,url2,contenedor2){
	new Ajax.Updater(contenedor, accion,
					{
						evalScripts:true,
						method: 'post',
						parameters: $(forma).serialize(), 
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><img src="../imagenes/load.gif"/></center>';
						},
						onComplete: function(request){
							
							if(editor=='TRUE'){
								 cargar_editor();
							}
							if(fecha=='TRUE'){
								datePickerController.destroyDatePicker('fecha');
								var opts = {
											formElements:{"fecha":"Y-ds-m-ds-d"},
									  		showWeeks:false,
									        statusFormat:"l-cc-sp-d-sp-F-sp-Y" ,
								            disabledDates:{}    	
									       };      
								datePickerController.createDatePicker(opts);
							}
							open_vista(url2,contenedor2,'TRUE','TRUE');
						}
					});
}

function cargar_combo(contenedor,url,id){
	var valor=document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	
	if(valor!=''){
		new Ajax.Updater(contenedor, url+valor,
				{
					onLoading: function(request){ 
						document.getElementById(contenedor).innerHTML='<center><img src="../imagenes/load.gif"/></center>';
					}
				});
	}
}

function accion_menu(seleccionado,total){
	for(i=1; i<=total; i++){
		if(seleccionado==i){
			document.getElementById("menu_"+i).className = "mseleccionado"+i;
		}
		else{
			document.getElementById("menu_"+i).className = "mnormal"+i;
		}
	}
}

function accion_servicios(seleccionado,total){
	for(i=1; i<=total; i++){
		if(seleccionado==i){
			$('servicio_'+i).hide();
			Effect.BlindDown('dservicio_'+i);
			
		}
		else{
			$('servicio_'+i).show();
			$('dservicio_'+i).hide();
		}
	}
}

function accion_proyectos(seleccionado,total){
	for(i=1; i<=total; i++){
		if(seleccionado==i){
			document.getElementById("proyecto_"+i).className = "seleccionado";
		}
		else{
			document.getElementById("proyecto_"+i).className = "normal";
		}
	}
}

function cambiar_tab(seleccionado,total){
	for(i=1; i<=total; i++){
		if(seleccionado==i){
			document.getElementById("pinfo_"+i).className = "cseleccionado";
		}
		else{
			document.getElementById("pinfo_"+i).className = "cnormal";
		}
	}
}

function cambiar_galeria(actual,total,aumento){
	actual=actual+aumento;
	if(actual<1)
		actual=total;
	if(actual>total)
		actual=1;
	for(i=1; i<=total; i++){
		if(actual==i){
			Effect.Appear('galeria_'+i, {delay: 1, duration: 2}); 
			$('punto_'+i).className = "pseleccionado";
		}
		else{
			Effect.Fade('galeria_'+i, {delay: .1, duration: 2});
			$('punto_'+i).className = "pnormal";
		}
	}
	return actual;
}

function cambiar_resultado(actual,total,aumento){
	actual=actual+aumento;
	if(actual<1)
		actual=total;
	if(actual>total)
		actual=1;
	for(i=1; i<=total; i++){
		if(actual==i){
			$('galeria_'+i).show();
		}
		else{
			$('galeria_'+i).hide();
		}
	}
	return actual;
}

function cambiar_rotar(rota,proyectos,aumento){
	rota=rota+aumento;
	if(rota<1)
		rota=proyectos;
	if(rota>proyectos)
		rota=1;
	for(i=1; i<=proyectos; i++){
		if(rota==i)
			Effect.Appear('rotar_'+i, {delay: 1, duration: 2}); 
		else
			Effect.Fade('rotar_'+i, {delay: .1, duration: 2});
	}
	return rota;
}

function rotativa(actual,mostrar,total,aumento){

	
	actual=actual+aumento;
	fin=actual+mostrar-1;
	
	if(actual==1)
		$('rotar_izquierdo').hide();
	else
		$('rotar_izquierdo').show();
	
	
	if(fin==total)
		$('rotar_derecho').hide();
	else
		$('rotar_derecho').show();
	
	for(i=1; i<=total; i++){
		if(i>=actual && i<=fin){
			$('rotativa_'+i).show();
		}
		else{
			$('rotativa_'+i).hide();
		}
	}
	return actual;
}

