$(window).load(iniciarEventos);
var cache_calendario = new Array();
var cache_dias = {};
var showmenu=0;
var is_hora_visible=false;
var is_moneda_visible=false;
var mapa_in;
var markers_info = [];
var loc_infowindow;
var registrado;
var titulo_orig;

function iniciarEventos(){
	
	$(".overeffect").bind("mouseover",function(){
		var img=$(this).attr("img_over");
		$(this).attr("src",img);
	});
	$(".overeffect").bind("mouseout",function(){
		var img=$(this).attr("img1");
		$(this).attr("src",img);
	});
	
	var seccion=$("#seccion").val();
	if(seccion=="descargas"){
		$('#sel_des_unidades').bind("change",goDescargasLink);
	}else if(seccion=="capacitacioneslab"){
		iniGaleria_semtall();
		iniGaleria_seminarios();
		iniGaleria_talleres();
	}else if(seccion=="capacitacioneslab_afiliados"){
		iniGaleria_semtall();
		iniGaleria_seminarios();
		iniGaleria_talleres();
	}
	
	cargarFlashJavascript();
	iniciarRSS();
	iniciarCalendario();
	iniTabs();
	iniContactenosMaps();
	iniGaleria_sedes();
	iniGaleria_convenios();
	iniGaleria_planes();
	iniDescargas();
	iniGaleriaMult();
	iniGaleria_establecimientos();
	iniResultadosDep();
	iniEncuestas();
	
	$('#select_ver_tambien').bind("change",goLink);
	$("[notif_sec='si']").toggle(showNotif,hideNotif)
	if(seccion=="index"){
		/*$('#coin-slider').coinslider({
			width: 983,
			height: 340,
			hoverPause: false,
			delay: 5000
		});*/
		//$("#pikame").PikaChoose({carousel:true, autoPlay:false});
		//$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	}
}

function iniGaleria_establecimientos(){
	$("#est_categoria").bind("change", getEstablecimientos);
}

function getEstablecimientos(){
	
	var categoria=$(this).val();
	
	var id_est_unidad=parseInt($("#id_est_unidad").val());
	var la=$("#la").val();
	var offset=0;
	
	var ancho=535;
	var alto=$("#div_est").height();
	$("#div_est").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:"+alto+"px; width:"+ancho+"px;'>");
	$.ajax({
		type: "POST",
		url: "contenido.php",
		data: "accion=getEstInfo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_est_unidad="+id_est_unidad+"&categoria="+categoria,
		dataType: "json"
	}).success(function(datos){
		var msj= decodeURIComponent(datos.result);
		var html= decodeURIComponent(datos.msg);
		var total= decodeURIComponent(datos.total);
		$("#offset_est").val("1");
		$("#offset_est_actual").val(total);
		
		$("#div_est").html(html);
		$("#div_est").css("left","0");
		
		/*$('#planes_ant').hide();
		if(parseInt(total)>0){
			$('#planes_sig').show();
		}else{
			$('#planes_sig').hide();
		}*/
	});
}

function abrirPopUp(nombre,enlace,ancho,alto){
	var ventana = window.open(enlace, "Comfenalco", "width="+ancho+",height="+alto+",scrollbars=no,status=no,resizable=no,menubar=no,location=no,directories=no,status=no, titlebar=no,toolbar=no,top=200,left=200");
}

function iniNavCampanas(){
	$('#imagenes_flash').bind('mouseover', function(){
		$('#nav_prev').show();
		$('#nav_next').show();
	});
	
	$('#imagenes_flash').bind('mouseleave', function(){
		$('#nav_prev').hide();
		$('#nav_next').hide();
	});
	$('#nav_prev').click(function(){
		playFlash(2);
	});
	$('#nav_next').click(function(){
		playFlash();
	});
}

var intervalNot;
var carg_tof=true;
function cargarFlashJavascript(){
	cargarImgFlash();
	iniNavCampanas();
}

function flashJavascript(){
	clearInterval(intervalNot);
	var durac=parseInt($("#duracion_camp").val());
	if(durac<1)
		durac=6;
	durac=durac*1000;
	intervalNot=setInterval("playFlash()",durac);
	
}

function cargarImgFlash(){
	if(carg_tof){
		$("img[carg='true']").each(function(){
			var imgsrc=$(this).attr("src_load");
			//alert(imgsrc);
			$(this).attr("src",imgsrc);
		});
		carg_tof=false;
		flashJavascript();
		
	}
}

function playFlash(){
	var type_nav=1;
	if(arguments[0])
		type_nav=arguments[0];
	
	var img=parseInt($("#imagen_flash_actual").val());
	clearInterval(intervalNot);
  var tot_imgs=parseInt($("#imagenes_flash div.campana_imgs").length);
  if(tot_imgs>1){
	if(img<tot_imgs || type_nav==2){
		if(type_nav==1)
			var img_sig=parseInt(img)+1;
		else
			var img_sig=parseInt(img)-1;
		if(img_sig<1 && type_nav==2){
			img_sig=tot_imgs;
		}
		$(".campana_imgs").css("z-index","1");
		$("#imagen_"+img).css("z-index","10");
		$("#imagen_"+img_sig).css("z-index","5");
		$("#imagen_"+img_sig).css("display","");
		//$(".div_flash:not #imagen_"+img_sig).css("z-index","1");
		$("#imagen_"+img).fadeOut("slow",function(){
			$("#imagen_"+img_sig).show();
			$("#imagen_flash_actual").val(img_sig);
			flashJavascript();
		});
	}else{
		img_sig=1;
		$(".campana_imgs").css("z-index","1");
		$("#imagen_"+img).css("z-index","10");
		$("#imagen_"+img_sig).css("z-index","5");
		$("#imagen_"+img_sig).css("display","");
		$("#imagen_"+img).fadeOut("slow",function(){
			$("#imagen_"+img_sig).show();
			$("#imagen_flash_actual").val(img_sig);
			flashJavascript();
		});
	}
  }
}


function showNotif(){
	var img=$(this).children().attr("src");
	var img2=$(this).children().attr("src2");
	$(this).children().attr("src",img2);
	$(this).children().attr("src2",img);
	$("#div_notificacion").animate({width:'183px'},500);
}

function hideNotif(){
	var img=$(this).children().attr("src");
	var img2=$(this).children().attr("src2");
	$(this).children().attr("src",img2);
	$(this).children().attr("src2",img);
	$("#div_notificacion").animate({width:'40px'},500);
}


function goDescargasLink(){
	var val=$(this).val();
	if(val.length>0){
		window.location="descargas.php?id_m_unidad="+val;
	}	
}

function goLink(){
	var val=$(this).val();
	if(val.length>0){
		window.location=val;
	}	
}

var max;
var interva_planes;
function iniGaleria_planes(){
	$('#planes_ant').bind("click",backImagePlanes);
	$('#planes_sig').bind("click",nextImagePlanes);
	interva_sedes=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
	$("#planes_categoria").unbind("change");
	$("#planes_destino").unbind("change");
	$("#planes_categoria").bind("change", function(){
		getPlanes("1");
	});
	$("#planes_destino").bind("change", function(){
		getPlanes("2");
	});
}

function getPlanes(tipo){
	
	if(tipo=="1"){
		$("#planes_destino").val("0");
	}else{
		$("#planes_categoria").val("0")
	}
	
	var categoria=$("#planes_categoria").val();
	var destino=$("#planes_destino").val();
	
	var id_plan_unidad=parseInt($("#id_plan_unidad").val());
	var la=$("#la").val();
	var offset=0;
	
	var ancho=535;
	var alto=$("#div_plan").height();
	$("#div_plan").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:"+alto+"px; width:"+ancho+"px;'>");
	$.ajax({
		type: "POST",
		url: "contenido.php",
		data: "accion=getPlanesInfo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_plan_unidad="+id_plan_unidad+"&categoria="+categoria+"&destino="+destino,
		dataType: "json"
	}).success(function(datos){
		var msj= decodeURIComponent(datos.result);
		var html= decodeURIComponent(datos.msg);
		var total= decodeURIComponent(datos.total);
		$("#offset_plan").val("1");
		$("#offset_plan_actual").val(total);
		
		$("#div_plan").html(html);
		$("#div_plan").css("left","0");
		
		$('#planes_ant').hide();
		if(parseInt(total)>0){
			$('#planes_sig').show();
		}else{
			$('#planes_sig').hide();
		}
	});
}

function detGaleria_planes(){
	$('#planes_ant').unbind("click");
	$('#planes_sig').unbind("click");
	clearInterval(interva_planes);
}

var offset_min_plan=1;
function backImagePlanes(){
	detGaleria_planes();
	var top_p=parseFloat($('#div_plan').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_plan").val());
	if(offset>=offset_min_plan){
		alto=top_p+alto;
		$('#div_plan') .animate({"left": alto},iniGaleria_planes);
		$("#offset_plan").val(offset-offset_min_plan);
	}else{
		iniGaleria_sedes();
	}
	offset=($("#offset_plan").val());
	if(offset==offset_min_plan){
		$('#planes_ant').hide();
	}
	$('#planes_sig').show();
}

function nextImagePlanes(){
	detGaleria_planes();
	var categoria=$("#planes_categoria").val();
	var destino=$("#planes_destino").val();
	var offset=parseInt($("#offset_plan").val());
	var offset_mayor=parseInt($("#offset_plan_actual").val());
	var id_plan_unidad=parseInt($("#id_plan_unidad").val());
	var la=$("#la").val();
	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getPlanesInfo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_plan_unidad="+id_plan_unidad+"&categoria="+categoria+"&destino="+destino,
			dataType: "json",
			success: mostrarGalPlanes
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_plan').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_plan+offset;
		$("#offset_plan").val(sum_off);
		$('#div_plan') .animate({"left": alto},iniGaleria_planes);
		$('#planes_ant').show();
	}
	
}

function mostrarGalPlanes(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_plan").val());
	var offset_mayor=parseInt($("#offset_plan_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_plan').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_plan+offset_2;
		$("#offset_plan").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_plan_actual").val(sum_off);
		var anch_div=parseInt($('#div_plan').css("width"));
		$('#div_plan').css("width",anch_div+ancho);
		$('#div_plan').append(html);
		$('#div_plan').animate({"left": alto},iniGaleria_planes);
		$('#planes_ant').show();
	}else{
		$('#div_plan').animate({"left": 0},iniGaleria_planes);
		$("#offset_plan").val(offset_min_plan);
		$('#planes_ant').hide();
	}
}

function iniGaleriaMult(){
	$("#multimedia_categoria").bind("change",getGaleriaMultTipo);
	iniGaleria_multimedia();
}

var max;
var interva_multimedia;
function iniGaleria_multimedia(){
	detGaleria_multimedia();
	$('#multimedia_ant, #multimedia_ant2').bind("click",backImageMultimedia);
	$('#multimedia_sig, #multimedia_sig2').bind("click",nextImageMultimedia);
	interva_multimedia=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_multimedia(){
	$('#multimedia_ant, #multimedia_ant2').unbind("click");
	$('#multimedia_sig, #multimedia_sig2').unbind("click");
	clearInterval(interva_multimedia);
}

var offset_min_multimedia=2;
function backImageMultimedia(){
	detGaleria_multimedia();
	var top_p=parseFloat($('#multimedia_div').css('top'));
	var alto=500;
	var offset=parseInt($("#offset_multimedia").val());
	if(offset>=offset_min_multimedia){
		alto=top_p+alto;
		$('#multimedia_div') .animate({"top": alto},iniGaleria_multimedia);
		$("#offset_multimedia").val(offset-offset_min_multimedia);
	}else{
		iniGaleria_multimedia();
	}
	offset=($("#offset_multimedia").val());
	if(offset==offset_min_multimedia){
		$('#multimedia_ant, #multimedia_ant2').hide();
	}
	$('#multimedia_sig, #multimedia_sig2').show();
}

function nextImageMultimedia(){
	detGaleria_convenios();
	var offset=parseInt($("#offset_multimedia").val());
	var offset_mayor=parseInt($("#offset_multimedia_actual").val());
	var id_unidad_mult=parseInt($("#id_unidad_mult").val());
	var tipo=$("#multimedia_categoria").val();
	var la=$("#la").val();
	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getMultimedia&random=true&codificar=no&la="+la+"&offset="+offset+"&id_unidad_mult="+id_unidad_mult+"&tipo="+tipo,
			dataType: "json",
			success: mostrarGalMultimedia
		});
	}else{
		var alto=500;
		var top_p=parseFloat($('#multimedia_div').css('top'));
		alto=top_p-alto;
		var sum_off=offset_min_multimedia+offset;
		$("#offset_multimedia").val(sum_off);
		$('#multimedia_div') .animate({"top": alto},iniGaleria_multimedia);
		$('#multimedia_ant, #multimedia_ant2').show();
	}
	
}
function mostrarGalMultimedia(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_multimedia").val());
	var offset_mayor=parseInt($("#offset_multimedia_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=500;
	var ancho=500;
	if(msj=="si"){
		var top_p=parseFloat($('#multimedia_div').css('top'));
		alto=top_p-alto;
		var sum_off=offset_min_multimedia+offset_2;
		$("#offset_multimedia").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_multimedia_actual").val(sum_off);
		var anch_div=parseInt($('#multimedia_div').css("height"));
		$('#multimedia_div').css("height",anch_div+ancho);
		$('#multimedia_div').append(html);
		$('#multimedia_div').animate({"top": alto},iniGaleria_multimedia);
		$('#multimedia_ant, #multimedia_ant2').show();
	}else{
		$('#multimedia_div').animate({"top": 0},iniGaleria_multimedia);
		$("#offset_multimedia").val(offset_min_multimedia);
		$('#multimedia_ant, #multimedia_ant2').hide();
	}
}

function getGaleriaMultTipo(){
	var tipo=$("#multimedia_categoria").val();
	var id_unidad_mult=$("#id_unidad_mult").val();
	var offset=0;
	var limit=parseInt($("#limit_multimedia").val());
	
	var ancho=$("#multimedia_div").width();
	$("#multimedia_div").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:100px; width:"+ancho+"px;'>");
	$.ajax({
		type: "POST",
		url: "contenido.php",
		data: "accion=getMultimedia&random=false&codificar=no&offset="+offset+"&id_unidad_mult="+id_unidad_mult+"&tipo="+tipo+"&limit="+limit,
		dataType: "json",
		success: function(datos){
			var html= decodeURIComponent(datos.msg);
			var total= decodeURIComponent(datos.total);
			$("#multimedia_div").html(html);
			$("#offset_multimedia").val(offset_min_multimedia);
			$("#offset_multimedia_actual").val(total);
			$("#multimedia_div").css("top","0");
			$('#multimedia_ant, #multimedia_ant2').hide();
		}
	});
}

function iniciarGalMemoria(){
	$(".imagenes_mem a[img='si']").lightBox();
}

function dewplayer_play(id) {
	  var dewp = document.getElementById(id);
	  if(dewp!=null) dewp.dewplay();
}

function iniDescargas(){
	$("#descarga_categoria").unbind("change");
	$("#descargas_ant").unbind("click");
	$("#descargas_sig").unbind("click");
	$("#descarga_categoria").bind("change",function(){
		getDescargasTipo("normal");
	});
	$("#descargas_ant").bind("click",function(){
		getDescargasTipo("ant");
	});
	$("#descargas_sig").bind("click",function(){
		getDescargasTipo("sig");
	});
}

function getDescargasTipo(modo){
	var tipo=$("#descarga_categoria").val();
	var id_unidad_desc=$("#id_unidad_descarga").val();
	var offset=parseInt($("#offset_descarga").val());
	var limit=parseInt($("#limit_descarga").val());
	
	if(modo=="sig"){
		offset=offset+limit;
	}else if(modo=="ant"){
		offset=offset-limit;
	}else{
		offset=0;
	}
	
	var ancho=$("#div_descargas").width();
	$("#div_descargas").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:80px; width:"+ancho+"px;'>");
	$.ajax({
		type: "POST",
		url: "contenido.php",
		data: "accion=getDescargas&random=true&codificar=no&offset="+offset+"&id_unidad_desc="+id_unidad_desc+"&tipo="+tipo+"&limit="+limit,
		dataType: "json",
		success: function(datos){
			var html= decodeURIComponent(datos.html);
			$("#div_descargas").html(html);
			$("#offset_descarga").val(offset);
			iniDescargas();
		}
	});
}

function iniResultadosDep(){
	$("#id_deporte").unbind("change");
	$("#id_torneo").unbind("change");
	$("#fecha_res").unbind("change");
	$("#resultdep_ant").unbind("click");
	$("#resultdep_sig").unbind("click");
	$("#id_deporte").bind("change",function(){
		cambiarSelectHijo('id_deporte', 'id_torneo', 'contenido.php', 'accion=getContenidoSelect&tipo=1');
		getResultadosDep("");
	});
	$("#id_torneo").bind("change",function(){
		getResultadosDep("");
	});
	$("#resultdep_ant").bind("click",function(){
		getResultadosDep("ant");
	});
	$("#resultdep_sig").bind("click",function(){
		getResultadosDep("sig");
	});
	$("#fecha_res").change(function(){
		getResultadosDep("");
	});
}

function getResultadosDep(modo){
	var id_deporte=$("#id_deporte").val();
	var id_torneo=$("#id_torneo").val();
	var fecha=$("#fecha_res").val();
	var offset=parseInt($("#offset_resultdep").val());
	var limit=parseInt($("#limit_resultdep").val());
	
	if(modo=="sig"){
		offset=offset+limit;
	}else if(modo=="ant"){
		offset=offset-limit;
	}else{
		offset=0;
	}
	
	$("#divresultados_dep").html("<div style='background:url(imagenes/ajax-loader.gif) no-repeat center; background-color:#F4F4F4; height:130px; width:100%;'>");
	$.ajax({
		type: "POST",
		url: "contenido.php",
		data: "accion=getResultadosDep&id_deporte="+id_deporte+"&id_torneo="+id_torneo+"&offset="+offset+"&limit="+limit+"&fecha="+fecha,
		dataType: "json",
		success: function(datos){
			var total = datos.total
			var html= decodeURIComponent(datos.html);
			$("#divresultados_dep").html(html);
			$("#offset_resultdep").val(offset);
			if(modo=="sig" && total=='0'){
				getResultadosDep("");
			}else if(total==0){
				$("#resultdep_ant").hide();
				$("#resultdep_sig").hide();
			}else if(offset==0){
				$("#resultdep_ant").hide();
				$("#resultdep_sig").show();
			}else if(modo=="sig"){
				$("#resultdep_ant").show();
			}
			iniResultadosDep();
		}
	});
}
function iniEncuestas(){
	$("#votar").bind('click',function(){
		registrarVotacion();
	});
}
function registrarVotacion(){
	var sw=false;
	var params;
	var valor=$("#div_encuesta input[name='encuesta']:checked").attr('id');
	/*$("#div_encuesta input:radio").each(function(){
		if($(this).attr('checked')==true){
			sw=true;
			var id_opcion=$(this).attr('id');
			var valor=$(this).val();
			params="id_opcion="+id_opcion+"&valor="+valor;
		}
	});*/
	if(valor){
		var id_encuesta=$("#id_encuesta").val();
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=registrarVotacion&id_encuesta="+id_encuesta+"&valor_opc="+valor,
			dataType: "json",
			success: function(datos){
				//var html= decodeURIComponent(datos.html);
				//$("#div_encuesta").html(html);
				var correcto = decodeURIComponent(datos.correcto);
				if(correcto=='error'){
					alert('Error');
				}else if(correcto=='existe'){
					alert('Su voto ya fue registrado');
				}else{
					resultadoEncuesta(id_encuesta);
				}
			}
		});
	}else{
		alert('Debe marcar una respuesta');
	}
}

