$(function(){
		$('<li class="tm_bot"><span></span></li>').appendTo('#menu_t ul.drop');
		$('#menu_t ul.drop').parent().each(function() {
				var o = $(this);
				var s = o.find('>ul');
				var l = o.parents('ul').length;
				var k = false;
				/*
				s.find('>li').each(function(){
					if ($(this).index()%4==2){
						$(this).after('<br clear="all" />')					
					}
				})
				*/
				o.hover(
					function() {
						o.find('>a').attr('class','over');
						for (i=$('#menu_t ul.drop').length; i>=0; i--){
						o.parent().find('>li').not(o).find('ul.drop').eq(i).hide();
						}
						k = true;
						var p = o.position();
						var ts, ls;
						if(p.left+s.width()>$('#wrapper').width()&&l==1){
                        	qwe = true;
                        }else if(l==1){
                        	qwe = false;
                        }
						if (qwe){
                            if (l == 1) {
                                ts = 0;
                                ls = p.left-s.width()+o.width();
                            } else {
                                ts = p.top;
                                ls = p.left - o.width() - 2;
                            }

                        }else{         
						if (l == 1) {
							ts = 0;
							ls = p.left;
						} else {
							ts = p.top;
							ls = p.left + o.width();
						}
						}
						s.css({
							top: ts,
							left: ls
						}).show();
					},
					function() {
						o.find('>a').attr('class','normal');
						k = false;
						window.setTimeout(function() {
							if (!k) s.hide(); 						   
						}, 500);
					}
				);
			});
})
