/*
articlepxfontsize_j15 - Plugin Article px Font Size for Joomla! 1.5x
author karmany
copyright (C) 2011 by karmany (http://www.karmany.co.cc)
license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
	
Please retain this copyright notice.
You can use this code if this copyright notice are included
*/

//Los tags que seran modificados:
var tgs = new Array( 'div', 'p', 'tr', 'td', 'table', 'ul', 'ol');
var sz = new Array();
var size_inicial = 9;

function sz_default (por_defecto,contador){
	//Reinicializa la variable sz y guardamos dato
	sz[contador] = por_defecto;
	size_inicial = por_defecto;
}

function modify_size(busca,inc,contador) {
	
	var doc = document,eldoc = null,busca_tgs,i,j;
	
	if (inc == 0)
	{
		sz[contador] = size_inicial;
	}
	else
	{
		sz[contador] += inc;
		if ( sz[contador] < 6 ) sz[contador] = 6;
		if ( sz[contador] > 21 ) sz[contador] = 21;
	}
	
	//Buscamos el div con class
	if (!(eldoc = getElementConClass( busca , 'div', contador))) return;
	eldoc.style.fontSize = sz[contador]+'px';
	
	for (i=0; i<tgs.length; i++)
	{
		busca_tgs = eldoc.getElementsByTagName( tgs[i] );
		for (j=0; j<busca_tgs.length; j++) busca_tgs[j].style.fontSize = sz[contador]+'px'; 	
	}	
}

function getElementConClass(busca_class,tag,cuenta) {

       var classElement, Cantidad_els, clave, ii, j;
       
       var els = this.document.getElementsByTagName(tag);

       Cantidad_els = els.length;
       clave = new RegExp("(^|\\s)"+busca_class+"(\\s|$)");
       j = 0;
       for (ii=0; ii<Cantidad_els; ii++) {
               if ( clave.test(els[ii].className)) {
                   ++j;
                   if (cuenta == j){
                	   classElement = els[ii];
                     break;
                   }
               }
       }
       return classElement;
}

