// JavaScript Document

//tab鍒囨崲鍏辩敤
$(function() {
	function tabs(tabTit, on, tabCon, tabMore) {
		$(tabCon).each(function() {
			$(this).children().eq(0).show();
		});
		$(tabTit).each(function() {
			$(this).children().eq(0).addClass(on);
		});
		$(tabMore).each(function() {
			$(this).children().eq(0).css('display', 'block');

		});
		$(".tab-more1").each(function() {
			$(this).children().eq(0).css('display', 'block');

		});
		$(tabTit).children().hover(function() {
			$(this).addClass(on).siblings().removeClass(on);
			var index = $(tabTit).children().index(this);
			$(tabCon).children().eq(index).show().siblings().hide();
			$(tabMore).children().eq(index).css('display', 'block').siblings().hide();
		});
	}

	tabs(".tab-hd1", "cur", ".tab-bd1", ".tab-more1");
	tabs(".tab-hd2", "cur", ".tab-bd2", ".tab-more2");
	tabs(".tab-hd3", "cur", ".tab-bd3", ".tab-more3");
	tabs(".tab-hd4", "cur", ".tab-bd4", ".tab-more4");
	tabs(".tab-hd5", "cur", ".tab-bd5", ".tab-more5");
	tabs(".tab-hd6", "cur", ".tab-bd6", ".tab-more6");

	function tabsindex(tabTit, on, tabCon, tabMore) {
		$(tabTit).children().hover(function() {
			$(this).addClass(on).siblings().removeClass(on);
			var index = $(tabTit).children().index(this);
			$(tabCon).children().eq(index).show().siblings().hide();
			$(tabMore).children().eq(index).css('display', 'block').siblings().hide();
		});
		$(".index-fwly").mouseleave(function() {
			$(".index-fwly-zlm").hide();
			$(".index-fwly-xlk .nr").removeClass("cur");
		})
	}
	tabsindex(".tabindex-hd1", "cur", ".tabindex-bd1", ".tabindex-more1");

	//瀵艰埅榧犳爣婊戝叆鍒掑嚭
	$(".header .header-r>li").mouseover(function() {
		$(".header .header-r>li>a.cur").removeClass("cur")
		$("a.more", this).addClass("cur");
		if($("ul.sub", this)[0])
		{
			$("ul.sub", this).show();
			var l = $("ul.sub", this).offset().left;
			var w = $("ul.sub", this).width();
			if ((w + l) > $(window).width()) {
				$("ul.sub", this).css("right", l+$(this).width()-$(window).width());
			}
		}
	});

	$(".header .header-r>li").mouseleave(function() {
		$("a.more", this).removeClass("cur");
		$("ul.sub", this).hide();
	})
	$(".header .header-r ul.sub>li").mouseover(function() {
		if($("ul.m_sub", this)[0])
		{
			$("ul.m_sub", this).show();
			var l = $("ul.m_sub", this).offset().left;
			var w = $("ul.m_sub", this).width();
			if ((w + l) > $(window).width()) {
				$("ul.m_sub", this).css({
					"right": "100%",
					"left": "auto"
				});
			}
		}
	})
	//瀵艰埅榧犳爣鐐瑰嚮
	$(".header .header-r ul.sub>li").mouseleave(function() {
		$("ul.m_sub").hide();
	});
	$(".header .header-r>li>a.more").click(function() {
		$(this).parent().mouseover();
		return false;
	})
	$(document).click(function(e) {
		var target = $(e.target);
		if (target.closest(".header .header-r>li").length != 0) return;
		$("a.more").removeClass("cur");
		$("ul.sub").hide();
	})
	//$(".header .header-r ul.sub-icon>li>a").click(function() {
		//$(this).parent().mouseover();
		//return false;
	//})
	$(document).click(function(e) {
		var target = $(e.target);
		if (target.closest(".header .header-r ul.sub>li").length != 0) return;
		$("ul.m_sub").hide();
	})
});
