function initSearch(){
	var f = $('search_form');
	var s = $('search_field');
	var btn = $('search_button');

	if (s && f && btn){
		s.observe('blur', function(){
			if (s.value=='')s.value='поиск'
		});

		s.observe('focus', function(){
			if (s.value=='поиск')s.value='';
		});

		btn.observe('click', function(e){
			e.preventDefault();
			f.submit();
		});
	}
}


var Slider = Class.create({
	initialize: function(sliderId, backId, forwardId, delay) {
		this.box = $(sliderId);
		this.list = new Array();
		this.slide = null;
		this.backBtn = $(backId);
		this.forwardBtn = $(forwardId);
		this.n = 0;
		this.ready=true;
		this.TID = null;
		this.delay = delay ? delay : 4000;//ms

		if (!this.box || !this.forwardBtn || !this.backBtn)
			return;

		var sList = this.box.childElements();
		if (sList) {
			sList.each(function(el){
				el.n=this.n;
				el.setAttribute('n', this.n);
				el.content=el.firstDescendant();

				this.addEventStart(el, 'mouseout');
				this.addEventStop(el, 'mouseover');

				this.list[this.list.length]=el
				this.n++;
			}.bind(this));

			if (this.list.length){
				this.slide = this.list[0];
			}
		};

		this.forwardBtn.observe('click', function(e){
			e.preventDefault();
			if (this.ready)this.forward();
		}.bind(this));
		this.addEventStart(this.forwardBtn, 'mouseout');
		this.addEventStop(this.forwardBtn, 'mouseover');

		this.backBtn.observe('click', function(e){
			e.preventDefault();
			if (this.ready)this.back();
		}.bind(this));
		this.addEventStart(this.backBtn, 'mouseout');
		this.addEventStop(this.backBtn, 'mouseover');

		this.start();
	},

	addEventStart:function(el, action){
		el.observe(action, function(e){
			e.preventDefault();
			this.start();
		}.bind(this));
	},

	addEventStop:function(el, action){
		el.observe(action, function(e){
			e.preventDefault();
			this.stop();
		}.bind(this));
	},

	start:function() {
		if (!this.TID){
			this.TID = setInterval(function(){
				this.forward();
			}.bind(this), this.delay);
		}
	},

	stop:function() {
		if(this.TID)clearInterval(this.TID);
		this.TID=null;
	},

	forward:function() {
		var next = this.getNext();
		if (this.slide=='undefined' || next==null || this.n<=1 || this.ready==false)
			return;

		this.ready=false;
		next.makePositioned().setStyle({left: -next.getWidth(), top:-this.slide.getHeight()}).show();

		new Effect.Move(this.slide,
		{
			duration:0.4,
			x:this.slide.getWidth(),
			y:0
		});

		new Effect.Move(next,
		{
			duration:0.4,
			x:next.getWidth(),
			//x:0,
			y:0,
			//y:-next.getHeight(),
			//mode:'absolute',
			afterFinish:function(){
				this.slide.hide();
				this.box.insert(this.slide);
				this.slide = next.undoPositioned();
				this.ready = true;
			}.bind(this)
		});
	},

	back:function() {
		var prev = this.getPrev();
		if (this.slide=='undefined' || prev==null || this.n<=1 || this.ready==false)
			return;

		//this.ready=false;
		//this.box.style.backgroundPosition = 'center bottom';
		//this.box.style.backgroundImage = prev.content.style.backgroundImage;


		this.ready=false;
		prev.makePositioned().setStyle({left: prev.getWidth(), top:-this.slide.getHeight()}).show();

		new Effect.Move(this.slide,
		{
			duration:0.4,
			x:-this.slide.getWidth(),
			y:0
		});

		new Effect.Move(prev,
		{
			duration:0.4,
			x:-this.slide.getWidth(),
			y:0,
			afterFinish:function(){
				this.slide.hide();
				this.box.insert({top:prev});
				this.slide = prev.undoPositioned();
				this.ready = true;
			}.bind(this)
		});
	},

	getNext: function() {
		if(this.list.length>1 && this.slide){
			if (this.slide.n+1>=this.n){
				return this.list[0];
			} else {
				return this.list[this.slide.n+1];
			}
		}
		return null;
	},

	getPrev: function() {
		if(this.list.length>1 && this.slide){
			if (this.slide.n-1<0){
				return this.list[this.n-1];
			} else {
				return this.list[this.slide.n-1];
			}
		}
		return null;
	}
});

var Sizer = Class.create({
	initialize: function(id) {
		this.container = $(id);

		if (this.container != 'undefined'){
			this.container.update(this.container.getWidth());

			Event.observe(window, 'resize', function() {
				this.container.update(this.container.getWidth())
			}.bind(this));
		}

	}
});

