$(function(){//ad
 var len  = $(".slider > li").length;
 $(".num li").slice(len).remove();
 if(len<2){
	$(".num").remove();
	return;
 }
 var index = 0;
 var adTimer;
 $(".num li").click(function(){
	index  =   $(".num li").index(this);
	showImg(index);
 }).eq(0).click();	
 $('.banner').hover(function(){
		 clearInterval(adTimer);
	 },function(){
		 adTimer = setInterval(function(){
			index++;
			if(index==len){index=0;}
			showImg(index);	
		  } , 3000);
 }).trigger("mouseleave");
});
function showImg(index){
	var adHeight = $(".banner").height();
	$(".slider").stop(true,false).animate({top : -adHeight*index},"normal");
	$(".num li").removeClass("on").eq(index).addClass("on");
};
$(function(){
	$(".slide").hover(function(){//百贸通
		$(".slide").children("ul").show();
		$(".slide").children("a").addClass("hover");
	},function(){
		$(".slide").children("ul").hide();
		$(".slide").children("a").removeClass("hover");
	});
	if($(".gallery img").attr("src")!="/html/photo1/noimg.gif")	//图片放大				   
	{
		$(".gallery a").lightBox();
	}
	else{
		var html=$(".gallery a").html();
		$(".gallery a").remove();
		$(".gallery").append(html);
		$(".gallery span").remove();
	};
	$("#select").bind("click",function(){
		$(".option").show(1,function(){
			$(document).bind("click.global",function(){
				$(".option").hide();
				$(document).unbind("click.global");
			});
		});
	});
	$(".option li").click(function(){
		$("#select").text($(this).text());
		$(".option").hide();
	});
	$(".option li").hover(
		function(){$(this).addClass("hover")},
		function(){$(this).removeClass("hover")}
	)
});
function SelectPerPageItem(num,obj,url)
{
	$("#peritem")[0].value = num;
	$("#perPageItemsForm")[0].action = document.URL;
	$("#perPageItemsForm")[0].submit();
}

function gotoPage(num)
{
	var pageno = $("#pageno")[0].value;
	if(pageno.search("^-?\\d+$")!=0==true)
	{
		alert("请输入有效页码");
		return false;
	}
	else if(pageno > num || pageno <= 0)
	{
		alert("请输入有效页码");
		return false;
	}
	$("#gotoPageForm")[0].action = document.URL;
	$("#gotoPageForm")[0].submit();
}

//图片加载自适应
function SetImg(obj,maxW,maxH)
{
	var imgH=obj.height;
	var imgW=obj.width;

	if(obj.height>maxH)
	{
		obj.height=maxH;
		obj.widht=(obj.width*(maxH/imgH));
		imgH=maxH;
		imgW=obj.width;
	}
   
	if(obj.width>maxW)
	{
		obj.width=maxW;
		obj.height=(maxW/imgW)*imgH;
		imgW=maxW;
		imgH=obj.height;
	}
	if(obj.style.cssFloat)
	{
		obj.style.cssFloat='left';
	}
	else
	{
		obj.style.styleFloat='left';
	}
	obj.style.marginTop=(maxH-obj.height)/2+'px';
	obj.style.marginLeft=(maxW-obj.width)/2+'px';
}
//产品图片加载自适应
function SetAdditionImg(obj,maxW,maxH)
{
	var imgH=obj.height;
	var imgW=obj.width;

	if(obj.height>maxH)
	{
		obj.height=maxH;
		obj.widht=(obj.width*(maxH/imgH));
		imgH=maxH;
		imgW=obj.width;
	}
   
	if(obj.width>maxW)
	{
		obj.width=maxW;
		obj.height=(maxW/imgW)*imgH;
		imgW=maxW;
		imgH=obj.height;
	}
	if(obj.style.cssFloat)
	{
		obj.style.cssFloat='left';
	}
	else
	{
		obj.style.styleFloat='left';
	}
	obj.style.marginLeft=(maxW-obj.width)/2+'px';
}
//头部搜索关键字检测
function checkKeyword(form){
    var keyword = form.keyword.value;
    var k_length = keyword.length;
    var trim_keyword = $.trim(keyword);
    var trim_k_length = trim_keyword.length;
    var noword = "请输入搜索关键字";
    var longsearch = "请输入少于50个字符的搜索关键字。";
    var pattern = /^\s+$/;
    
    if(k_length == 0 || pattern.test(keyword)){//检测空格
        alert(noword);
        return false;
    }else if(trim_k_length < 1){
        alert(shortnotice);
        return false;
    }else if(trim_k_length > 50){
        alert(longsearch);
        return false;
    }else if(keyword == '请输入产品名称'){
        return false;
    }

    return true;
}

function changeSearchSelect(type,domain)
{
    if(type == 1){
        $('#form_search').attr('action', domain+'/manufacturer/suppliers.htm');
    }else if(type == 2){
        $('#form_search').attr('action', domain+'/purchase/buy.htm');
    }else if(type == 3){
        $('#form_search').attr('action', domain+'/import/export.htm');
    }else if(type == 0){
        $('#form_search').attr('action','');
    }
}
