$(document).ready(function () {
 $('.nav_top1 table tr td:last-child').css('background','none')		
 
 $('.nav_right1>ul>li').has('ul').css('background','none').children('a').css('background','url("/images/bg_nav_right_open.gif") left 10px no-repeat')
 $('.sub1 li:last-child').css('background','none')		
 if ($.browser.msie & $.browser.version == 6) {$('.nav_top2 table tr td:last-child').css('background','url(/images/bg_about.gif) right 2px no-repeat')} else 
 {$('.nav_top2 table tr td:last-child').css('background','url(/images/bg_about.gif) right top no-repeat')}

var mainwidth = $('div.container').width();
var dokoff = $('div.container').offset();

 $('.sub').each(function() {
	var oL=$(this).offset();

	if ((oL.left - dokoff.left) < (250 + $($(this).parent()).parent().width())) {
		$(this).css('left','-4px').find('.sub1').each(function() {$(this).css('left','100%')})
		$(this).css('left','-4px').find('.sub2').each(function() {$(this).css('left','100%')})
	} else {
		if ($.browser.msie & $.browser.version == 6) {
			$(this).css('right','-4px').find('.sub1').each(function() {$(this).css('right','100%')})	
			$(this).css('right','-4px').find('.sub2').each(function() {$(this).css('left','100%')})	
		} else {
			$(this).css('right','2px').find('.sub1').each(function() {$(this).css('right','100%')})
			$(this).css('right','2px').find('.sub2').each(function() {$(this).css('left','100%')})
		}
	}
	$(this).hide().css('visibility','visible');
 })
							
	//Выпадающее меню верх, первый уровень						
$(".nav_top1 table tr td").hoverIntent({
 over: show,
 out: hide,
 interval: 30,
 timeout: 30,
 sensitivity: 4
 });
 
 function show() {
 var current = $(this);
 current.css('background','url(/images/bg_li_hover.gif) repeat-x').find("div.sub").show();
 }
 function hide() {
 var current = $(this);
 current.css('background','url(/images/bg_li.gif) right top no-repeat').find("div.sub").hide();
 $('.nav_top1 table tr td:last-child').css('background','none')	
 }

	//Выпадающее меню верх, второй уровень						
 $(".sub_right>ul>li").hoverIntent({
 over: show1,
 out: hide1,
 interval: 30,
 timeout: 30,
 sensitivity: 4
 });
 
 $(".sub1>li").has('ul').hoverIntent({
 over: showsub,
 out: hidesub,
 interval: 30,
 timeout: 30,
 sensitivity: 4
 });

 function showsub() {
 var current = $(this);
 current.css('background','#2669b5').find(".sub2").show();

 }
 function hidesub() {
 var current = $(this);
 current.css('background','#3883c7').find(".sub2").hide();
 }
 
 
 function show1() {
 var current = $(this);
 current.css('background','#3883c7 url(/images/bg_dash1.gif) bottom repeat-x').find(".sub1").show();
 }

 function hide1() {
 var current = $(this);
 current.css('background','url(/images/bg_dash1.gif) bottom repeat-x').find(".sub1").hide();
 }
 
 	//Выпадающее меню низ, первый уровень						
$(".nav_top2 table tr td").hoverIntent({
 over: show2,
 out: hide2,
 interval: 30,
 timeout: 30,
 sensitivity: 4
 });
 
 function show2() {
 var current = $(this);
 
 if ($.browser.msie & $.browser.version == 6) {
	 var q=current.find("div.sub").outerHeight()+25;
	 current.css('background','url(/images/bg_li_hover.gif) bottom repeat-x').find("div.sub").css('top',-q).show();
	 } else 
 {
	 var q=current.find("div.sub").outerHeight()+27;
	 current.css('background','url(/images/bg_li_hover.gif) repeat-x').find("div.sub").css('top',-q).show();
 }
 
 }
 function hide2() {
 var current = $(this);
 if ($.browser.msie & $.browser.version == 6) {
	 current.css('background','url(/images/bg_li.gif) right 2px no-repeat').find("div.sub").hide();
	 $('.nav_top2 table tr td:last-child').css('background','url(/images/bg_about.gif) right 3px no-repeat');
	 } else 
 {
	 current.css('background','url(/images/bg_li.gif) right 1px no-repeat').find("div.sub").hide();
	 $('.nav_top2 table tr td:last-child').css('background','url(/images/bg_about.gif) right top no-repeat');
 }
 }
 
 //разворачивающееся меню
 
	/*$('.nav_right ul li:has(ul)').click(function(event) {
			if (this==event.target) {
				$(this).children().toggle();
			}
			//return false;
		})*/



}); 

