/* ------------------------------------------------------------------------
	s3Capcha
	
	Developped By: Boban Karišik -> http://www.serie3.info/
    Icons and css: Mészáros Róbert -> http://www.perspectived.com/
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */

(function ($) {

    jQuery.fn.extend({
        check: function () {
            return this.each(function () { this.checked = true; });
        },
        uncheck: function () {
            return this.each(function () { this.checked = false; });
        }
    });


    $.fn.s3Capcha = function (vars) {
        var i = 0;
        for (i = 0; i < (this.length); i++) {
            var element = this[i];
            var elid = $(element).attr("id");
            var spans = $("#" + elid + " div span");
            var radios = $("#" + elid + " div span input");
            var images = $("#" + elid + " div .img");
            // hide radios //
            spans.css({ 'display': 'none' });
            // show images //
            images.css({ 'display': 'block' });
            
            images.each(function (j) {
                $(images[j]).click(function () {
                    images.css({ 'background-position': 'bottom left' });
                    $(images[j]).css({ 'background-position': 'top left' });
                    $(radios[j]).check();
                    try {
                        $("#capcha_value").val($(radios[j]).val());
                    }
                    catch (ex) {
                    }
                });
            });
        }
    }

})(jQuery);
