/**
 * JSToggler
 *
 * Javascript code for the JSToggler mediawiki extension
 *
 *	@author Filipe Morais
 *      @Version 0.9
 *      @Last Change 27/10/2010
 *      @License Gnu GPLv2 (http://www.gnu.org/licenses/gpl-2.0.html)
 *      
 *      @note This extension was created as part of the implementation of a new generation of wiki to the 
 *      Caixa Magica Community (http://www.caixamagica.pt/pag/a_index.php)  during the Caixa Magica Summer Internships 2010 program. 
 *      Caixa Magica is a Mandriva based Linux distribution developed in Portugal by the Portuguese Company "Caixa Magica Software".
 *
 * 	@usage check the extension page at mediawiki or JSToggler.php
 */
 
 
/**
 * JSTSwitch
 *
 * Obtains the class of the div with the id 'item'. 
 * Then, sets all divs of that class but the one with the id 'item' with the css attribute display:none IF 'type' is set to single.
 * Finally, the divs with the id 'item' will be set to display:none if they have display:block set or display:block if they are set to display:none.
 *
 * @param item name of the var to be set visible (or invisible)
 * @param group Group this items belongs. Check JSToggler.php for more info
 * @param type (accepts 'single' or 'multi' or 'group' as imput. check usage on JSToggler.php for more info.
 */
var JSTSwitch = function(item ,group, type){
 
	//gets all divs in this document
	var divs = document.getElementsByTagName('div');
 
	//hides or shows the correct divs. Only handles divs with class==group
	if(type != "group"){
		for(var i = 0; i < divs.length; i++)
			if(divs[i].getAttribute("class") == group)
				if(divs[i].id != item && type == "multi")
					document.getElementById(divs[i].id).style.display = "none";
				else if (divs[i].id == item)
					if(document.getElementById(divs[i].id).style.display == "none")
						document.getElementById(divs[i].id).style.display = "block";
					else
						document.getElementById(divs[i].id).style.display = "none";
	}else{
		var open = 0;
 
		for(var i=0; i < divs.length; i++) 
			if(divs[i].getAttribute("class") == group)
				if(document.getElementById(divs[i].id).style.display == "block")
					open-=1;
		                else
					open+=1;
 
		for(var i=0; i < divs.length; i++)
			if(divs[i].getAttribute("class") == group)
				if(open >= 0)
					document.getElementById(divs[i].id).style.display = "block";
			        else
				        document.getElementById(divs[i].id).style.display = "none"; 
	}
 
}


