/*
	 Created by Samir Chaves
   Git Repo https://github.com/samirbraga/Double-Option-Button---JQuery-Plugin/edit/master/README.md
*/
$.fn.dblOption = function(opts){
	var self = $(this);

  $.fn.dblOption.options = $.extend({}, $.fn.dblOption.defaults, opts);
  opts = $.fn.dblOption.options;

  self.addClass('dbl-option-container ' + opts['initSide']);

  if (opts['callOnInit'] == true) {
    if (opts['initSide'] == 'right') {
			opts['onRight']();
    } else {
			opts['onLeft']();
    }
  }

  self.css({
  	width: opts['width'] || '220px',
  	height: opts['height'] || '30px',
  	lineHeight: opts['height'] || '30px'
  });

  var template = [
  '<div class="labels labels-back">',
    '<div class="label label-left">',
      '<span></span>',
    '</div>',
    '<div class="label label-right">',
      '<span>RENTTALLER</span>',
    '</div>',
  '</div>',
  '<div class="labels labels-front">',
    '<div class="labels-ranger">',
      '<div class="label label-left">',
       ' <span>RENTTER</span>',
      '</div>',
      '<div class="label label-right">',
        '<span>RENTTALLER</span>',
      '</div>',
    '</div>',
  '</div>'].join('');

  self.append(template);

  self.find('.labels .label').css('width', parseFloat(opts['width'])/2 + 'px');
  self.find('.labels-ranger').css('background', opts['bgSelector']);

  if (opts['animation'] == true) {
  	self.find('.labels-ranger').addClass('animated');
    self.find('.labels-front').addClass('animated');
  }

  self.mousedown(function(e){
    e.preventDefault();
    return false;
  })

  self.find('.label-right span').text(opts['rightLabel']);
  self.find('.label-left span').text(opts['leftLabel']);

  var toggleOption = function(e){
    e.preventDefault();

    var label = $(this);

    if (label.hasClass('label-right')) {
      self.setSide('right');
    } else {
      self.setSide('left');
    }
    return false;
  }

  self.find('.labels-back .label').click(toggleOption);
}

$.fn.dblOption.defaults = {
  width: '200px',
  height: '30px',
  initSide: 'left',
  leftLabel: 'OPÇÃO 1',
  rightLabel: 'OPÇÃO 2',
  callOnInit: true,
  bgSelector: '#363b44',
  animation: true,
  onChange: function () {
  },
  onRight: function () {
    console.log('right');
  },
  onLeft: function () {
    console.log('left');
  }
}

$.fn.setSide = function(side){
	var self = $(this);

  if (self.hasClass('dbl-option-container') && !!side) {
  	$.fn.dblOption.options['onChange']()

  	side = side.toLowerCase();
  	self.removeClass('right left');
  	self.addClass(side);
    if (side == 'right') {
    	$.fn.dblOption.options['onRight']()
    } else {
    	$.fn.dblOption.options['onLeft']();
    }
  }
}

@@ -126,16 +126,17 @@
 E.md%0A*/%0A
+%0A
 $.fn.dbl
@@ -429,42 +429,129 @@
 ) %7B%0A
-%09%09%09opts%5B'onRight'%5D();%0A    %7D else %7B
+    %09$.fn.dblOption.options.side = 'right';%0A%09%09%09opts%5B'onRight'%5D();%0A    %7D else %7B%0A    %09$.fn.dblOption.options.side = 'left';
 %0A%09%09%09
@@ -709,17 +709,16 @@
 px'%0A  %7D)
-;
 %0A%0A  var 
@@ -1336,17 +1336,16 @@
  + 'px')
-;
 %0A  self.
@@ -1404,18 +1404,16 @@
 ector'%5D)
-;%0A
 %0A  if (o
@@ -1825,24 +1825,83 @@
 l = $(this);
+%0A    var option = $(this).closest('.dbl-option-container');
 %0A%0A    if (la
@@ -2542,48 +2542,8 @@
 e) %7B
-%0A  %09$.fn.dblOption.options%5B'onChange'%5D()
 %0A%0A  
@@ -2656,106 +2656,380 @@
 ght'
-) %7B%0A    %09$.fn.dblOption.options%5B'onRight'%5D()%0A    %7D else %7B%0A    %09$.fn.dblOption.options%5B'onLeft'%5D();
+ && $.fn.dblOption.options.side != 'right') %7B%0A    %09$.fn.dblOption.options.side = 'right';%0A    %09$.fn.dblOption.options%5B'onRight'%5D()%0A  %09%09$.fn.dblOption.options%5B'onChange'%5D()%0A    %7D else if (side == 'left' && $.fn.dblOption.options.side != 'left') %7B%0A    %09$.fn.dblOption.options.side = 'left';%0A    %09$.fn.dblOption.options%5B'onLeft'%5D();%0A      $.fn.dblOption.options%5B'onChange'%5D()
 %0A   

Fix bugs