function resultadoEncuesta(id_encuesta){
	//var la=$("#la").val();
	var nombre="Resultados";
	var ventana = window.open("resultados.php?id="+id_encuesta, nombre, "width=530,height=380,scrollbars=yes,status=no,resizable=no,menubar=no,location=no,directories=no,status=no, ,titlebar=no,toolbar=no,top=200,left=200");
}
function cambiarSelectHijo(id_padre, id_hijo, url, params){
	params+="&q="+$("#"+id_padre).val();
	$.ajax({
		type: "POST",
		url: url,
		data: params,
		dataType: "json",
		success: function(datos){
			var html= decodeURIComponent(datos.html);
			$("#"+id_hijo).html(html);
		}
	});
}

var max;
var interva_convenios;
function iniGaleria_convenios(){
	$('#convenio_ant').bind("click",backImageConvenios);
	$('#convenio_sig').bind("click",nextImageConvenios);
	interva_convenios=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_convenios(){
	$('#convenio_ant').unbind("click");
	$('#convenio_sig').unbind("click");
	clearInterval(interva_convenios);
}

var offset_min_convenio=1;
function backImageConvenios(){
	detGaleria_convenios();
	var top_p=parseFloat($('#div_convenio').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_convenio").val());
	if(offset>=offset_min_convenio){
		alto=top_p+alto;
		$('#div_convenio') .animate({"left": alto},iniGaleria_convenios);
		$("#offset_convenio").val(offset-offset_min_convenio);
	}else{
		iniGaleria_convenios();
	}
	offset=($("#offset_convenio").val());
	if(offset==offset_min_convenio){
		$('#convenio_ant').hide();
	}
	$('#convenio_sig').show();
}

function nextImageConvenios(){
	detGaleria_convenios();
	var offset=parseInt($("#offset_convenio").val());
	var offset_mayor=parseInt($("#offset_convenio_actual").val());
	var id_sede_unidad=parseInt($("#id_convenio_unidad").val());
	var la=$("#la").val();
	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getConveniosInfo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_sede_unidad="+id_sede_unidad,
			dataType: "json",
			success: mostrarGalConvenios
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_convenio').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_convenio+offset;
		$("#offset_convenio").val(sum_off);
		$('#div_convenio') .animate({"left": alto},iniGaleria_convenios);
		$('#convenio_ant').show();
	}
	
}
function mostrarGalConvenios(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_convenio").val());
	var offset_mayor=parseInt($("#offset_convenio_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_convenio').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_convenio+offset_2;
		$("#offset_convenio").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_convenio_actual").val(sum_off);
		var anch_div=parseInt($('#div_convenio').css("width"));
		$('#div_convenio').css("width",anch_div+ancho);
		$('#div_convenio').append(html);
		$('#div_convenio').animate({"left": alto},iniGaleria_convenios);
		$('#convenio_ant').show();
	}else{
		$('#div_convenio').animate({"left": 0},iniGaleria_convenios);
		$("#offset_convenio").val(offset_min_convenio);
		$('#convenio_ant').hide();
	}
}

var max;
var interva_sedes;
function iniGaleria_sedes(){
	$('#sede_ant').bind("click",backImageSede);
	$('#sede_sig').bind("click",nextImageSede);
	interva_sedes=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_sedes(){
	$('#sede_ant').unbind("click");
	$('#sede_sig').unbind("click");
	clearInterval(interva_sedes);
}

var offset_min_sede=1;
function backImageSede(){
	detGaleria_sedes();
	var top_p=parseFloat($('#div_sede').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_sede").val());
	if(offset>=offset_min_sede){
		alto=top_p+alto;
		$('#div_sede') .animate({"left": alto},iniGaleria_sedes);
		$("#offset_sede").val(offset-offset_min_sede);
	}else{
		iniGaleria_sedes();
	}
	offset=($("#offset_sede").val());
	if(offset==offset_min_sede){
		$('#sede_ant').hide();
	}
	$('#sede_sig').show();
}

function nextImageSede(){
	detGaleria_sedes();
	var offset=parseInt($("#offset_sede").val());
	var offset_mayor=parseInt($("#offset_sede_actual").val());
	var id_sede_unidad=parseInt($("#id_sede_unidad").val());
	var la=$("#la").val();
	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getSedesInfo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_sede_unidad="+id_sede_unidad,
			dataType: "json",
			success: mostrarGalSede
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_sede').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_sede+offset;
		$("#offset_sede").val(sum_off);
		$('#div_sede') .animate({"left": alto},iniGaleria_sedes);
		$('#sede_ant').show();
	}
	
}
function mostrarGalSede(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_sede").val());
	var offset_mayor=parseInt($("#offset_sede_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_sede').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_sede+offset_2;
		$("#offset_sede").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_sede_actual").val(sum_off);
		var anch_div=parseInt($('#div_sede').css("width"));
		$('#div_sede').css("width",anch_div+ancho);
		$('#div_sede').append(html);
		$('#div_sede').animate({"left": alto},iniGaleria_sedes);
		$('#sede_ant').show();
	}else{
		$('#div_sede').animate({"left": 0},iniGaleria_sedes);
		$("#offset_sede").val(offset_min_sede);
		$('#sede_ant').hide();
	}
}
//////////// Seminarios-Talleres ////////
var interva_semtall;
function iniGaleria_semtall(){
	$('#semtall_ant').bind("click",backImage_semtall);
	$('#semtall_sig').bind("click",nextImage_semtall);
	interva_semtall=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_semtall(){
	$('#semtall_ant').unbind("click");
	$('#semtall_sig').unbind("click");
	clearInterval(interva_semtall);
}

var offset_min_semtall=1;
function backImage_semtall(){
	detGaleria_semtall();
	var top_p=parseFloat($('#div_semtall').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_semtall").val());
	if(offset>=offset_min_semtall){
		alto=top_p+alto;
		$('#div_semtall') .animate({"left": alto},iniGaleria_semtall);
		$("#offset_semtall").val(offset-offset_min_semtall);
	}else{
		iniGaleria_semtall();
	}
	offset=($("#offset_semtall").val());
	if(offset==offset_min_semtall){
		$('#semtall_ant').hide();
	}
	$('#semtall_sig').show();
}

function nextImage_semtall(){
	detGaleria_semtall();
	var offset=parseInt($("#offset_semtall").val());
	var offset_mayor=parseInt($("#offset_semtall_actual").val());
	var id_sede_unidad=parseInt($("#id_semtall_unidad").val());
	var la=$("#la").val();	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getPortafolioCedesarrollo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_sede_unidad="+id_sede_unidad,
			dataType: "json",
			success: mostrarGal_semtall
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_semtall').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_semtall+offset;
		$("#offset_semtall").val(sum_off);
		$('#div_semtall') .animate({"left": alto},iniGaleria_semtall);
		$('#semtall_ant').show();
	}
	
}
function mostrarGal_semtall(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_semtall").val());
	var offset_mayor=parseInt($("#offset_semtall_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_semtall').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_semtall+offset_2;
		$("#offset_semtall").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_semtall_actual").val(sum_off);
		var anch_div=parseInt($('#div_semtall').css("width"));
		$('#div_semtall').css("width",anch_div+ancho);
		$('#div_semtall').append(html);
		$('#div_semtall').animate({"left": alto},iniGaleria_semtall);
		$('#semtall_ant').show();
	}else{
		$('#div_semtall').animate({"left": 0},iniGaleria_semtall);
		$("#offset_semtall").val(offset_min_semtall);
		$('#semtall_ant').hide();
	}
}
//////////// Seminarios ////////
var interva_seminarios;
function iniGaleria_seminarios(){
	$('#seminarios_ant').bind("click",backImage_seminarios);
	$('#seminarios_sig').bind("click",nextImage_seminarios);
	interva_seminarios=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_seminarios(){
	$('#seminarios_ant').unbind("click");
	$('#seminarios_sig').unbind("click");
	clearInterval(interva_seminarios);
}

var offset_min_seminarios=1;
function backImage_seminarios(){
	detGaleria_seminarios();
	var top_p=parseFloat($('#div_seminarios').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_seminarios").val());
	if(offset>=offset_min_seminarios){
		alto=top_p+alto;
		$('#div_seminarios') .animate({"left": alto},iniGaleria_seminarios);
		$("#offset_seminarios").val(offset-offset_min_seminarios);
	}else{
		iniGaleria_seminarios();
	}
	offset=($("#offset_seminarios").val());
	if(offset==offset_min_seminarios){
		$('#seminarios_ant').hide();
	}
	$('#seminarios_sig').show();
}

function nextImage_seminarios(){
	detGaleria_seminarios();
	var offset=parseInt($("#offset_seminarios").val());
	var offset_mayor=parseInt($("#offset_seminarios_actual").val());
	var id_sede_unidad=parseInt($("#id_seminarios_unidad").val());
	var la=$("#la").val();	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getPortafolioCedesarrollo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_sede_unidad="+id_sede_unidad,
			dataType: "json",
			success: mostrarGal_seminarios
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_seminarios').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_seminarios+offset;
		$("#offset_seminarios").val(sum_off);
		$('#div_seminarios') .animate({"left": alto},iniGaleria_seminarios);
		$('#seminarios_ant').show();
	}
	
}
function mostrarGal_seminarios(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_seminarios").val());
	var offset_mayor=parseInt($("#offset_seminarios_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_seminarios').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_seminarios+offset_2;
		$("#offset_seminarios").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_seminarios_actual").val(sum_off);
		var anch_div=parseInt($('#div_seminarios').css("width"));
		$('#div_seminarios').css("width",anch_div+ancho);
		$('#div_seminarios').append(html);
		$('#div_seminarios').animate({"left": alto},iniGaleria_seminarios);
		$('#seminarios_ant').show();
	}else{
		$('#div_seminarios').animate({"left": 0},iniGaleria_seminarios);
		$("#offset_seminarios").val(offset_min_seminarios);
		$('#seminarios_ant').hide();
	}
}
////////////Talleres ////////
var interva_talleres;
function iniGaleria_talleres(){
	$('#talleres_ant').bind("click",backImage_talleres);
	$('#talleres_sig').bind("click",nextImage_talleres);
	interva_talleres=setInterval(function(){
		//$('#sede_sig').click();
	},7000);
}
function detGaleria_talleres(){
	$('#talleres_ant').unbind("click");
	$('#talleres_sig').unbind("click");
	clearInterval(interva_talleres);
}

var offset_min_talleres=1;
function backImage_talleres(){
	detGaleria_talleres();
	var top_p=parseFloat($('#div_talleres').css('left'));
	var alto=535;
	var offset=parseInt($("#offset_talleres").val());
	if(offset>=offset_min_talleres){
		alto=top_p+alto;
		$('#div_talleres') .animate({"left": alto},iniGaleria_talleres);
		$("#offset_talleres").val(offset-offset_min_talleres);
	}else{
		iniGaleria_talleres();
	}
	offset=($("#offset_talleres").val());
	if(offset==offset_min_talleres){
		$('#talleres_ant').hide();
	}
	$('#talleres_sig').show();
}

function nextImage_talleres(){
	detGaleria_talleres();
	var offset=parseInt($("#offset_talleres").val());
	var offset_mayor=parseInt($("#offset_talleres_actual").val());
	var id_sede_unidad=parseInt($("#id_talleres_unidad").val());
	var la=$("#la").val();	
	if(offset==offset_mayor){
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getPortafolioCedesarrollo&random=true&codificar=no&la="+la+"&offset="+offset+"&id_sede_unidad="+id_sede_unidad,
			dataType: "json",
			success: mostrarGal_talleres
		});
	}else{
		var alto=535;
		var top_p=parseFloat($('#div_talleres').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_talleres+offset;
		$("#offset_talleres").val(sum_off);
		$('#div_talleres') .animate({"left": alto},iniGaleria_talleres);
		$('#talleres_ant').show();
	}
	
}
function mostrarGal_talleres(datos){
	var msj= decodeURIComponent(datos.result);
	var html= decodeURIComponent(datos.msg);
	var offset=parseInt($("#offset_talleres").val());
	var offset_mayor=parseInt($("#offset_talleres_actual").val());
	var offset_2=parseInt(decodeURIComponent(datos.offset));
	var primer_tour=parseInt(decodeURIComponent(datos.id_to));
	var alto=535;
	var ancho=535;
	if(msj=="si"){
		var top_p=parseFloat($('#div_talleres').css('left'));
		alto=top_p-alto;
		var sum_off=offset_min_talleres+offset_2;
		$("#offset_talleres").val(sum_off);
		if(sum_off>offset_mayor)
			$("#offset_talleres_actual").val(sum_off);
		var anch_div=parseInt($('#div_talleres').css("width"));
		$('#div_talleres').css("width",anch_div+ancho);
		$('#div_talleres').append(html);
		$('#div_talleres').animate({"left": alto},iniGaleria_talleres);
		$('#talleres_ant').show();
	}else{
		$('#div_talleres').animate({"left": 0},iniGaleria_talleres);
		$("#offset_talleres").val(offset_min_talleres);
		$('#talleres_ant').hide();
	}
}
function iniContactenosMaps(){
	$("[tipo_mapa='true']").each(function(){
		var id=$(this).attr("id");
		var id_unidad=$(this).attr("id_unidad");
		iniGaleria_puntos(id_unidad);
		getMapNew(id);
	});
}

var max;
var interva_puntos;
function iniGaleria_puntos(id){
	$('#back_puntos_'+id).bind("click",function(){
		backImage(id);
	});
	$('#next_puntos_'+id).bind("click",function(){
		nextImage(id);
	});
	interva_puntos=setInterval(function(){
		$('#next_puntos_'+id).click();
	},9000);
}
function detGaleria_puntos(id){
	$('#back_puntos_'+id).unbind("click");
	$('#next_puntos_'+id).unbind("click");
	clearInterval(interva_puntos);
}
var offset_min=1;
function backImage(id){
	detGaleria_puntos(id);
	var top_p=parseFloat($('#div_puntos_'+id).css('left'));
	var alto=201;
	var offset=parseInt($("#offset_puntos_"+id).val());
	if(offset>=offset_min){
		alto=top_p+alto;
		$('#div_puntos_'+id) .animate({"left": alto},function(){
			iniGaleria_puntos(id);
		});
		$("#offset_puntos_"+id).val(offset-offset_min);
	}else{
		iniGaleria_puntos(id);
	}
	offset=($("#offset_puntos_"+id).val());
	if(offset=="0"){
		$('#back_puntos_'+id).hide();
	}
	$('#next_puntos_'+id).show();
}

function nextImage(id){
	detGaleria_puntos(id);
	var offset=parseInt($("#offset_puntos_"+id).val());
	var offset_mayor=parseInt($("#offset_puntos_actual_"+id).val());
	var la=$("#la").val();
	
	if(offset==offset_mayor){
		$('#div_puntos_'+id) .animate({"left": 0},function(){
			iniGaleria_puntos(id);
		});
		$("#offset_puntos_"+id).val("0");
		$('#back_puntos_'+id).hide();
	}else{
		var alto=201;
		var top_p=parseFloat($('#div_puntos_'+id).css('left'));
		alto=top_p-alto;
		var sum_off=offset_min+offset;
		$("#offset_puntos_"+id).val(sum_off);
		$('#div_puntos_'+id) .animate({"left": alto},function(){
			iniGaleria_puntos(id);
		});
		$('#back_puntos_'+id).show();
	}
	
}

var list_map;
var map;
function getMapNew(id){
	var latitud=10.404515;
	var longitud=-75.553624;
	var latlng = new google.maps.LatLng(latitud, longitud);
	var zoom=11;
	var obj_type=google.maps.MapTypeId.ROADMAP;
	var myOptions = {
     zoom: zoom,
     center: latlng,
     mapTypeId: obj_type
   };
	var div=id;
   map = new google.maps.Map(document.getElementById(div), myOptions);
   list_map=addEvent(map,"tilesloaded",getPuntos);
}
var markersArray=[];
var markers=[];
function getPuntos(){
	var cont=0;
	$("[puntos_map='si']").each(function(){
		var idp=$(this).attr("id_punto");
		var lat=$("#latitud_"+idp).val();
		var lng=$("#longitud_"+idp).val();
		var direccion=$("#direccion_"+idp).val();
		var telefono=$("#telefono_"+idp).val();
		var movil=$("#movil_"+idp).val();
		var correo=$("#correo_"+idp).val();
		
		var latlng = new google.maps.LatLng(lat, lng, direccion);
		var marker=addMarker(latlng,map);
		marker.id=cont;
		marker.direccion=direccion;
		//markers[cont]=nombre;
		
		addEvent(marker,"click",showInfoWindow);
		cont++;
	});
	removeEvent(list_map);	
}

function showInfoWindow(){
	var id=this.id;
	var direccion=this.direccion;
	var infowindow=new google.maps.InfoWindow();
	infowindow.setContent("<table width='220'> <tr><th style='text-align:center' class=''><img src='imagenes/logo_small.jpg'</th></tr><tr><td class='parrafos'>"+direccion+"</td></tr></table>");
    infowindow.open(map, this);
}

function addMarker(location, map) {
	if(arguments[2])
		var title=arguments[2];
	else
		var title="";
	
	if(arguments[3])
		var icon=arguments[3];
	else
		var icon="";
	
	  var marker = new google.maps.Marker({
	    position: location,
	    map: map,
	    title: title,
	    icon: icon
	  });
	  markersArray.push(marker);
	  
	  return marker;
}
function addEvent(map,event,function_name){
	 var listener=google.maps.event.addListener(map, event, function_name);
	 return listener;
}

function removeEvent(listener){
	google.maps.event.removeListener(listener); 
}

function iniTabs(){
	$("#div_tabs").tabs("destroy");
	$("#div_tabs").tabs({
		select: function(event, ui){
			//$("#tipo_menu").val($(ui.tab).attr("tipo"));
		}
	});
}

function iniciarCalendario(){
	$("#ant_calendario").bind("click", backCalendario);
	$("#sig_calendario").bind("click", nextCalendario);
	addEventoDias();
}

function addEventoDias(){
	$("[eventos='yes']").bind("click", getEventosDia);
}

function getEventosDia(){
	var la=$("#la").val();
	var mes_actual=$("#mes_actual").val();
	var ano_actual=$("#ano_actual").val();
	var fecha_buscar=$(this).attr("fecha");
	if(cache_dias[fecha_buscar]){
		$("#div_eventos_items").html(cache_dias[fecha_buscar]);
	}else{
		var alto=$("#div_eventos_items").height();
		$("#div_eventos_items").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:"+alto+"px; width:250px;'>");
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getEventosFecha&random=true&codificar=no&tipo=back&la="+la+"&fecha="+fecha_buscar,
			dataType: "text"
		}).success(function(datos){
			$("#div_eventos_items").html(datos);
			cache_dias[fecha_buscar] = datos;
		});
	}
}

function backCalendario(){
	var la=$("#la").val();
	var mes_actual=$("#mes_actual").val();
	var ano_actual=$("#ano_actual").val();
	var mes_new=mes_actual-1;
	var ano_new=ano_actual;
	if(mes_new<1){
		mes_new=12;
		ano_new--;
	}
	/*if(cache_calendario[mes_new][ano_new]){
		$("#td_plantilla_calenario").html(cache_calendario[mes_new][ano_new]);
		$("#span_ano_actual").html(ano_new);
		$("#mes_actual").html(mes_new);
		$("#ano_actual").html(ano_new);
	}else{*/
		$("#td_plantilla_calenario").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:559px; width:580px;'>");
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getCalendario&random=true&codificar=no&tipo=back&la="+la+"&mes_actual="+mes_actual+"&ano_actual="+ano_actual,
			dataType: "json"
		}).success(function(datos){
			var html= decodeURIComponent(datos.html);
			var mes= decodeURIComponent(datos.mes);
			var ano= decodeURIComponent(datos.ano);
			
			$("#td_plantilla_calenario").html(html);
			$("#span_ano_actual").html(ano);
			$("#mes_actual").val(mes);
			$("#ano_actual").val(ano);
			addEventoDias();
			//cache_calendario[mes][ano] = html;
		});
	/*}*/
}

function nextCalendario(){
	var la=$("#la").val();
	var mes_actual=$("#mes_actual").val();
	var ano_actual=$("#ano_actual").val();
	var mes_new=mes_actual+1;
	var ano_new=ano_actual;
	
		$("#td_plantilla_calenario").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader.gif) no-repeat center; height:559px; width:580px;'>");
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=getCalendario&random=true&codificar=no&tipo=next&la="+la+"&mes_actual="+mes_actual+"&ano_actual="+ano_actual,
			dataType: "json"
		}).success(function(datos){
			var html= decodeURIComponent(datos.html);
			var mes= decodeURIComponent(datos.mes);
			var ano= decodeURIComponent(datos.ano);
			
			$("#td_plantilla_calenario").html(html);
			$("#span_ano_actual").html(ano);
			$("#mes_actual").val(mes);
			$("#ano_actual").val(ano);
			addEventoDias();
			//cache_calendario[mes][ano] = html;
		});
}

