//函数区域

//function bgpos
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);




//函数调用及自定义


var OK = {};// 定义命名空间

// 主导航
OK.mainNav = function(){
	var tout;
	var uiNavBtn = $("#mainNav>ul>li");
	var uiNavUl=$("#mainNav li ul");
	var strA='<span class="spanG"></span>';
	uiNavBtn.prepend(strA);

	var muSlideDown = function(btn){
		tout = setTimeout(function(){
			btn.find('span').addClass('spanN').css({backgroundPosition: "0 2px"})
			.animate({height:'37px'},300,function (){
				$(this).animate({backgroundPosition:"(0px 6px)"},{duration:200})
			});
		btn.addClass("on").find("ul").slideDown(400)},200);
		//tout = setTimeout(function(){btn.find("ul").slideUp("fast")},500);
	}
	var muSlideUp = function(btn){
		clearTimeout(tout);
		btn.removeClass("on").find("ul").slideUp("fast");
		btn.find('span').animate({height:0},'fast',function () {
			$(this).removeClass('spanN').css({backgroundPosition: "0 2px"});
			});
		//tout = setTimeout(function(){btn.find("ul").slideDown("fast")},500);
	}
	uiNavBtn.each(function(){
		$(this).bind("mouseenter",function(evt){var _a=$(this); muSlideDown(_a);});
		$(this).bind("mouseleave",function(evt){var _a=$(this); muSlideUp(_a);});
		//if($(this).attr("id") == "mn5"){
		//	$(this).click(function(){return false;});
	//	}
	});
}

////////////////表格斑马样式
OK.tableSty = function(type){
	if(type == "tableTyp1"){
		$("table."+type+" tr:even").addClass("dark");
		$("table."+type+" tr:odd").addClass("light");
	}
}


////////////////左侧导航高亮
OK.sideNavHighlight = function(){
	var hl = $("li.on");
	if(hl.length>0){
		hl.parents("li").addClass("on");
	}
}

////////////////产品标签
OK.pdTab = function(tabs,tabCons){
	tabs.each(function(i){
		$(this).bind("click", function(){
			tabs.removeClass("on");
			tabs.eq(i).addClass("on");
			tabCons.hide();
			tabCons.eq(i).fadeIn();
			return false;
		});
	});
}

//表格斑马
OK.tableZebra = function(className){
	$(className+" tr:even").each(function(i){
		$(this).css({"background-color":"#f8f7f7"});	
	});
}
//////////////////////////内容防拷贝（IE）
function noSelect() {
	return false;
} 
function rClick() { 
	if(event.button==2) alert("对不起，鼠标右键被屏蔽了。");
}
function CtrlKeyDown(){ 
	if(event.ctrlKey) return false;
}
function forbidCopy(){
	document.onkeydown=CtrlKeyDown; 
	document.onselectstart=noSelect; 
	document.onmousedown=rClick; 
}

function login() {
		var lia = $("ul#topBar li.tb2>a");
		var lip = $("ul#topBar li.tb2>p");
		var lis = $("ul#topBar li.tb2>p>span");
		lia.click(function(){lip.fadeIn()});
		lis.click(function(){lip.fadeOut("fast")});
}

OK.pageInit = function(){
	if($("#mainNav").length>0){
		OK.mainNav();
	}
	if($("table.tableTyp1").length>0){
		OK.tableSty("tableTyp1");
	}
	if($("#subNav").length>0){
		OK.sideNavHighlight();
	}
	if($("ul.tabSty1").length>0){
		OK.pdTab($("ul.tabSty1 li"),$(".tabCon"));
	}
	if($("table.tableSty1").length>0){
		OK.tableZebra("table.tableSty1");
	}
	forbidCopy();
	if($("ul#topBar li.tb2>p").length){
		login();
	}
}


$(document).ready(function(){
	OK.pageInit();
});




