var secs2wait = 5;
var secs;
var delay = 1000;
var timerID = null;
var timerRunning = false;
var element_ant = '';
var num_ant = 0;

function InitializeTimer() {
	secs = secs2wait;
	StopTheClock();
	StartTheTimer();
}

function StopTheClock() {
	if (timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}

function StartTheTimer() {
	if (secs == 0) {
		StopTheClock();
		toc (element_ant, 1);
	}
	else {
		secs--;
		timerRunning = true;
		timerID = self.setTimeout("StartTheTimer()", delay);
	}
}



if (document.images) {
	m1on = new Image(); m1on.src = '/commons/imgs/m1_on.gif';
	m1off = new Image(); m1off.src = '/commons/imgs/m1_off.gif';
	
	m_2off_2off = new Image(); m_2off_2off.src = '/commons/imgs/m_2off_2off.gif';
	m_2on_2off = new Image(); m_2on_2off.src = '/commons/imgs/m_2on_2off.gif';
	m_2off_2on = new Image(); m_2off_2on.src = '/commons/imgs/m_2off_2on.gif';
	m_2on_2on = new Image(); m_2on_2on.src = '/commons/imgs/m_2on_2on.gif';
	m2_2off = new Image(); m2_2off.src = '/commons/imgs/m2_2off.gif';
	m2_2on = new Image(); m2_2on.src = '/commons/imgs/m2_2on.gif';
	
	m_3off_3off = new Image(); m_3off_3off.src = '/commons/imgs/m_3off_3off.gif';
	m_3on_3off = new Image(); m_3on_3off.src = '/commons/imgs/m_3on_3off.gif';
	m_3off_3on = new Image(); m_3off_3on.src = '/commons/imgs/m_3off_3on.gif';
	m_3on_3on = new Image(); m_3on_3on.src = '/commons/imgs/m_3on_3on.gif';
	m3_3off = new Image(); m3_3off.src = '/commons/imgs/m3_3off.gif';
	m3_3on = new Image(); m3_3on.src = '/commons/imgs/m3_3on.gif';
	
	m4on = new Image(); m4on.src = '/commons/imgs/m4_on.gif';
	m4off = new Image(); m4off.src = '/commons/imgs/m4_off.gif';
	m5on = new Image(); m5on.src = '/commons/imgs/m5_on.gif';
	m5off = new Image(); m5off.src = '/commons/imgs/m5_off.gif';
	m6on = new Image(); m6on.src = '/commons/imgs/m6_on.gif';
	m6off = new Image(); m6off.src = '/commons/imgs/m6_off.gif';
	m7on = new Image(); m7on.src = '/commons/imgs/m7_on.gif';
	m7off = new Image(); m7off.src = '/commons/imgs/m7_off.gif';
	
	abrir_on = new Image(); abrir_on.src = '/commons/imgs/abrir_on.gif';
	abrir_off = new Image(); abrir_off.src = '/commons/imgs/abrir_off.gif';
	cerrar_on = new Image(); cerrar_on.src = '/commons/imgs/cerrar_on.gif';
	m_pie = new Image(); m_pie.src = '/commons/imgs/m_pie.gif';

	/* Elementos de la caja de recortes */
	clipping_trash_on = new Image(); clipping_trash_on.src = '/commons/imgs/trash_on.gif';
	clipping_trash_off = new Image(); clipping_trash_off.src = '/commons/imgs/trash_off.gif';
	clipping_folder = new Image(); clipping_folder.src = '/commons/imgs/folder.gif';
	clips_abrir_on = new Image(); clips_abrir_on.src = '/commons/imgs/clips_abrir_on.gif';
	clips_abrir_off = new Image(); clips_abrir_off.src = '/commons/imgs/clips_abrir_off.gif';
	clips_cerrar_on = new Image(); clips_cerrar_on.src = '/commons/imgs/clips_cerrar_on.gif';
	clips_cerrar_off = new Image(); clips_cerrar_off.src = '/commons/imgs/clips_cerrar_off.gif';
}
		
function cambiar (imagen, cambio) {
	if (document.images)
		document[imagen].src = eval(cambio).src;
}


function toc (element, timeout) {
	/* cierro la carpeta de recortes */
	var clippings_container = new get_obj('clippings_container');
	if (clippings_container.style.display == '') {
		var clippings_toc = new get_obj('clippings_toc');
		clippings_toc.obj.innerHTML = '<a href="javascript:;" onclick="toc_clippings()" title="" onmouseover="cambiar(\'clips_abrir\',\'clips_abrir_on\')" onmouseout="cambiar(\'clips_abrir\',\'clips_abrir_off\')"><img name="clips_abrir" src="/commons/imgs/clips_abrir_off.gif" alt="" /></a>';
		clippings_container.style.display = 'none';
	}
	/* end */
	
	var menu = new get_obj(element);
	var m_abrir = new get_obj(element + '_abrir');
	var m_cerrar = new get_obj(element + '_cerrar');
	var num = 0;
	
	switch (element) {
		case ('m_secciones') : num = 2; break;
		case ('m_suplementos') : num = 3;
	}
	
	if (element_ant != element && element_ant != '') {
		var menu_ant = new get_obj(element_ant);
		var m_abrir_ant = new get_obj(element_ant + '_abrir');
		var m_cerrar_ant = new get_obj(element_ant + '_cerrar');
		menu_ant.style.display = 'none';
		m_cerrar_ant.style.display = 'none';
		m_abrir_ant.style.display = '';
		if (secc_actual == num_ant) cambiar(element_ant + '_10_abrir','m' + num_ant + '_' + num_ant + 'off');
		else cambiar(element_ant + '_10_abrir','m_' + num_ant + 'off_' + num_ant + 'off');
		cambiar(element_ant + '_01_abrir','abrir_off');
	}
	
	if (menu.style.display == 'none') {
		/* escondo los selects del IE */
		if (ie_s1 != '') {
			var ie_s = new get_obj(ie_s1);
			if (ie_s.style.display == '') {
				ie_s.style.display='none'; 
				flag1 = true;
			}
		}
		if (ie_s2 != '') {
			var ie_s=new get_obj(ie_s2);
			if (ie_s.style.display == '') {
				ie_s.style.display='none';
				flag2 = true;
			}
		}
		if (ie_s3 != '') {
			var ie_s = new get_obj(ie_s3);
			if (ie_s.style.display == '') {
				ie_s.style.display='none';
				flag3 = true;
			}
		}
		if (ie_s4 != '') {
			var ie_s = new get_obj(ie_s4);
			if (ie_s.style.display == '') {
				ie_s.style.display='none';
				flag4 = true;
			}
		}

		/* */
		menu.style.display = '';
		m_abrir.style.display = 'none';
		m_cerrar.style.display = '';
		if (secc_actual == num) cambiar(element + '_10_cerrar','m' + num + '_' + num + 'on');
		else cambiar(element + '_10_cerrar','m_' + num + 'off_' + num + 'on');
		cambiar(element + '_01_cerrar','cerrar_on');
		InitializeTimer();
		element_ant = element;
		num_ant = num;
	}
	else {
		/* muestro los fuckings selects del IE */
		if (ie_s1 != '') {
			var ie_s = new get_obj(ie_s1);
			if (ie_s.style.display == 'none' && flag1==true) ie_s.style.display='';
		}
		if (ie_s2 != '') {
			var ie_s = new get_obj(ie_s2);
			if (ie_s.style.display == 'none' && flag2==true) ie_s.style.display='';
		}
		if (ie_s3 != '') {
			var ie_s = new get_obj(ie_s3);
			if (ie_s.style.display=='none' && flag3==true) ie_s.style.display='';
		}
		if (ie_s4 != '') {
			var ie_s = new get_obj(ie_s4);
			if (ie_s.style.display=='none' && flag4==true) ie_s.style.display='';
		}
		/* */
		menu.style.display = 'none';
		m_cerrar.style.display = 'none';
		m_abrir.style.display = '';
		if (timeout) {
			if (secc_actual == num) cambiar(element + '_10_abrir','m' + num + '_' + num + 'off');
			else cambiar(element + '_10_abrir','m_' + num + 'off_' + num + 'off');
			cambiar(element + '_01_abrir','abrir_off');
		}
		else {
			if (secc_actual == num) cambiar(element + '_10_abrir','m' + num + '_' + num + 'on');
			else cambiar(element + '_10_abrir','m_' + num + 'off_' + num + 'on');
			cambiar(element + '_01_abrir','abrir_on');
		}
		StopTheClock();
		element_ant = '';
		num_ant = 0;
	}
}

