d = document;
$j = jQuery;
num = parseInt;
function tag(o, v) {
	return (v) ? (o.tagName.toLowerCase() == v.toLowerCase()) : o.tagName.toLowerCase();	
}

function make_slides(slides, opts) {	
	var o = this,
		def = {
			s: false,
			act: function(o2) {
				if (o.s) {
					o.s.hide();
					//o.s.tab.stop().animate({'marginTop':170}, 300, 'swing');
				}
				o.opts.eff(o2);
				o.s = o2.$;
				o.i = o2.i;
				return (false);
			},
			eff: function(o2) {
				o2.$.fadeIn(1000, function() {o2.parentNode.style.backgroundImage = 'url('+o2.firstChild.src+')'; })
			},
			
			auto: true
	};
	
	o.auto = {
		act: function() {o.opts.act(o.itms[o.i]); o.i = (o.i < o.itms.length-1) ? o.i+1 : 0},
		start:function() {
			o.auto.act();
			clearInterval(o.auto.t1);
			o.auto.t1 = setInterval(o.auto.act, 5000);
			o.auto.paused = false;
		},
		pause:function() {
			clearInterval(o.auto.t1);
			o.auto.paused = true;
		}		
	}
	
	o.itms = $('.i', slides).each(function(i) {this.$ = $(this), this.i = i; if (i) {this.$.hide()} else { o.s = this.$; this.parentNode.style.backgroundImage = 'url('+this.firstChild.src+')'; } });
	
	o.tabs = $('.push a', slides)
		.each(function(i) {this.$ = $(this); this.i = i; o.itms[i].$.tab = this.$; })
		/*.click(function(e) {
			e.preventDefault(); 
			
			o.i = this.i;
			o.auto.start();
		})*/
		.hover(
			function() {this.$.stop().animate({'marginTop':0}, 300, 'swing')},  
			function() {this.$.stop().animate({'marginTop':200}, 300, 'swing')}
		)
	o.i = 0;
	
	(!opts) ? opts = def : opts = $.merge({}, def);
	
	o.opts = opts;
	
	o.auto.start();
	
	return o;
	
}

$(d).ready(
	function() {		
		var pr = $('#promo'); 
		if (pr.length) pr.slides = new make_slides(pr);
		
		$('form#booking .d img')
			.each(function() {this.input = this.parentNode.getElementsByTagName('input')[0]})
			.click(function() {
				this.input.value = (this.className == 'up') ?
					parseInt(this.input.value)+1 :
					((this.input.value != '0') ? parseInt(this.input.value)-1 : 0) 
			});
		
		if ($('form#booking').length) Calendar.setup({inputField  : "date",   ifFormat    : "%Y/%m/%d"});
})
