d = document;

function make_menu(o)  {
	
	o.itms = $('.i_a', o).data('_p',o).each(function() {
		var o = $(this), si = o.next();
		
		if (si.length) {
			si.mouseover(function(){clearInterval($(this).data('_p').t1)}).mouseout(function(){
				var o = $(this),
					_p = o.data('_p'), 
					act = function() {
						var sm = _p.data('s').next();
						sm.stop().animate({height:0}, 300, 'swing', function() {$(this).hide(); }).parent().removeClass('s');
						$('.c', sm).hide();
						if (_p.data('def')) {_p.data('def').parent().addClass('s'); _p.data('s', _p.data('def'));};
						_p.bg.hide(); 						
						delete act; 
					};
				_p.t1 = setTimeout(act, 500);	
			}).data('_p',o.data('_p'));
		}
												   
	}).mouseover(function() {
		var o = $(this), _p = o.data('_p');
		
		clearInterval(_p.t1);
		
		
		
		if (_p.data('s')) _p.data('s').next().stop().hide().parent().removeClass('s');			
		
		
		o.next().css('height',0).stop().animate({height:263}, 500, 'swing', function() {_p.bg.css('backgroundImage',o.next().css('backgroundImage')).show();});//, function() {$('.c', this).fadeIn()}		
		$('.c', o.next()).hide().fadeIn(500);
		
		_p.data('s', o);
		o.parent().addClass('s');
		
	}).mouseout(function() {
		
		var o = $(this),
		_p = o.data('_p'),
		act = function() {
			var sm = _p.data('s').next();
			sm.stop().animate({height:0}, 300, 'swing', function() {$(this).hide()}).parent().removeClass('s'); 
			$('.c', sm).hide();
			if (_p.data('def'))  {_p.data('def').parent().addClass('s'); _p.data('s', _p.data('def'));};
			_p.bg.hide();
			delete act 
		};
		_p.t1 = setTimeout(act, 500);
		
		
	});
	
	o.act = function() {}
	
	o.bg = $('<div class="sm"/>').css({top:0, left:0, zIndex:9}).appendTo(o);
	
	var def = $('.s', o);	
	def = (def.length) ? def : false//$('.i:first', o);
	
	//def.parent().addClass('s');
	
	o.data('def',def).data('s',def);
}

function make_promo(o) {
	var o = o;
	
	o.data('itms', $('a', o).addClass('i'));
	
	if (o.data('itms').length < 2) return;
	
	o.append('<a class="frame"/><div class="th"/>');
	
	o.css('backgroundImage','url('+$('img:last', o).attr('src')+')');
	o.s = 0;
	
	o.set_pct = function() {
		o.data('itms').each(function(i) {
			(i < o.s) ? $(this).hide() : $(this).show();								   
		})
		o.css('backgroundImage','url('+$('.i:last', o).attr('src')+')');
	}
	
	o.f = function() {
		if (!o.s) {
			o.data('itms').show();	
		}
		
		$(o.data('itms').get(o.s)).fadeOut(1000);
		$('.th a:nth-child('+(o.s+1)+')', o).removeClass('s');
		
		o.s = (o.s < o.data('itms').length-1) ? o.s + 1 : 0;
		
		$('.th a:nth-child('+(o.s+1)+')', o).addClass('s');
		$('.frame', o).attr('href', o.data('itms').get(o.s).href);
		
		if (!o.s) {			
			$(o.data('itms').get(0)).hide().fadeIn(1000);
		}
	}
	
	o[0].t1 = setInterval(o.f, 6000);
	//o.click(function() {clearInterval(this.t1)})
	
	$('.i', o).each(function(i) {
		var o2 = $(this);
		if (!i) $('.frame',o).attr('href', o2.attr('href'));
		o2.clone().appendTo($('.th',o)).data('_p',o).data('i',i).click(function(e){
			e.preventDefault();			 
			
			var o = $(this).addClass('s'), _p = o.data('_p');
			clearInterval(_p[0].t1);
			$('.th a:nth-child('+(_p.s+1)+')', _p).removeClass('s');
			
			_p.css('backgroundImage', 'url('+$('.th a:nth-child('+(_p.s+1)+')', _p).children(0).attr('src')+')');
			_p.s = o.data('i');
			_p.data('itms').each(function(i) {
				if (i != _p.s) {
					$(this).hide();
				} else {
					$(this).hide().fadeIn(1000, _p.set_pct);
					$('.frame', _p).attr('href', this.href);
				}
			});
			
			_p[0].t1 = setInterval(_p.f, 6000);
		});
		o2.css('zIndex', o.data('itms').length - i).data('_p', o);
		
	});
	
	$('.th :first', o).addClass('s');
}

function make_tabs(tabs, pads, s) {
	var o1 = this, s = s || 0;
	
	tabs.each(function(i, o) {
		o.pad = $(pads[i]);
		o._p = o1;
		
		var o = $(o).click(function(e) {
			e.preventDefault();
			e.stopPropagation();
			var o = $(this), _p = this._p;
			_p.s.removeClass('s');			
			o.addClass('s');			
			_p.s[0].pad.hide();
			this.pad.fadeIn(500);
			_p.s = o;
		})
		
		if (o.hasClass('s') && !s) s = i;
		
	});
	
	o1.s = $(tabs[s]).addClass('s');
	
	pads.hide().filter(function(i) {return i == s}).show();
}