(function() { 

  astroloskiCentar.activate_runners = function() {
    var template = astroloskiCentar.templates[astroloskiCentar.controller][astroloskiCentar.action];
    var blocks = template.blocks;
    var mixins = template.mixins;
    for(var i = 0; i < blocks.length; i++) {
      astroloskiCentar.runners.blocks[blocks[i]](); 
    };
    for(var i = 0; i < mixins.length; i++) {
      astroloskiCentar.runners.mixins[mixins[i]](); 
    };
  };

})();
// This lib implements Omniture tracking. Just usual wrapper around iv_doTracking.
(function() { 

  astroloskiCentar.tracking = function(tracking_code) {
    iv_doTracking(tracking_code, '', 's_iv.eVar13');
  };

})();


String.prototype.capitalize = function() {
  return this.slice(0,1).toUpperCase() + this.slice(1);
};

String.prototype.escape_html = function() {
  this.replace(/&/g, '&amp;'); 
  this.replace(/"/g, '&quot;'); 
  this.replace(/>/g, '&gt;'); 
  this.replace(/</g, '&lt;'); 
  return this;
};

Array.prototype.remove = function(value) {
  var new_array = []; 
  for(var i = 0; i < this.length; i++) {
    if(this[i] != value) {
      new_array.push(this[i]);
    };
  };
  return new_array;
};

(function() {

  astroloskiCentar.templates = {

    home: {
      index: {
        blocks: [ 'popup_birthdate_changer', 'wheel' ],
        mixins: [  ]
      }
    }
  };

})();


(function($) {
  
  var classes = {
    self: 'm-tooltip',
    target: 'm-tooltip_target',
    source: 'm-tooltip_source'
  };
  
  $.fn.m_tooltip = function(options) {
    var opts = $.extend({}, $.fn.m_tooltip.defaults, options);
    return this.each(function() {
      var self = $(this);
      var target = self.find('.' + classes.target);
      var source = self.find('.' + classes.source);
      var tooltip = $("<div class='m-tooltip_popup'></div>");
      $('body').append(tooltip);
      target.mouseover(function(e) {
        tooltip.html(source.html());
        tooltip.css({left: e.pageX + opts.left_offset + 'px', top: e.pageY + opts.top_offset + 'px'});
        tooltip.show();
      });
      target.mousemove(function(e) {
        tooltip.css({left: e.pageX + opts.left_offset + 'px', top: e.pageY + opts.top_offset + 'px'});
      });
      target.mouseout(function() {
        tooltip.hide();
      });
    });
  };

  $.fn.m_tooltip.defaults = {
    top_offset: 20,
    left_offset: 20
  };

})(jQuery);

// This lib adds omniture tracking function to jQuery namespace. There are 2 methods
// jQuery.m_tracking
// jQuery.fn.m_tracking
// 
// First one is used in other JS scripts, e.g. when we need to track moving of slider.
// Second one is used for tracking clicks not in JS, applying to different blocks.
;astroloskiCentar.runners.mixins.tracking = function() {
  jQuery('.m-tracking').m_tracking();
};

(function($) {
  
  var classes = {
    self: 'm-tracking',
    target: 'm-tracking_target',
    code: 'm-tracking_code'
  };
  
  // Tries to find tracking code within given block
  // and send it to Omniture tracking function.
  $.m_tracking = function(block, text) {
    text = text || block.find('.' + classes.code).text(); 
    if(text) { astroloskiCentar.tracking(text) };
  };


  $.fn.m_tracking = function() {
    return this.each(function() {
      var self = $(this);
      var text = self.find('.' + classes.code).text(); 
      var target = self.find('.' + classes.target);
      target.click(function() {
        if(text) { astroloskiCentar.tracking(text) };
        return true;
      });
    });
  };

})(jQuery);



// Allows to add validators to form elements. 
//
// * m-validations class should be assigned to form.
// * m-validations_element (several types, see below), m-validations_validate_your-validator-type 
//   should be assigned to div containing validated element.
//   For allowable your-validator-type values, check 'validations' variable below
// * m-validations_error (optional), it should contain error you want to show if element is invalid
// * m-validations_border (optional), it may be assigned to div you want to have red border if element is invalid
//
// m-validations_element can be m-validations_element_on-submit and m-validations_element_all
// (validation will be run only after submitting the form or after submitting and blur)
//
// == Example
// - form_tag("#", :class => "m-validations") do
//   .m-validations_element_on-submit.m-validations_validate_not-empty
//     .m-validations_border
//       %em.m-validations_error This field should be filled
//       = text_field_tag(:name, "John")
;astroloskiCentar.runners.mixins.validations = function() {
  jQuery('.m-validations_inner').m_validations({error_type: 'inner'});
  jQuery('.m-validations_notice').m_validations({error_type: 'notice'});
};

(function($) {
  
  var classes = {
    self: 'm-validations',
    element_on_submit: 'm-validations_element_on-submit',
    element_all: 'm-validations_element_all',
    validate: 'm-validations_validate',
    border: 'm-validations_border',
    invalid_border: 'm-validations_invalid-border',
    correct_country: 'm-validations_correct-country',
    correct_country_field: 'm-validations_correct-country_field',
    error: 'm-validations_error',
    error_country: 'm-validations_error_correct-country',
    spinner: 'm-validations_spinner'
  };
  
  $.fn.m_validations = function(options) {
    var opts = $.extend({}, $.fn.m_validations.defaults, options);
    return this.each(function() {
      var self = $(this);
      self.submit(function() { 
        // Catch error with element to focus.
        try {
          validate_all(self, opts); 
          return true;
        } catch(element) {
          element.find(':input').focus();
          return false;
        };
      });
      self.find('.' + classes.element_all + ' :input').blur(function() { 
        return validate_this(self, opts, $(this).closest('.' + classes.element_all)); 
      });
    });
  };


  // Add your validation rules to here:
  var validations = {
    'not-empty': function(self, opts, element) {
      var input = element.find(':input:eq(0)');
      var match = true;
      input.each(function() { 
        if(!this.disabled) {
          match = match && $(this).val() != ""; 
        };
      });
      return validate_element(self, opts, element, match);
    },

    'not-empty_if-us': function(self, opts, element) {
      var input = element.find(':input:eq(0)');
      var num = input.attr("name").match(/.*(\d+)$/);
      num = (num ? num[1] : 1);
      if(self.find("#country" + num).val() == "US") { 
        var match = true;
        input.each(function() { 
          if(!this.disabled) {
            match = match && $(this).val() != ""; 
          };
        });
        return validate_element(self, opts, element, match);
      } else {
        return validate_element(self, opts, element, true);
      }
    },

    'correct-email': function(self, opts, element) {
      var input = element.find(':input:eq(0)');
      // This huge regexp is taken from http://xyfer.blogspot.com/2005/01/javascript-regexp-email-validator.html
      var reg_exp = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
      var match = true;
      input.each(function() { 
        if(!this.disabled) {
          match = match && $(this).val().match(reg_exp);
        };
      });
      return validate_element(self, opts, element, match);
    },

    'correct-date': function(self, opts, element) {
      if(element.find(':disabled').size() == 0) {
        var input = element.find(':input');
        var day;
        var month;
        var year;
        var match;
        input.each(function() {
          var that = $(this);
          var name = that.attr('name');
          if(name.match(/_day/)) { day = that.val(); }
          else if(name.match(/_month/)) { month = that.val() - 1; }
          else if(name.match(/_year/)) { year = that.val(); };
        });
        try {
          var date = new Date(year, month, day);
          match = (date.getFullYear() == year && date.getMonth() == month && date.getDate() == day);
        } catch(exception) {
          match = false;
        };
        return validate_element(self, opts, element, match);
      } else {
        return true;
      }
    },

    'correct-time': function(self, opts, element) {
      if(element.find(':disabled').size() == 0) {
        var input = element.find(':input');
        var hour;
        var minute;
        input.each(function() {
          var that = $(this);
          var name = that.attr('name');
          if(name.match(/_hour/)) { hour = that.val(); }
          else if(name.match(/_minute/)) { minute = that.val(); }
        });
        try {
          var time = new Date(1970, 1, 1, hour, minute);
          match = (time.getHours() == hour && time.getMinutes() == minute);
        } catch(exception) {
          match = false;
        };
        return validate_element(self, opts, element, match);
      } else {
        return true;
      };
    },

    'correct-time_ampm': function(self, opts, element) {
      if(element.find(':disabled').size() == 0) {
        var input = element.find(':input');
        var hour;
        var minute;
        var ampm;
        input.each(function() {
          var that = $(this);
          var name = that.attr('name');
          if(name.match(/_hour/)) { hour = parseInt(that.val()); }
          else if(name.match(/_minute/)) { minute = parseInt(that.val()); }
          else if(name.match(/_ampm/)) { ampm = that.val(); }
        });
        try {
          if(ampm == 'pm') { hour += 12 };
          if(hour == 24) { hour = 0; };
          var time = new Date(1970, 1, 1, hour, minute);
          match = (time.getHours() == hour && time.getMinutes() == minute);
        } catch(exception) {
          match = false;
        };
        return validate_element(self, opts, element, match);
      } else {
        return true;
      };
    },



    // This validation is more complex than other validations. It requres some
    // additional markup and special divs for error and additional select box.
    //
    // == Example ==
    // .m-validations_element_on-submit.m-validations_validate_correct-country
    //   .m-validations_error_correct-country (error messages will be shown here)
    //   .m-validations_correct-country (additional select box will be shown here)
    //   / Here should be city, state and country inputs, maybe with other validations
    //   = hidden_field_tag(:latitude1, "", :class => "latitude")
    //   = hidden_field_tag(:longitude1, "", :class => "longitude")
    //
    'correct-country': function(self, opts, element) {
      if(element.find(':disabled').size() == 0) {
        var self = element.closest('.' + classes.self);
        var spinner = self.find('.' + classes.spinner);
        var city = element.find(".city");
        var state = element.find(".state");
        var country = element.find(".country");
        var error = element.find("." + classes.error_country);
        var correct_country = element.find("." + classes.correct_country);
        var correct_country_field = correct_country.find("." + classes.correct_country_field);
        var result;
        if(city.val() != "" && country.val() != "") {
          if(element.data("city") == city.val() && element.data("state") == state.val() && element.data("country") == country.val()) {
            // User already selected his birthplace from many variants
            result = true;
          } else {
            // Disable many countries selector if user changes his mind and select new country
            correct_country.hide();
            correct_country_field.empty();
            error.empty();
            spinner.show();
            // User sends AJAX Atlas request at first time
            $.ajax({
              type: "GET",
              url: "/products/atlas.js", 
              data: { city: city.val(), state: state.val(), country: country.val() }, 
              dataType: 'json',
              async: false,
              success: function(json) {
                if(json.status == "0") {
                  if(!json.data) {
                    result = false;
                    show_error(self, opts, "Please select another city/country, nearest to you");
                  } else {
                    switch(json.data.length) {
                      case 1:
                        element.find('.place_id').val(json.data[0].place_id);
                        element.find('.latitude_str').val(json.data[0].latitude_str);
                        element.find('.longitude_str').val(json.data[0].longitude_str);
                        element.find('.latitude_dec').val(json.data[0].latitude_dec);
                        element.find('.longitude_dec').val(json.data[0].longitude_dec);
                        element.find('.timezone').val(json.data[0].timezone);
                        result = true;
                        break;
                      default:
                        element.data('city', city.val());
                        element.data('state', state.val());
                        element.data('country', country.val());
                        var number = city.attr("id").match(/[a-zA-Z](\d+)/)[1];
                        var select_new_place = $("<select name='accurate_place" + number + "'></select>");
                        correct_country_field.append(select_new_place);
                        var have_other_locations;
                        for(var i = 0; i < json.data.length; i++) {
                          var text = json.data[i].city;
                          if(json.data[i].county) { text += " (" + json.data[i].county + ")"; };
                          if(json.data[i].state) { text += ", " + json.data[i].state; };
                          text += ", " + json.data[i].country;

                          // value of select box = "place_id;city;state;county;country;latitude;longitude"
                          var value = [ json.data[i].city ];
                          value.push(json.data[i].place_id);
                          value.push(json.data[i].state);
                          value.push(json.data[i].county);
                          value.push(json.data[i].country);
                          value.push(json.data[i].latitude_str);
                          value.push(json.data[i].longitude_str);
                          value.push(json.data[i].latitude_dec);
                          value.push(json.data[i].longitude_dec);
                          value.push(json.data[i].timezone);

                          have_other_locations = true;
                          select_new_place.append('<option value="' + value.join(";") + '">' + text + '</option>');
                        };
                        if(have_other_locations) {
                          show_error(self, opts, "Multiple locations match what you entered. Please select one or enter a more exact city name.");
                        };
                        correct_country.show();
                        result = false;
                        break;
                    };      
                  };
                } else {
                  alert("There was some server error while checking your birthplace");
                };
                spinner.hide();
              }
            });
          };
        };
        return result;
      };
    }
  };


  function validate_all(self, opts) {
    var elements = self.find('.' + classes.element_all + ', .' + classes.element_on_submit);
    var overall_result = true;
    var error_element;
    elements.each(function() { 
      element_result = validate_this(self, opts, $(this));
      overall_result = overall_result && element_result; 
      if(!error_element && !element_result) { error_element = $(this); }; 
    });
    if(error_element) { throw(error_element); };
    return overall_result;
  };
  

  function validate_this(self, opts, element) {
    var reg_exp = new RegExp(classes.validate + '_([a-zA-Z0-9_\\-]+)');
    var element_classes = element.attr('class').split(" ");
    var result = true;
    $.each(element_classes, function() {
      var type_of_validation = this.match(reg_exp); 
      if(type_of_validation) {
        result = result && validations[type_of_validation[1]](self, opts, element);
      };
    });
    return result;
  };


  function validate_element(self, opts, element, valid_condition) {
    var border = element.find('.' + classes.border);
    if(valid_condition) {
      border.removeClass(classes.invalid_border);
      hide_error(self, opts, element);
      return true;
    } else {
      border.addClass(classes.invalid_border);
      show_error(self, opts, element);
      return false;
    };
  };


  function show_error(self, opts, element) {
    if(opts.error_type == 'inner') {
      var error = element.find('.' + classes.error);
      error.show();
    } else {
      if(typeof element == "string") {
        var text = element;
      } else {
        var error = element.find('.' + classes.error);
        var text = error.text();
      }
      $.notice_add({ text: text, type: 'error', stay: true });
    };
  };

  function hide_error(self, opts, element) {
    var error = element.find('.' + classes.error);
    if(opts.error_type == 'inner') {
      error.hide();
    };
  };



  $.fn.m_validations.defaults = {
    error_type: 'inner'
  };



})(jQuery);


(function($) {
  
  var classes = {
    close_text: 'b-popup-birthdate-changer_close-text',
    close_sign: 'b-popup-birthdate-changer_close-sign'
  };

  $.fn.b_popup_birthdate_changer = function(options) {
    return this.each(function() {
      var self = $(this);
      init(self, options);
    });
  };


  function init(self, options) {
    options.opener.click(function() { self.parent().show(); return false; });
    self.find("." + classes.close_sign).click(function() { self.parent().hide(); return false; });
    self.find("." + classes.close_text).click(function() { self.parent().hide(); return false; });
    
  };

})(jQuery);


//Popup window for changing user's birthdate or looking at friend's birthdate (p.91 of F.Spec)
//You have to pass 'opener' to b_popup_birthdate_changer (jQuery object, the parent container 
//of the b-popup-birthdate-changer block, if user clicks on them, the window will be opened).
;astroloskiCentar.runners.blocks.popup_birthdate_changer = function() {
var kaleidoscope = jQuery('#b-wheel');
kaleidoscope.find('.b-popup-birthdate-changer').b_popup_birthdate_changer({
 opener: kaleidoscope.find('.b-wheel_date-container')  
});

var hero_numerology = jQuery('#b-hero');
hero_numerology.find('.b-popup-birthdate-changer').b_popup_birthdate_changer({
 opener: hero_numerology.find('.b-hero_birthdate_edit')  
});
};


// Description of the block. Please, show example of HTML of the block here
;astroloskiCentar.runners.blocks.wheel = function() {
  jQuery('#b-wheel').b_wheel();
};

(function($) {
  
  var classes = {
    self: 'b-wheel',
    wheel: 'b-wheel_wheel',
    date_container: 'b-wheel_date-container',
    date_tooltip: 'b-wheel_date-container_tooltip',
    tooltip: 'b-wheel_tooltip',
    birthday_change: 'b-wheel_birthday-change',
    label: 'b-wheel_label'
  };

  var distances = [
    [360,60,120,180,240,300],	//horoskopski znak
    [300,360,60,120,180,240],	//ljubav
    [240,300,360,60,120,180],  	//novac -> ps 180-120 = 60
    [180,240,300,360,60,120], 	//kineski znak
    [120,180,240,300,360,60], 	//dom -> ps 180-120 = 60
    [60,120,180,240,300,360]  	//godina
  ];


  var coordinates = [
     	[ 35, 115, 100, 80 ], 	//kineski znak
     	[ 84, 178, 110, 110 ],  //dom
        [ 170, 175, 110, 110 ],  //godina
        [ 212, 120, 100, 80 ],	//horoskopski znak
        [ 160, 20, 110, 110 ], 	//ljubav
        [ 78, 34, 100, 80 ]  	//novac
	];
  
  $.fn.b_wheel = function(options) {
    var opts = $.extend({}, $.fn.b_wheel.defaults, options);
    return this.each(function() {
      var self = $(this);
      init_variables(self, opts);
      init_wheel(self);
      init_birthday_changing(self);
      init_random_spinning(self, self.data("wheel"));
      set_index(self, self.data("wheel"), 0);
    });
  };

    function init_variables(self, opts) {
        self.data("is_wheel_running", false);
        self.data("current_rotation", null);
        self.data("selected_index", 0);
        self.data("selected_sign", 0);
        self.data("wheel", {});
        self.data("western_sign", self.parent().parent().find('.b-horoscopes').b_horoscopes_get_western_sign());
        self.data("chinese_sign", self.parent().parent().find('.b-horoscopes').b_horoscopes_get_chinese_sign());
        self.data("wheel_cycles", opts.wheel_cycles);
        var data = [
	        {
	            name: 'daily-overview',
	            image: "zapadni/zapadni_" + self.data("western_sign"),
	            tooltip: "Horoskop"
	          },
	          {
	              name: 'daily-home-and-garden',
	              image: "ostali/ostali_dom",
	              tooltip: "Obiteljski horoskop"
	            },
	            {
	              name: 'yearly-overview',
	              image: "ostali/ostali_godina",
	              //tooltip: "Godišnji horoskop - " + astroloskiCentar.display_year + "."
	              tooltip: "Godišnji horoskop"
	            },
	          {
	            name: 'daily-chinese',
	            image: "kineski/kineski_" + self.data("chinese_sign"),
	            tooltip: "Kineski horoskop"
	          },
	          
	          {
	              name: 'daily-singles',
	              image: "ostali/ostali_ljubav",
	              tooltip: "Ljubavni horoskop"
	            },
	            {
	              name: 'daily-finance',
	              image: "ostali/ostali_novac",
	              tooltip: "Financijski horoskop"
	            }
        ];
        
    
    // If given (by route) sign is chinese sign, then we need to set default state of the wheel to daily-chinese
    // I.e., we need to reorder data array - daily-chinese should be the first element of the array.
    if(astroloskiCentar.selected_signs == 'chinese') {
      for(var i = 0; i <= 2; i++) { 
        var item = data.shift();
        data.push(item);
      };
    };
    if(astroloskiCentar.selected_signs == 'yearly') {
        for(var i = 0; i <= 1; i++) { 
          var item = data.shift();
          data.push(item);
        };
      };
    self.data("wheel_data", data);
  };


  function init_wheel(self) {
    var wheel_dom = self.find("." + classes.wheel).get(0);
    var wheel = {};
    wheel.raphael = Raphael(wheel_dom, 354, 312);
    wheel.image = wheel.raphael.image("/img/zvijezda.png", 0, 0, 354, 312);	
    wheel.selected_icon_bg = init_selected_icon_bg(wheel);
    wheel.icon_set = init_icon_set(self, wheel, self.data("western_sign"), self.data("chinese_sign"));
    wheel.selected_icon_set = init_selected_icon_set(self, wheel, self.data("western_sign"), self.data("chinese_sign"));
    var circle_pointer = wheel.raphael.image("/img/odabir.png", 126, 110, 101, 90);
    
    self.data("wheel", wheel);
  };

  
  function init_random_spinning(self, wheel) {
    var label = self.find('.' + classes.label);
    label.click(function() { 
      var wheel_length = 6;
      var index = Math.round(Math.random() * (wheel_length - 1));
      
      rotate(self, wheel, index, 2000, ">");
      return false;
    });
  };


  function rotate(self, wheel, index, time, easing) {
    wheel.selected_icon_bg.hide();
    wheel.selected_icon_set.hide();
    wheel.icon_set.show();
    var angle = distances[self.data("selected_index")][index];
    if(!self.data("is_wheel_running")) {
      self.data("is_wheel_running", true);
      var angle_with_cycles = angle + self.data("wheel_cycles");
      self.data("current_rotation", wheel.image.rotate());
      
      wheel.image.animate(
        { rotation: [wheel.image.rotate() + angle_with_cycles, 177, 156] },
        time,
        easing,
        function() { finish_animation(self, wheel, index); }
      );
      wheel.icon_set.animate(
        { rotation: [wheel.image.rotate() + angle_with_cycles, 177, 156] }, 
        time, 
        easing
      );				
    };
    wheel.raphael.safari();
    $.m_tracking(self);
  };


  function init_birthday_changing(self) {
    var tooltip = self.find("." + classes.date_tooltip);
    var date_container = self.find("." + classes.date_container);
    date_container.hover(function() { tooltip.fadeIn(); }, function() { tooltip.fadeOut(); });
  };


  function init_selected_icon_bg(wheel) {
    //var selected_icon_bg = wheel.raphael.image("http://localhost/img/selected.png", 18, 103, 165, 115);
    var selected_icon_bg = wheel.raphael.image("/img/selected.png", 18, 103, 165, 115);
    selected_icon_bg.hide();
    return selected_icon_bg;
  };


  function init_icon_set(self, wheel, western_sign, chinese_sign) {
    var icon_set = wheel.raphael.set();
    images = []
    $.each(self.data("wheel_data"), function(index) {
      var coords = coordinates[index];
      images.push(wheel.raphael.image("/img/kotac/" + this['image'] + ".png", coords[0], coords[1], coords[2], coords[3]));
    });
    icon_set.push(images[0], images[1], images[2], images[3], images[4], images[5]);
    var tooltip = $('.' + classes.tooltip);
    $(icon_set).each(function(index) {
      icon_set[index].click(function() {
        rotate(self, wheel, index, 2000, ">");
      });
      icon_set[index].mouseover(function() {
        tooltip.text(self.data("wheel_data")[index]['tooltip']);
        tooltip.show(); 
      });
      icon_set[index].mousemove(function(icon) {
        var left_offset = -120;
        var top_offset = 12;
        var left = (icon.pageX || icon.clientX) + left_offset + 'px';
        var top = (icon.pageY || icon.clientY) + top_offset + 'px';
        tooltip.css({ left: left, top: top });
      });
      icon_set[index].mouseout(function() {
        tooltip.hide(); 
      });
    });
    return icon_set;
  };


  function init_selected_icon_set(self, wheel, western_sign, chinese_sign) {
    var selected_icon_set = wheel.raphael.set();
    images = []
    $.each(self.data("wheel_data"), function() {
      images.push(wheel.raphael.image("/img/kotac/" + this['image'] + "_on.png", 40, 120, 100, 80));
      //images.push(wheel.raphael.image("/img/kotac/" + this['image'] + "_on.png", 212, 120, 100, 80));
    });
    selected_icon_set.push(images[0], images[1], images[2], images[3], images[4], images[5]);
    selected_icon_set.hide();
    return selected_icon_set;
  };


  function finish_animation(self, wheel, index) {	
    set_index(self, wheel, index);
    self.data("is_wheel_running", false);
    change_to_selected_horoscope(self, index);
  };

  function set_index(self, wheel, index) {
    wheel.selected_icon_bg.show();
    wheel.icon_set[index].hide();
    wheel.selected_icon_set[index].show();
    self.data("selected_index", index);
  };

  function change_to_selected_horoscope(self, index) {
    var name = self.data("wheel_data")[index]['name'];
    self.parent().parent().find('.b-horoscopes').b_horoscopes_set_current_horoscope(name); 
  };
 

  $.fn.b_wheel.defaults = {
    // set to 360 * (number of desired rotations)
    wheel_cycles: 360 * 2
  };

})(jQuery);




// Description of the block. Please, show example of HTML of the block here
(function($) {
  
  var classes = {
    self: 'b-horoscopes',
    another_sign: 'b-horoscopes_another-sign',
    chinese_sign: 'b-horoscopes_chinese-sign',
    western_sign: 'b-horoscopes_western-sign',
    big: 'b-horoscopes_big',
    current_sign: 'b-horoscopes_current-sign',
    current_type: 'b-horoscopes_current-type',
    horoscopes: 'horoscopes',
    header: 'b-horoscopes_header',
    sign: 'sign',
    selected_horoscopes: 'selected-horoscopes'
  };
    
  $.fn.b_horoscopes_get_chinese_sign = function() {
    var chinese_horoscopes = this.find('.daily-chinese');
    var selected_sign_dom = chinese_horoscopes.find('.' + classes.sign);
    var sign; 
    if(selected_sign_dom.size() > 0) { 
      sign = selected_sign_dom.attr('class').match(/sign (\w+)/)[1];
      
    };
    return sign;
  };

  $.fn.b_horoscopes_get_western_sign = function() {
    var western_horoscopes = this.find('.daily-overview'); 
    var selected_sign_dom = western_horoscopes.find('.' + classes.sign);
    var sign; 
    if(selected_sign_dom.size() > 0) {
      sign = selected_sign_dom.attr('class').match(/sign (\w+)/)[1];
    };
    return sign;
  };


  $.fn.b_horoscopes_set_current_horoscope = function(name) {
    return this.each(function() {
      var self = $(this);
      self.find('.' + classes.horoscopes).removeClass(classes.selected_horoscopes);
      self.find('.' + name).addClass(classes.selected_horoscopes);
    });
  };
 
})(jQuery);



