/**
 * http://ajaxui.nhndesign.com/svn/Jindo_Component/Component/tags/0.2.1/component.js
 * http://ajaxui.nhndesign.com/svn/Jindo_Component/HTMLComponent/tags/0.1.1/htmlcomponent.js
 * http://ajaxui.nhndesign.com/svn/Jindo_Component/CheckBox/tags/0.4/checkbox.js
 */


if(typeof jindo=="undefined"){jindo={};jindo.$Class=$Class;jindo.$Event=$Event;jindo.$H=$H;jindo.$Fn=$Fn;}
nhn.Component=jindo.$Class({_eventHandlers:null,_options:null,$init:function(){var ins=this.constructor._instances;if(typeof ins=="undefined"){this.constructor._instances=ins=[];}
ins[ins.length]=this;this._eventHandlers={};this._options={};this._options._setters={};},option:function(sName,sValue){var nameType=(typeof sName);if(nameType=="undefined"){return this._options;}else if(nameType=="string"){if(typeof sValue!="undefined"){this._options[sName]=sValue;if(typeof this._options._setters[sName]=="function"){this._options._setters[sName](sValue);}
return this;}else{return this._options[sName];}}else if(nameType=="object"){try{for(var x in sName){this._options[x]=sName[x];if(typeof this._options._setters[x]=="function"){this._options._setters[x](sName[x]);}}}catch(e){}
return this;}},optionSetter:function(sName,fSetter){var nameType=(typeof sName);if(nameType=="undefined"){return this._options._setters;}else if(nameType=="string"){if(typeof fSetter!="undefined"){this._options._setters[sName]=jindo.$Fn(fSetter,this).bind();return this;}else{return this._options._setters[sName];}}else if(nameType=="object"){try{for(var x in sName){this._options._setters[x]=jindo.$Fn(sName[x],this).bind();}}catch(e){}
return this;}},fireEvent:function(sEvent,oEvent){var oEvent=oEvent?(oEvent instanceof jindo.$Event?oEvent._event:oEvent):{};var inlineHandler=this['on'+sEvent];var handlerList=this._eventHandlers[sEvent];var bHasInlineHandler=typeof inlineHandler=='function';var bHasHandlerList=typeof handlerList!='undefined';if(!bHasInlineHandler&&!bHasHandlerList)return true;var isRealEvent=(function(oEvent){try{if(oEvent instanceof Event)return true;}catch(x){}
try{if(oEvent instanceof MouseEvent)return true;}catch(x){}
try{if(oEvent instanceof KeyEvent)return true;}catch(x){}
try{if(('cancelBubble'in oEvent||'preventBubble'in oEvent)&&'type'in oEvent)return true;}catch(x){}
return false;})(oEvent);if(!isRealEvent){try{if(typeof oEvent._extends=='undefined'){oEvent._extends=[];oEvent.stop=function(){this._extends[this._extends.length-1].canceled=true;};}
oEvent._extends.push({type:sEvent,canceled:false});oEvent.type=sEvent;}catch(e){isRealEvent=true;}}
if(isRealEvent)oEvent=jindo.$Event(oEvent);var aArg=[oEvent];for(var i=2,len=arguments.length;i<len;i++)
aArg.push(arguments[i]);if(bHasInlineHandler)inlineHandler.apply(this,aArg);if(bHasHandlerList)
for(var i=0,handler;handler=handlerList[i];i++)
handler.apply(this,aArg);if(isRealEvent)return!oEvent.canceled;var oPopedEvent=oEvent._extends.pop();return!oPopedEvent.canceled;},attach:function(sEvent,fHandler){if(arguments.length==1){jindo.$H(arguments[0]).forEach(jindo.$Fn(function(fHandler,sEvent){this.attach(sEvent,fHandler);},this).bind());return this;}
var handlers=this._eventHandlers[sEvent];if(typeof handlers=='undefined')
handlers=this._eventHandlers[sEvent]=[];handlers.push(fHandler);return this;},detach:function(sEvent,fHandler){if(arguments.length==1){jindo.$H(arguments[0]).forEach($Fn(function(fHandler,sEvent){this.detach(sEvent,fHandler);},this).bind());return this;}
var handlers=this._eventHandlers[sEvent];if(typeof handlers=='undefined')return this;for(var i=0,handler;handler=handlers[i];i++){if(handler===fHandler){handlers=handlers.splice(i,1);break;}}
return this;},detachAll:function(sEvent){var handlers=this._eventHandlers;if(arguments.length){if(typeof handlers[sEvent]=='undefined')return this;delete handlers[sEvent];return this;}
for(var o in handlers){delete handlers[o];}
return this;}});nhn.Component.factory=function(aObject,oOption){var aReturn=[];if(typeof oOption=="undefined")oOption={};for(var i=0;i<aObject.length;i++){try{oInstance=new this(aObject[i],oOption);aReturn[aReturn.length]=oInstance;}catch(e){}}
return aReturn;};nhn.HTMLComponent=jindo.$Class({tagName:"",$init:function(){return;}}).extend(nhn.Component);nhn.HTMLComponent.paint=function(){var ins=this._instances;if(typeof ins=="undefined")return;for(var i=0;i<ins.length;i++){if(ins[i]&&ins[i].paint)ins[i].paint();}};nhn.HTMLComponent.factory=function(aObject,oOption){if(typeof aObject=="string"){var sClassName=aObject;if(/^(\w+)\s*(?:\[(\w+)\s*=\s*(\w+)\])?$/.test(this.prototype.tagName)){var a=[];aObject=document.getElementsByTagName(RegExp.$1);if(RegExp.$2&&RegExp.$3){for(var i=0;i<aObject.length;i++){if(aObject[i].getAttribute(RegExp.$2)==RegExp.$3)a[a.length]=aObject[i];}
aObject=a;}
if(sClassName){var regex=new RegExp("\\b"+sClassName+"\\b","i");for(var i=0,a=[];i<aObject.length;i++){if(regex.test(aObject[i].className)){a[a.length]=aObject[i];}}
aObject=a;}}else{return[];}}
this._tmpFactory=nhn.Component.factory;var aObject=this._tmpFactory(aObject,oOption);delete this._tmpFactory;return aObject;};
nhn.CheckBox=jindo.$Class({tagName:'input[type=checkbox]',_bChecked:false,$init:function(el,oOptions){this.option({classPrefix:'checkbox-'});this.option(oOptions||{});this._elWrapper=jindo.$(el);this._welWrapper=jindo.$Element(el);this._assignHTMLElements();this._attachEvent();this.paint();},_assignHTMLElements:function(){var elWrapper=this._elWrapper;var welWrapper=this._welWrapper;this._elInput=cssquery.getSingle('input',elWrapper);this._elLabel=cssquery.getSingle('label[for='+this._elInput.id+']');this._bChecked=this._elInput._bChecked;if(this._elInput.type=="radio"){this.option("classPrefix","radio-");this.tagName="input[type=radio]";}
var sPrefix=this.option('classPrefix');this._elSubstitute=cssquery.getSingle(sPrefix+'mark',elWrapper)||cssquery.getSingle('span',elWrapper)||elWrapper;if(welWrapper.hasClass(sPrefix+'applied'))return;welWrapper.addClass(sPrefix+'applied');},getInput:function(){return this._elInput;},getChecked:function(){return this.getInput().checked;},setChecked:function(b){this.getInput().checked=b;this.paint();return this;},enable:function(){this.getInput().disabled=false;this.paint();return this;},disable:function(){this.getInput().disabled=true;this.paint();return this;},_attachEvent:function(){var sPrefix=this.option('classPrefix');var elWrapper=this._elWrapper;var elInput=this._elInput;var bIE=jindo.$Agent().navigator().ie;if(this._elLabel){jindo.$Fn(function(e){e.stop(jindo.$Event.CANCEL_DEFAULT);jindo.$Element(elWrapper).fireEvent("click");},this).attach(this._elLabel,'click');}
jindo.$Fn(function(e){if(elInput.disabled)return;if(!this.fireEvent("beforeChange",{checked:elInput.checked})){return;}
if(e.element!==elInput)
elInput.checked=elInput.type=='checkbox'?!elInput.checked:true;if(bIE)return;elInput.type=='checkbox'?this.paint():this.constructor.paint();},this).attach(elWrapper,'click');jindo.$Fn(function(e){setTimeout(function(){try{elWrapper.focus();}catch(e){}},1);},this).attach(elWrapper,'mousedown');jindo.$Fn(function(e){this._welWrapper.addClass(sPrefix+'focused');},this).attach(elInput,'focus');jindo.$Fn(function(e){this._welWrapper.removeClass(sPrefix+'focused');},this).attach(elInput,'blur');if(bIE)jindo.$Fn(function(e){this.paint();},this).attach(elInput,'propertychange');},paint:function(){var sPrefix=this.option('classPrefix');var elInput=this.getInput();this._welWrapper.removeClass(sPrefix+'disabled');if(elInput.disabled){this._welWrapper.addClass(sPrefix+'disabled');}
if(elInput.checked==this._bChecked){return;}
this._bChecked=elInput.checked;jindo.$Element(this._elSubstitute).removeClass(sPrefix+'checked');if(elInput.checked){jindo.$Element(this._elSubstitute).addClass(sPrefix+'checked');}
this.fireEvent("change",{checked:elInput.checked})}}).extend(nhn.HTMLComponent);