var Carousel = new Class({
  Implements: [ Options ],
  options: {
    duration: 10000,
    animationDuration: 'long'
  },

  initialize: function(el, options) {
    this.setOptions(options);
    this._el = $(el).getElement('ul');
    this._fx = new Fx.Tween(this._el, {
      duration: this.options.animationDuration,
      property: 'left',
      unit: 'px'
    });
    this._fx.addEvent('complete', function() {
      var i = this._el.getFirst('li');
      i = this._el.removeChild(i);
      this._el.grab(i);
      this._el.set('styles', {
        'left': '0px'
      });
    }.bind(this));
    (function() {
      this._fx.start(0, -120);
    }).periodical(this.options.duration, this);
  }
});

Element.implement({
  carouselify: function(options) {
    new Carousel(this, options || {});
  }
});

window.addEvent('domready', function() {
  $('carousel').carouselify({
    duration: 10000,
    animationDuration : 'normal'  // one of: 'short', 'normal' or 'long'; default is 'long'
  });

  if ($('cart') != null) {
    $('cart').getElements('form.refresh').getElements(
      'input[type=checkbox]').each(function(ele) {
      ele.addEvent('change', function() {
    	$('service').setStyle('background','url(../img/ajax-loader.gif) no-repeat center center');
        this.form.submit();
      });
    });
  }

  if ($('product_tabs') != null) {
    $('product_tabs').getElements('li').each(function(ele, idx) {
      ele.addEvent('click',function() {
        $('product_tabs_content').getElements('.tabcontent').each(function(el) {
          el.removeClass('active');
        });
        $('product_tabs_content').getElements('.tabcontent')[idx].addClass('active');

        $('product_tabs').getElements('li').each(function(elem) {
          elem.removeClass('active');
        });
        ele.addClass('active');
      });
    });
  }
  
  if($('kind') != null) {
	$('kind').getElements('input[type=radio]').each(function(ele,idx) {
		ele.addEvent('change',function(){
			 $('kind-container').getElements('.kind-element').each(function(el) {
		          el.setStyle('display','none');
		     });
			 $('kind_' + idx).setStyle('display','block');
		});
	});
  }
});

