/* -*- coding:utf-8-unix;tab-width:4 -*- vim:set enc=utf-8 ff=unix ts=4: */
/*!	$Id$ */
/*jslint browser: true, eqeqeq: true, immed: true, nomen: true, onevar: true,
         plusplus: true, regexp: true, sloppy: true, undef: true, white: true */
/*global jQuery, window */

(function ($) {
	var c = {
		buttons: [],
		duration: 6000,
		slides: [],
		timeoutId: null,
		init: function () {
			c.slides = $('.elem_slider .elem_slider_mask .slide');
			c.buttons = $('.elem_slider .elem_slider_btns li');
			c.buttons.each(function (i) {
				var button = $(this);
				button.click(function () {
					if (null !== c.timeoutId) {
						clearTimeout(c.timeoutId);
					}
					c.buttons.removeClass('on');
					button.addClass('on');
					c.slides.
						filter(':visible:first').
						fadeOut('fast', function () {
							$(c.slides[i]).fadeIn(function () {
								var next = i + 1;
								if (next >= c.slides.length || next < 0) {
									next = 0;
								}
								c.timeoutId = setTimeout(function () {
									$(c.buttons[next]).click();
								}, c.duration);
							});
						});
					return false;
				});
			});
			c.timeoutId = setTimeout(function () {
				$(c.buttons[1]).click();
			}, c.duration);
		}
	};
	$(document).ready(c.init);
}(jQuery));

