d = document;
$j = jQuery;
num = parseInt;
function tag(o, v) {
	return (v) ? (o.tagName.toLowerCase() == v.toLowerCase()) : o.tagName.toLowerCase();	
}

function set_pad() {
	var pad = $('#pad1');
	if (!pad.length) return (false);
	
	pad.pads = [$('#adv_search'), $('#basket1')];

	pad.itms = $('#to_adv, #basket_info')
		.each(function(i) {
			this.i = i; this.pad = pad.pads[i]; this.class2 = (i) ? 'show_basket' : 'show_adv';
		})
		.click(function() {		
			if (pad.pads[this.i].is(':hidden')) {
				this.pad.slideDown();
				pad.pads[(this.i) ? 0 : 1].hide();
				pad[0].className = 'pad1 ' + this.class2;
			} else {
				this.pad.slideUp();
				pad[0].className = 'pad1'
			};
			 return (false);
		});
		
		if ($.browser.msie && $.browser.version < 7) pad.itms.click(function() { $('.filter select').toggleClass('hid'); return (false);});
		
		return (pad);
} 

function set_vitr() {
	var v = $('#vitr'), plus = $('<span class="plus"/>');
	if (!v.length) return (false);	
	
	if ($.browser.msie && $.browser.version < 7) {
		var list = $('ul.list',v);
		if (list.height() < 250) list.height(250);
	}
	
	v.s = false;																																				
	v.itms = $('a.i img', v).each(function() {
		this.style.backgroundImage = 'url('+this.src+')';
		this.src = 'i/t.gif';
		this.className = 'pct';
		this.$ = $(this);
		this._p = this.parentNode._p = this.$.parents('li');
		
		if (this.parentNode.parentNode.className != 'pad') this.parentNode.pad = this._p.find('.pad');
		
		
		this.$.parent().click(function() {
			if (v.s) {
				v.s.removeClass('s');
				
				if (v.s[0] == this._p[0]) {
					v.s = false;
					return (false);
				}
			}
			
			if ((this._p[0].offsetLeft + 248) > v.width()) this.pad.css('left', -129);
			if ((this._p[0].offsetTop + 248) > v.height()) this.pad.css('top', -129);
			
			this._p.addClass('s');
			v.s = this._p;
			
			return (false);
		}).filter('li>a.i').mouseover(function() {this.appendChild(plus[0])})		
	})
}

function set_cat_list() {
	var v = $('#cat');
	if (!v.length) return (false);	
	
	v.s = false;																																				
	v.itms = $('a.i img', v).each(function() {
		this.style.backgroundImage = 'url('+this.src+')';
		this.src = 'i/t.gif';
		this.className = 'pct';
		this.$ = $(this);
		this._p = this.$.parents('li');		
		
		this._p[0].$ = this._p;
		
		this._p
			.mouseover(function() {								
				clearTimeout(v.t1);				   
				if (v.s && v.s[0] != this) {
					v.s.removeClass('s');
					
					/*if (v.s[0] == this._p[0]) {
						v.s = false;
						return (false);
					}*/
				}
				
				this.$.addClass('s');
				v.s = this.$;
				
				return (false);
			})
		.mouseout(function(e) {
				var o = this;
				if ($(e.target).parents().filter(function() {return (this == o)}).length) {
					v.t1 = setTimeout(function() {v.s.removeClass('s')}, 500);
					return (false)
				}
			})	
			
			
	})
}

function make_tabs(tabs, pads, opts) {
	
	
	var o1 = this, s = s || 0,
	
	
	
	def = {
		t:300,
		eff:function() {this.fadeIn(def.t)},
		click:function(e) {
			if (this.tagName.toLowerCase() == 'a') {
				e.preventDefault();
				e.stopPropagation();
				
			}
			
			var o = $(this), _p = this._p;
			
			if (def.hide && _p.s[0] == this) {
				o.removeClass('s');
				this.pad.hide();
				_p.s = false;				
				return (false);
			}
			
			if (_p.s) {			
				_p.s.removeClass('s');
				_p.s[0].pad.hide();
			}
				
			o.addClass('s');
			
			_p.s = o;
			def.eff.apply(this.pad)//this.pad.fadeIn(def.t);
		
			
		},
		hide:false
	};
	if (opts) $.extend(def, opts);
	
	if (def.hide) s = -1;
	
	tabs.each(function(i, o) {
		o.pad = $(pads[i]);
		o._p = o1;
		o.i = i;
		
		var o = $(o).click(def.click)
		
		if (o.hasClass('s') && !s) s = i;
		
	});
	
	
	o1.s = (def.hide) ? false : $(tabs[s]).addClass('s');
	o1.tabs = tabs;
	pads.filter(function(i) {return i != s}).hide();
	
	return o1;
	
}

$(d).ready(function() {
	var pad = set_pad();
	$('input.input, textarea').filter('[value]').focus(function() {if (this.value == this.defaultValue) this.value = ''}).blur(function() {if (this.value == '') this.value = this.defaultValue});
}) 