function iniciarRSS(){
	$("#registrar_rss").bind("click",registrarRSS);
}

function registrarRSS(){
	var nombre=$("#rss_nombre").val();
	var correo=$("#rss_correo").val();
	var direccion=$("#rss_direccion").val();
	var telefono=$("#rss_telefono").val();
	var movil=$("#rss_movil").val();
	var empresa=$("#rss_empresa").val();
	if(validarVacio(nombre)!=false && validarVacio(correo)!=false){
		//$("#div_rss").html("<div id='cargandodiv' style='background:url(imagenes/ajax-loader3.gif) no-repeat center; height:10px; width:280px;'>");
		var la=$("#la").val();
		$.ajax({
			type: "POST",
			url: "contenido.php",
			data: "accion=registrarRSS&codificar=no&la="+la+"&nombre="+encodeURIComponent(nombre)+"&correo="+encodeURIComponent(correo)+"&direccion="+encodeURIComponent(direccion)+"&telefono="+encodeURIComponent(telefono)+"&movil="+encodeURIComponent(movil)+"&empresa="+encodeURIComponent(empresa),
			dataType: "json",
			success: function(datos){
			 		var result=decodeURIComponent(datos.msg);
			 		var html=decodeURIComponent(datos.html);
			 		if(result=="correcto"){
			 			$("#div_rss").html(html);
						$("#registrar_rss").unbind("click");
			 		}else{
			 			alert(html);
			 		}
					
			}
		});
	}else{
		var txt_error=$("#txt_error_suscripcion").val();
		alert(txt_error);
	}
}

