if ($ !== undefined || jQuery !== undefined) {

    if (typeof(BART) == 'undefined'){
        BART = {};
        BART.Front = {};
    };

    BART.Front.Mod_Poll = function () {       
        return {
             animate_results: function (opt_voted) {
                  $(".bar").each(function(){
                      var bar   = $(this).find('.bar_line');
                      var perc  = $(this).find('.bar_perc').text();
                      
                      bar.css({width: "0%"}).animate({width: jQuery.trim(perc)}, 'slow','linear',function(){
                        var option_val = bar.attr('id');
                        option_val = jQuery.trim(option_val.replace('bar',''));

                        if(opt_voted === option_val){
                            bar.removeClass('def_bar_color').addClass('vote_bar_color');
                        };
                      });
                  });
            },
             set_poll: function(){
                 var poll_option = $("input[name='poll_option']:checked").val();
				 var sec_code    = $("input[name='sec_code']").val();
				 var description = $("#description").val();
				
				 if (description == '' && sec_code !== '') {
				 	$.post('index.php?id=' + BART.Front.Mod_Poll.page_id + '&pi=' + BART.Front.Mod_Poll.panel_id + '&action=set_poll&pida=yes&smarty=yes', {
				 		poll_option: poll_option,
				 		sec_code: sec_code
				 	}, function(data){
				 		if (data.success) {
				 			$.post('index.php?id=' + BART.Front.Mod_Poll.page_id + '&pi=' + BART.Front.Mod_Poll.panel_id + '&pida=yes&smarty=yes', {
				 				html_result: true
				 			}, function(data){
				 				$('#poll_container' + BART.Front.Mod_Poll.panel_id + ' .poll_container_content').html(data);
				 				BART.Front.Mod_Poll.animate_results(poll_option);
				 			}, "html");
				 		}
				 		else {
				 			$('#poll_container' + BART.Front.Mod_Poll.panel_id).html('Er is iets fout gegaan tijdens het stemmen.');
				 		}
				 	}, "json");
				 }
             }
        };
    }();
}
