/**
 * zudolab AllCheck
 *
 * @version    1
 * @copyright    (c)2008 Takeshi Takatsudo (http://zudolab.net/)
 * @license    MIT (http://www.opensource.org/licenses/mit-license.php)
 */
(function(a){AllCheck=function(c){this.multiple=c.multiple?true:false;this.selector_container=c.container?c.container:null;this.selector_all=c.all?c.all:null;this.selector_children=c.children?c.children:null;this.elemSets=[];var b=this;a(function(){b.setup()})};AllCheck.prototype.setup=function(){var b=this;a(function(){b.prepareSets();if(!b.elemSets){return}b.setEvents()})};AllCheck.prototype.prepareSets=function(){var b=this;if(b.multiple){d()}else{c()}function c(){var f=a(b.selector_all).eq(0);if(!f.length){return}var e=a(b.selector_children);b.elemSets.push({all:f.get(0),children:e})}function d(){a(b.selector_container).each(function(){var e=a(this);b.elemSets.push({all:e.find(b.selector_all).eq(0).get(0),children:e.find(b.selector_children)})})}};AllCheck.prototype.setEvents=function(){var b=this;for(var f=0,e;e=this.elemSets[f];f++){a(e.all).click(h);for(var c=0,g;g=e.children[c];c++){a(g).click(d)}}function h(){var i=b.getElemSetFromAllChecker(this);if(this.checked){b.checkAll(i.children)}else{b.uncheckAll(i.children)}}function d(){var i=b.getElemSetFromChildrenCheck(this);if(b.areAllChecked(i.children)){i.all.checked=true}else{i.all.checked=false}}};AllCheck.prototype.areAllChecked=function(d){for(var b=0,c;c=d[b];b++){if(!c.checked){return false}}return true};AllCheck.prototype.uncheckAll=function(d){for(var b=0,c;c=d[b];b++){c.checked=false}};AllCheck.prototype.checkAll=function(d){for(var b=0,c;c=d[b];b++){c.checked=true}};AllCheck.prototype.getElemSetFromAllChecker=function(c){for(var b=0,d;d=this.elemSets[b];b++){if(d.all==c){return d}}};AllCheck.prototype.getElemSetFromChildrenCheck=function(e){for(var c=0,f;f=this.elemSets[c];c++){for(var b=0,d;d=f.children[b];b++){if(d==e){return f}}}}})(jQuery);