function preload() {
	if (!document.images) return;
	var ar = new Array();
	var arguments = preload.arguments;
	for (var i = 0; i < arguments.length; i++) {
		ar[i] = new Image();
		ar[i].src = arguments[i];
	}
}

function validarVacio(q) {  
         for ( i = 0; i < q.length; i++ ) {  
                 if ( q.charAt(i) != " " ) {  
                         return true  
                 }  
         }  
         return false  
}

/*********************
//* jQuery Multi Level CSS Menu (horizontal)- By Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//* Menu instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
//* Last modified: Sept 6th, 08'. Usage Terms: http://www.dynamicdrive.com/style/csslibrary/tos/
*********************/

//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'arrow-down.gif', 0], right:['rightarrowclass', './imagenes/fly-over.gif']}

var jquerycssmenu={

fadesettings: {overduration: 0, outduration: 5}, //duration of fade in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			var htimg=this.istopheader? '' : '<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				htimg
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					$targetul.css({left:menuleft+"px"}).fadeIn(jquerycssmenu.fadesettings.overduration)
				},
				function(e){
					$(this).children("ul:eq(0)").fadeOut(jquerycssmenu.fadesettings.outduration)
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myjquerymenu" on page:
jquerycssmenu.buildmenu("myjquerymenu", arrowimages)
