﻿////////////////////////////////////////////////////////////////////////
//////////////////二///级///导///航///jquery///方///法////////////////////
////////////////////////////////////////////////////////////////////////
/////////////////////////Author///:///Keboy/////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////Version///:///v1.0//////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////Date///:///2010-8-10/////////////////////////
////////////////////////////////////////////////////////////////////////
$.extend( {
	//---------- 获取当前鼠标在整个页面（包括滚动条）的绝对位置x轴坐标
	ax: function() {
		var cx = event.x?event.x:event.pageX;
		if ( typeof(cx) == "undefined" ) {
			cx = 0;
		}
		if ( $.browser.msie ) {
			if ( $.browser.version != "8.0" ) {
				cx += document.documentElement.scrollLeft;
			}
		}
		else if ( $.browser.safari ) {
			cx += document.body.scrollLeft;
		}
		return cx;
	},
	//---------- 获取当前鼠标在整个页面（包括滚动条）的绝对位置y轴坐标
	ay: function() {
		var cy = event.y?event.y:event.pageY;
		if ( typeof(cy) == "undefined" ) {
			cy = 0;
		}
		if ( $.browser.msie ) {
			if ( $.browser.version != "8.0" ) {
				cy += document.documentElement.scrollTop;
			}
		}
		else if ( $.browser.safari ) {
			cy += document.body.scrollTop;
		}
		return cy;
	}
} );
$( function() {
	$(document.body).click( function() {
		$.ax();
	} );
	var Bingo = new Array(
		"index.asp",
		"about.asp",
		"product.asp",
		new Array(
			"servce.asp",
			"question.asp",
			"question_view.asp",
			"jsjl.asp",
			"jsjl_view.asp"
		),
		"rlzy.asp",
		new Array(
			"download1.asp",
			"download2.asp"
		),
		"contact.asp"
	),pageindex = 0,pagename = window.location.href;
	pagename = pagename.split("/");
	pagename = pagename[pagename.length - 1];
	pagename = pagename.split("?")[0];
	pagename = pagename.toLowerCase();
	$.each(Bingo,function(i,m) {
		if ( typeof m == "string" ) {
			if ( pagename == m ) {
				pageindex = i;
				return;
			}
		}
		else if ( typeof m == "object" ) {
			$.each(m,function(j,n) {
				if ( pagename == n ) {
					pageindex = i;
					return;
				}
			});
		}
	});
	var pageObj = $("#nav").find("li:odd").eq(pageindex).find("img");
	pageObj.attr("src",pageObj.attr("src").replace("nav1","nav2"));
	if ( $.browser.mozilla ) {
		$("div.underlist").each( function() {
			resetUnderlist($(this).prev());
		} );
		$("#nav").find("li:odd").not(":eq(" + pageindex + ")").hover( function() {
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace("nav1","nav2")).next().slideDown(300);
		},function() {
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace("nav2","nav1")).next().slideUp(100);
		} ).end().eq(pageindex).hover( function() {
			$(this).find(".underlist").slideDown(300);
		},function() {
			$(this).find(".underlist").slideUp(100);
		} );
	}
	else {
		$("#nav").find("li:odd").not(":eq(" + pageindex + ")").find("img").hover( function() {
			$(this).attr("src",$(this).attr("src").replace("nav1","nav2"));
		},function() {
			if ( $(this).next().is("div.underlist") ) {
				if ( $.ax() < $(this).next().offset().left || $.ax() >= ( $(this).next().offset().left + $(this).next().outerWidth(true) ) || $.ay() < $(this).next().offset().top || $.ay() >= ( $(this).next().offset().top + $(this).next().outerHeight(true) ) ) {
					$(this).attr("src",$(this).attr("src").replace("nav2","nav1"));
				}
			}
			else {
				$(this).attr("src",$(this).attr("src").replace("nav2","nav1"));
			}
		} ).end().end().find("img").hover( function() {
			if ( $(this).next().is("div.underlist") ) {
				resetUnderlist($(this));
				$(this).next().slideDown(300);
			}
		},function() {
			if ( $(this).next().is("div.underlist") ) {
				checkClose($(this).next())
			}
		} );
		$("div.underlist").bind("mouseleave", function() {
			checkClose($(this))
		} );
	}
	function checkClose(Obj) {
		if ( $.ax() < Obj.offset().left || $.ax() >= ( Obj.offset().left + Obj.outerWidth(true) ) || $.ay() < Obj.offset().top || $.ay() >= ( Obj.offset().top + Obj.outerHeight(true) ) ) {
			Obj.slideUp(100);
			if ( $("#nav").find("li:odd").index(Obj.parent()) != pageindex ) {
				Obj.prev().attr("src",Obj.prev().attr("src").replace("nav2","nav1"));
			}
		}
	}
	$("div.underlist td").filter( function() {
		return $(this).text().length > 4;
	} ).css("padding","2px 10px").end().filter( function() {
		return $(this).text().length <= 4;
	} ).css("padding","2px 34px 2px 10px");
	if ( !$.browser.msie || $.browser.version != "6.0" ) {
		$("div.underlist table").removeAttr("width");
	}
	function resetUnderlist(Obj) {
		Obj.next().css( { "top" : ( Obj.offset().top + Obj.height() ) + "px" , "left" : Obj.offset().left + "px" } );
	}
	$(window).resize( function() {
		$("div.underlist").each( function() {
			resetUnderlist($(this).prev());
		} );
	} );
} );
