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.opts.eff(o2);
				o.s = o2.$;
				return (false);
			},
			eff: function(o2) {
				o2.$.fadeIn(2000, 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();
			o.auto.t1 = setInterval(o.auto.act, 5000);
			o.auto.paused = false;
		},
		pause:function() {
			clearInterval(o.auto.t1);
			o.auto.paused = true;
		}		
	}
	
	o.itms = $('#promo_c .i').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.i = 0;
	
	(!opts) ? opts = def : opts = $.merge({}, def);
	
	o.opts = opts;
	
	o.auto.start();
	
	//$('#promo_c').click(function() {(o.auto.paused) ? o.auto.start() : o.auto.pause(); return (false)});	
	
	return o;
	
}

function make_scroll(pr) {
	var o = $('<div class="scroll"/>').appendTo(pr);
	$('<div class="sh"/>').appendTo(pr);
	o.bg = []; 
		
	
	o.scr = $('<ul/>').appendTo(o);
	o.itms = $('a.pad', pr).each(function(i) { 
		this.$ = $(this);
		this.tab = $('<li />')
			.append(this.$.clone().append('<div>' + this.firstChild.alt + '</div>').removeClass('pad'))
			.appendTo(o.scr)
			.find('img')
			.mouseover(function() {
					var o = this.pad;									
					pr.slides.auto.pause();
					$('#promo_c a').stop().css('opacity','').hide();
					
					o.$.stop().fadeIn(1000, function() {
						o.parentNode.style.backgroundImage = 'url('+o.firstChild.src+')';
					}) 
			})
			.mouseout(function() {
					this.pad.$.stop().fadeOut(1000);
					pr.slides.auto.start();
			});
			
		this.tab[0].i = i;
		this.tab[0].pad = this;
		
		var src = this.firstChild.src.split('/');
		src.push(src[src.length-1]);
		src[src.length-2] = 'th';		
		
		this.tab.attr('src', src.join('/'));
		this.i = i;
	}).hide();
	
	var i = 0, w = 235;//$('li', o.scr).attr('offsetWidth');
	o.scr.width(o.itms.length*w);
	
	
	o.push = $('<img src="img/push/arrl.gif" class="arrl"/><img src="img/push/arrr.gif" class="arrr"/>').appendTo(pr)
		.each(function(i) {this.$ = $(this); this.i = i})
		.click(function() {		
						
			i = (this.i) ? i+1 : i-1;
			
			if (i<0) { i = 0; return (false) 
				
			}		
			
			if (i>o.itms.length-4) {i=o.itms.length-4; return (false)}	
				
			o.stop().animate({scrollLeft:i*w}, 500, 'swing');
			
			return (false);
		})
}

function make_menu () {
	
	var o = $('#menu');
	
	if (!o.length) return;
	
	o.s = false;
	o.hov = false;
 
	o.itms = o.find('td')
		.each(
		function(i) 
		{
			this.$ = $(this); 
			if (this.className == 's') 
				o.s = this.$;
				
			this.sm = this.$.find('.sm').mouseover(function() {clearInterval(o.t1)} );
		} )
		.mouseover(function() {
                        clearInterval(o.t1);
                        
			if (o.s) 
                            o.s.attr('className','');
                        
			if (o.hov && o.hov != this.sm) 
                            o.hov.fadeOut();
                        
			this.$.addClass('hov');
			this.sm.slideDown();
			o.hov = this.sm;
		})
		.mouseout(function() {
			clearInterval(o.t1);
			
			if (o.s != this) 
                            this.className = '';
			
			o.t1 = setTimeout(function() { 
                            if (o.s) 
                                o.s.addClass('s');

                            o.hov.slideUp();
                        }, 500);
		});
			
		
	
	o.find('.sm').hide().filter(':last').addClass('v2');
	o.find('.s .i').append($('<span class="arr"/>'));
        

        o.find('.sub_menu')
		.each(
		function(i) 
		{
                    this.$ = $(this); 
                    if (this.className == 's1') 
                        o.s1 = this.$;
                            
                    this.smsm = $(this).find('.smsm').mouseover(function() {clearInterval(o.t2);} );
                    this.smsm.css("margin-left", $(this).parent().css("width"));
					
					var len = this.smsm.find("img").length;
					if(len > 0){
						var default_width = 130;
						var width = len * default_width;
						this.smsm.css("width", width + "px");
					}

		})
                .mouseover(function() {
                        clearInterval(o.t2);
                        if (o.s1) 
                            o.s1.attr('className','');
                        
                    	if (o.hov1 && o.hov1 != this.smsm) 
                            o.hov1.hide();//o.hov1.fadeOut();
                        
			this.$.addClass('hov1');
			this.smsm.show();//this.smsm.slideDown();
			o.hov1 = this.smsm;
                })
                .mouseout(function() {
                    clearInterval(o.t2);
                     o.t2 = setTimeout(function() { 
                            if (o.s1) 
                                o.s1.addClass('s1');

                            o.hov1.hide();//o.hov1.slideUp();
                        }, 1);
                });
                
	return (o);
};

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 m = new make_menu(); })
