(function(G){var C="thumbnailRadioCheckbox",E="radio-checkbox-thumbnail-container",D="radio-checkbox-thumbnail",A="selected",F="disabled";var H={thumbnailClass:"",preselect:null,select:null,unselect:null};var B={init:function(K){var J=this;if(typeof K==="object"){J.settings=G.extend({},H,K)}J.each(function(){var L=G(this);L.hide();G("<div></div>").addClass(E).addClass(function(){return(L.attr("type")=="radio")?I.apply(L):""}).insertBefore(L).append(G("<div></div>").attr("id",(L.attr("id")?"thumbnail-"+L.attr("id"):"")).addClass(D+" "+J.settings.thumbnailClass).addClass(function(){return(L.attr("type")=="radio")?"has-hover":"no-hover"}).bind("mousedown."+C,function(){return(typeof J.settings.preselect==="function")?J.settings.preselect(G("img",this),L):true}).bind("click."+C,function(){if(G(this).hasClass(F)||(L.attr("type")=="radio"&&G(this).hasClass(A))){return }if(L.attr("type")=="checkbox"){G(this).toggleClass(A);if(G(this).hasClass(A)){L.attr("checked","checked");if(typeof J.settings.select==="function"){J.settings.select(G("img",this),L)}}else{L.removeAttr("checked");if(typeof J.settings.unselect==="function"){J.settings.unselect(G("img",this),L)}}}else{L.attr("checked","checked");G("."+E+"."+I.apply(L)+" > div."+A).removeClass(A);G(this).addClass(A);if(typeof J.settings.unselect==="function"){J.settings.unselect(G("img",this),L)}if(typeof J.settings.select==="function"){J.settings.select(G("img",this),L)}}}).append(G("<img />").attr({src:L.attr("data-thumbnail"),alt:L.next("label").text(),title:""}).css({width:(L.attr("data-thumbnail-width"))?L.attr("data-thumbnail-width")+"px":"auto",height:(L.attr("data-thumbnail-height"))?L.attr("data-thumbnail-height")+"px":"auto"})).append(L.nextAll(".radio-checkbox-inside-thumbnail"))).append(L.removeAttr("data-thumbnail").removeAttr("data-thumbnail-width").removeAttr("data-thumbnail-height"),L.nextAll());if(L.is(":checked")){L.prev().addClass(A);if(typeof J.settings.select==="function"){J.settings.select(G("img",L.prev()),L)}}if(L.is(":disabled")){L.prev().addClass(F)}});return this},enable:function(J,K){J.each(function(){var L=G(this);if(K){L.prev().removeClass(F);L.removeAttr("disabled")}else{L.prev().addClass(F);L.attr("disabled","disabled")}});return this},check:function(J,M){var L=J.prev();var K=G("img",L);if(!M){L.removeClass(A);J.removeAttr("checked");if(typeof this.settings.unselect==="function"){this.settings.unselect(K,J)}}else{if(J.attr("type")=="radio"){G("."+E+"."+I.apply(J)+" > div."+A).removeClass(A);if(typeof this.settings.unselect==="function"){this.settings.unselect(K,J)}}L.addClass(A);J.attr("checked","checked");if(typeof this.settings.select==="function"){this.settings.select(K,J)}}return this},option:function(){if(arguments.length>=2){this.settings[arguments[0]]=arguments[1];return this}else{if(arguments.length===1){return this.settings[arguments[0]]}}return this}};function I(){return"radio-checkbox-"+this.attr("name").replace(/\[|\]/g,"")}G.fn.thumbnailRadioCheckbox=function(){var J=arguments[0];this.settings=this.settings||H;if(B[J]){return B[J].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof J==="object"||!J){return B.init.apply(this,arguments)}else{G.error("Method "+J+" does not exist.")}}}})(jQuery);