!function ($) {

    $('.rad-icon-param-container').each(function () {

        var $list = $(this),
        $input = $list.find('input'),
        $icons = $list.find('.rad-icon-param'),
        $selected = $(),
        $inputval = $input.val();
       
        if ($inputval.length !== 0) {
            var val = $inputval.split(":"),
                name = val[0],
                type = val[1];
            $selected = $list.find("span[data-name=" + name + "][data-type=" + type + "]").addClass('selected');
        }
        //Scroll iconContainer to show the selected icon
        setTimeout(function(){
            if($selected.length)
            {
                var $offset = $selected.offset().top - $list.offset().top;
                if($offset >0)
                {
                    $list.stop().animate({
                        scrollTop: $offset + "px"
                    }, 10); 
                }        
            }
        },600)


        $icons.click(function () {
            if($(this).hasClass('selected'))
            {
                $(this).removeClass('selected');
                $input.val('');
            }
            else
            {
                $input.val($(this).attr('data-name') + ':'+ $(this).attr('data-type'));
                $icons.removeClass('selected');
                $(this).addClass('selected');
            }
            $input.trigger( "change" );
        });

    });


}(window.jQuery);