d = document;
$j = jQuery;
num = parseInt;

function make_menu(o) {
	
	o.s = false;
	$('.i',o).data('_p',o).each(function() {if (this.parentNode.className == 's') o.s = this}).click(function() {

		var o = $(this), _p = o.data('_p'), s = _p.s, sm = o.next().show(), sm_h = sm.height();		
		
		sm.css('display', '');		
		
		if (_p.s) $(_p.s).parent().removeClass('s');
		if (!sm.length) return;
        return;
		
		if (_p.s != this) {
			sm.css('height',1).animate({height:sm_h}, 500, function() {sm.css({display:'', height:''}); });
			o.parent().addClass('s');
			
			_p.s = this;
		} else {
			_p.s = false;
		}
		return (false);	
	});
	
	
}

function make_menu2(o) {

	o.s = false;
	$('.i',o).data('_p',o).each(function() {if (this.parentNode.className == 's') o.s = this}).click(function() {

		var o = $(this), _p = o.data('_p'), s = _p.s, sm = o.next().show(), sm_h = sm.height();

		sm.css('display', '');

		if (_p.s) $(_p.s).parent().removeClass('s');
		if (!sm.length) return;

		if (_p.s != this) {
			sm.css('height',1).animate({height:sm_h}, 500, function() {sm.css({display:'', height:''}); });
			o.parent().addClass('s');

			_p.s = this;
		} else {
			_p.s = false;
		}
		return (false);
	});


}

function make_menus(o) {
	o.each(function() {make_menu($(this))});
}
function make_menus2(o) {
	o.each(function() {make_menu2($(this))});
}


function make_car(o) {
    var itms2 = $('li',o);
	var n2 = itms2.length;
    if (n2>6) n2=6;

   var itms = $('li',o),
		n = itms.length,
		n0=n,
		show_itms = n2,
		slide = $('ul',o),
		hold = $('.hold', o),
		w,
		set_car_w = function() {
			w = Math.floor(hold.width()/show_itms);
			itms.css('width', w);
			slide.width(w*itms.length+5);
			hold.scrollLeft(0);
		};

	$('a', slide).each(function() {var i = this.getElementsByTagName('img')[0]; this.style.backgroundImage = 'url('+i.src+')'; i.src = '/i/t.gif'});

	var i = 0;

	while (i + n < show_itms*2 || n + i < n + show_itms) {
		$('li:nth-child('+(i+1)+')',o).clone().appendTo(slide);
		i++;
	}

	itms = $('li',o);

	if (n < show_itms) n = show_itms;

	var back1 = function() {if (hold.scrollLeft() >= n0*w) hold.attr('scrollLeft', 0)}, //hold.attr('scrollWidth')-hold.width()
		back2 = function() {if (hold.scrollLeft() == 0) hold.scrollLeft(n0*w)};

	$('.l, .r', o).data('_p', o).mousedown(function(e) {

		o.flag1 = true;
        clearInterval(o.t1);

		if (this.className == 'l') {
			hold.stop().animate({scrollLeft:Math.round(hold.attr('scrollLeft')/w)*w+w}, 300, back1);
			o.t1 = setInterval(function() {(o.flag1) ? hold.stop().animate({scrollLeft:Math.round(hold.attr('scrollLeft')/w)*w+w}, 300, back1) : clearInterval(o.t1) }, 500);
		} else {
			back2();
			hold.stop().animate({scrollLeft:Math.round(hold.attr('scrollLeft')/w)*w-w}, 300, back2);
			o.t1 = setInterval(function() {(o.flag1) ? hold.stop().animate({scrollLeft:Math.round(hold.attr('scrollLeft')/w)*w-w}, 300, back2) : clearInterval(o.t1) }, 500);
		}

		return (false);
	}).mouseup(function() {o.flag1 = false; return (false);}).click(function() {o.flag1 = false; return (false)})



	set_car_w();

	$(window).resize(set_car_w);

	
}

function make_tabs(tabs, pads, opts) {
	
	
	var o1 = this, s = s || 1000,

	
	def = {
		t:1,
		eff:function() {
            //this.fadeIn(def.t)
        },
		click:function(e) {
			if (this.tagName.toLowerCase() == 'a') {
				//e.preventDefault();
				//e.stopPropagation();
				
			}
			
			var o = $(this), _p = this._p;
			//_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);
			
		}	
	};
	if (opts) $.extend(def, opts)
	
	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 = i;
		
	});
	
	
	o1.s = $(tabs[s]).addClass('s');
    //alert(s);
	o1.tabs = tabs;
	pads.filter(function(i) {return i != s}).hide();
	
	return o1;
	
}

function make_tabs2(tabs, pads, opts) {


	var o1 = this, s = s || 0,


	def = {
		t:1,
		eff:function() {
            this.fadeIn(def.t)
        },
		click:function(e) {
			if (this.tagName.toLowerCase() == 'a') {
				e.preventDefault();
				e.stopPropagation();

			}

			var o = $(this), _p = this._p;
			_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);

		}
	};
	if (opts) $.extend(def, opts)

	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 = $(tabs[s]).addClass('s');
	o1.tabs = tabs;
	pads.filter(function(i) {return i != s}).hide();

	return o1;

}

$(d).ready(
	function() {
		make_menu2($('#menu2'));
		$('#menu a').each(function() {$(this).css('backgroundImage','url('+this.firstChild.src+')').children('img').attr('src','/i/t.gif')});
		$('.input[value]').focus(function() {this.value = ''}).blur(function() {if (this.value == '') this.value = this.defaultValue})
	});
