/*
	Custom Checkbox
	Fransjo Leihitu
	http://www.woedend.nl

	
	Description:
	
	
	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
	(basically, do anything you want, just leave my name and link)
	
	NOTE!
	This script uses Prototype!
*/
function customCheckbox(id,args)
{
	this.imgID=null;
	this.imgCountLoaded=0;
	this.img=Array();
	this.currentState=0;
	
	// defaults
	this.args=Array();
	this.args["imgPath"]="";
	this.args["defaultState"]=0;
	
	this.onClicked=onClicked;
	
	
	// use the arguments
	this.args=args;		
	
	this.currentState=this.args["defaultState"];
	
	if(typeof this.args["onClicked"] != "undefined") this.onClicked=this.args["onClicked"];
	
	// the methods
	this.initAfterImgLoaded=initAfterImgLoaded;
	this.setState=setState;
	this.getState=getState;
	this.setChecked=setChecked;
	this.setUnChecked=setUnChecked;
	this.switchState=switchState;
	//------------------------------------------------
  //HV.2007.04.23: 3707 Filters resetten
	this.setInitUnChecked=setInitUnChecked;
	//------------------------------------------------
	
	if(typeof id !="undefined")
	{		
		if($(id))
		{
			this.imgID=$(id);
		}
	}
	
	if(this.imgID==null)
	{
		//alert("cannot find the element");
	} else {
	
	//alert(this.args["imgPath"]);
	// load the images
	
		this.img[0]=new Image();
		this.img[0].src=this.args["imgPath"] + "state_0.gif";
		this.img[0].onerror=imgLoadErrorHandler;
		
		this.img[1]=new Image();
		this.img[1].src=this.args["imgPath"] + "state_1.gif";
		this.img[1].onerror=imgLoadErrorHandler;
		
		
		this.img[2]=new Image();
		this.img[2].src=this.args["imgPath"] + "state_2.gif";		
		this.img[2].error=imgLoadErrorHandler;

		/*
		this.go=false;
		while(!this.go)
		{
			if( (this.img[0].complete==true) && (this.img[1].complete==true) && (this.img[2].complete==true))
			{
				this.go=true;
			}
		}
		*/
		
		this.initAfterImgLoaded();
	}
	
	function imgLoadErrorHandler()
	{
		alert("hmm cannot load : " + this.src);
	}
	
		
	function initAfterImgLoaded()
	{
		this.imgID.src=this.img[this.args["defaultState"]].src;
		
		this.imgID.onclick=this.onClicked;
		
	}
	
	function onClicked()
	{
		alert("you have clicked on : " + this.id);
	}
	
	function setState(stateNr)
	{
		if(typeof this.imgID != "undefined")
		{
			if(typeof stateNr != "undefined")
			{
				if(stateNr<=2)
				{
					this.currentState=stateNr;
					this.imgID.src=this.img[this.currentState].src;
				}
			}
		}
	}
	
	function setChecked()
	{
		this.setState(1);
	}
	
	function setUnChecked()
	{
		this.setState(0);
	}
	
	//------------------------------------------------
  //HV.2007.04.23: 3707 Filters resetten
	function setInitUnChecked()
	{
		this.setState(2);
	}
	//------------------------------------------------
	
	function switchState()
	{
		if(this.currentState==1) 
		{
			this.setUnChecked();
		} else {
			this.setChecked();
		}
	}
	
	function getState()
	{
		return this.currentState;
	}
}

var checkboxMen;
var checkboxWomen;
var checkboxKids;
var checkboxShoes;
var checkboxApparel;
var checkboxAccesories;

var filterState=0;

function initCustomCheckboxObjects(strImagePath)
{
	checkboxMen=new customCheckbox("check_men",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});
	checkboxWomen=new customCheckbox("check_women",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});	
	checkboxKids=new customCheckbox("check_kids",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});	
	
	checkboxShoes=new customCheckbox("check_shoes",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});	
	checkboxApparel=new customCheckbox("check_apparel",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});	
	checkboxAccesories=new customCheckbox("check_accesories",{imgPath:strImagePath+"customcheckbox/firefox/",defaultState:2,onClicked:checkboxHandler});	
}

