d = document;
$d = $(d);
$j = jQuery;
num = parseInt;
function tag(o, v) {
	return (v) ? (o.tagName.toLowerCase() == v.toLowerCase()) : o.tagName.toLowerCase();	
}

function make_scroll() {
	var o = $('#promo_c'), bg_w = 1920, i = 0;
	o.bg = []; 
	
	o.hold = $('.hold', o)//.width(o.width());
		
	o.h2 = $('.h2', o);
	o.scr = $('ul', o);
	
	o.scr.children(':first').clone().appendTo(o.scr);
	o.itms = $('li', o).width(o.width()).each(function(i) { var o1 = $(this); o.bg.push(o1.css('backgroundImage')); o1.css('backgroundImage', ''); o1.i = i;});
	o.scr.width(o.width()*o.itms.length);
	
	$('li img', o).addClass('png');
	
	o.pads = $('.pad', o.parent()).each(function(i) {						 
		var o1 = $(this);		
		if (i) {
			o1.hide();	
		} else {
			o.itms[o.itms.length-1].pad = o1.clone().appendTo(o1.parent()).hide();	
		}		
		o.itms[i].pad = o1;
	})
	
	o.hold.scrollLeft(0);
	
	o.push = $('<div class="arrl"/><div class="arrr"/>').appendTo(o).addClass('png')
		.each(function(i) {this.$ = $(this); this.i = i})
		.click(function() {
						
			clearInterval(o.t1);
			o.t1 = setInterval(auto, 10000);
			
			o.itms[i].pad.hide();				
						
			i = (this.i) ? i+1 : i-1;
			
			if (i<0) { /* i = 0; return (false) */ back1(); }		
			
			if (i>=o.itms.length) {i=o.itms.length-1; return (false)}		
				
			o.hold.stop().animate({scrollLeft:o.hold.scrollLeft() + ((this.i) ? o.width() : -o.width())}, 500, 'swing', back1);
			o.h2.css({backgroundImage:o.bg[i], backgroundPosition:((this.i) ? -bg_w+((o.width()-bg_w)/2) : o.width()-((o.width()-bg_w)/2))+'px 0'}).stop().animate({backgroundPosition: (o.width()/2-bg_w/2)+'px 0'}, 700, 'linear');
			o.stop().animate({backgroundPosition: ((this.i) ? (o.width()-(o.width()-bg_w)/2) : -bg_w+(o.width()-bg_w)/2)+'px 0'}, 700, 'linear', set_bg);
			
			o.itms[i].pad.fadeIn(500);
			
			return (false);
		})
	
	
	var set_bg = function() {
		o.css({backgroundImage:o.bg[i], backgroundPosition:(o.width()/2-bg_w/2)+'px 0'});
	}, back1 = function() {
		
		if (i == o.itms.length-1) {
			o.itms[i].pad.hide();
			o.itms[0].pad.show();
			o.hold.scrollLeft(0);
			i = 0;
			set_bg();
			
			return (false);
		}
		
		if (i < 0) {
			o.hold.scrollLeft((o.itms.length-1)*o.hold.width());
			i = o.itms.length-2;
			set_bg();
			
			return (false);
		}
	}, auto = function() {o.push[1].$.click();}
	
	set_bg();
	
	$(window).load(function() {o.t1 = setInterval(auto, 10000)}).resize(function() {var w = $(d).width(); o.itms.width(w); o.hold.scrollLeft(i*w); o.scr.width(w*o.itms.length); set_bg(); })
}

function make_menu(m1, index) {
	var itms = $('.i', m1);
	m1.s = m1.hov = false;
	itms.each(function(i) {
			if (this.parentNode.className == 's') m1.s = m1.hov = this;
			this.i = i+1;
			this.$ = $(this);
			this.pad = this.$.next()
				.mouseover(function() {
					clearTimeout(m1.t1)
				})
				.mouseout(function() {
					this.tab.mouseout();
				})
			if (this.pad.length) this.pad[0].tab = this.$;
		})
		.mouseover(function() {
			clearTimeout(m1.t1);
			if (m1.hov) m1.hov.parentNode.className = '';
			this.parentNode.className = 's';	
			
			m1.hov = this; 		
			if (sh1) {				
				if (index) {
					if (sh1) ($.browser.msie) ? sh1.show() : sh1.fadeIn();
				} else {
					sh1.stop().css({backgroundImage:'url(img/bg/menu_bg_'+this.i+'.jpg)', opacity:0}).animate({opacity:1}, 500, 'linear',function() {sh1.parent().css('backgroundImage', sh1.css('backgroundImage'));})
				}
			}
		})
		.mouseout(function() {
			clearTimeout(m1.t1);
			
			m1.t1 = setTimeout(function() {
				if (m1.hov != m1.s) m1.hov.parentNode.className = '';
				if (m1.s) {
					m1.s.parentNode.className = 's';
					m1.hov = m1.s;
					sh1.parent().css('backgroundImage', 'url(img/bg/menu_bg_'+m1.s.i+'.jpg)');
				} else if (!index) {
					sh1.parent().css('backgroundImage', 'url(img/bg/menu_bg_1.jpg)');
				}
				
				if (sh1) {
					if (index) {
						if (sh1) ($.browser.msie) ? sh1.hide() : sh1.fadeOut();
					} else {
						sh1.stop().animate({opacity:0}, 500);
					}
				}
			}, 500);
		});
}
