/* 
	FunctionsCombino for Loterie Nationale 
	by Gauthier Dumont (gauthier.dumont@lbigroup.be) :: LBi
	created on 28/03/08 
*/

var conbino = {
	
	inputs		:	'',
	label		:	'',
	imgFalse 	: 	'',
	imgTrue 	: 	'',
	globalElem  :  	'',
	colorFalse	:	'',
	colorTrue	:	'',
	idInput		:	'',
	instance	:	0,
	imageArr	: 	new Array(),
	colorArr	: 	new Array(),

	_initCombino : function(){
		var globalElem = $(this.globalElem);
		//get all the input fields on the page
		this.inputs 	= globalElem.getElementsByTagName('input');
		this.labels		= globalElem.getElementsByTagName('label');
		arrTemp			= new Array();
		arrTemp[0]		= this.imgFalse;
		arrTemp[1]		= this.imgTrue;
		this.imageArr.push(arrTemp);
		arrTemp			= new Array();
		arrTemp[0]		= this.colorFalse;
		arrTemp[1]		= this.colorTrue;
		this.colorArr.push(arrTemp);
		this.instance++;
		
		this._parseDoc();
	},
	
	_parseDoc : function(){
		//cycle trough the input fields
		for(var i=1; i < this.inputs.length+1; i++) {
			//create a new image
			var img 	= document.createElement('img');
			var idItem 	= i - 1;
			//check if the checkbox is checked
			if(this.inputs[idItem].checked) {
				this.labels[idItem].style.color 	= 	'#'+this.colorTrue;
				img.src 							= 	this.imgTrue;
			} else {
				this.labels[idItem].style.color 	= 	'#'+this.colorFalse;
				img.src 							= 	this.imgFalse;
			}
			//set image ID and onclick action
			img.id 									= this.idInput+'IMG'+i;
			//set image
			img.onclick 							= new Function("conbino._checkChange('"+i+"','"+this.idInput+"','"+this.instance+"', 0)");
			this.labels[idItem].onclick 			= new Function("conbino._checkChange('"+i+"','"+this.idInput+"','"+this.instance+"', 1)");
			//place image in front of the checkbox
			this.inputs[idItem].parentNode.insertBefore(img, this.inputs[idItem]);
			
			//hide the checkbox
			this.inputs[idItem].style.display 		= 'none';
			this.labels[idItem].id					= this.idInput+'LABEL'+i;
		}
	},
	

	//change the checkbox status and the replacement image
	_checkChange : function (i,idInput,instance, isLabel) {
		if (navigator.appName.indexOf("Explorer") > -1) {isLabel=0;}
		instance = instance -1;
		if($(idInput+i).checked) {
			if(!isLabel)
				$(idInput+i).checked 				= 	'';
			$(idInput+'IMG'+i).src 				= 	this.imageArr[instance][0];
			$(idInput+'LABEL'+i).style.color 	= 	'#'+this.colorArr[instance][0];
		} else {
			if(!isLabel)
				$(idInput+i).checked 				= 	'checked';
			$(idInput+'IMG'+i).src 				= 	this.imageArr[instance][1];
			$(idInput+'LABEL'+i).style.color	=	'#'+this.colorArr[instance][1];
		}
	}
	
	
}  