// JavaScript Document
$(document).ready(function() {
	resizeMain();//自动调整框大
	ImgSize();
	imgFixPath($("#nv .home").attr('href'));
});



window.onresize = function(){resizeMain();}
function resizeMain(){	
	$(".wp.ah .main").css('height',(document.documentElement.clientHeight-162)+'px');
	$(".wp.ah .main .mshow").css('height',(document.documentElement.clientHeight-172)+'px');
	$(".wp .main>.mabg").css('height',$(".wp .main").css('height'));
	$(".wp").css('left',(document.documentElement.clientWidth-960)/2+'px');
	$(".is").css('height',document.documentElement.clientHeight+'px');
	//$("#news_info").css('top',(document.documentElement.clientHeight-$("#news_info").height()-47)+'px');
}
function openUrl(theurl){
	thetraget=$("#nv ."+theurl).attr('target');
	if(typeof(thetraget) == 'undefined'){
		location.href=$("#nv ."+theurl).attr('href');
	}else if(thetraget=='_blank'){
		window.open($("#nv ."+theurl).attr('href'))
	}
}
//首页特效开始
function loadInfo(){
	//$("#news_info").animate({opacity: '1'}, "slow");
	$("#news_info").fadeIn("fast", function() {
		newsDiv=$("#news_info")
		newsDiv.find(".main").hover(
		  function () {newsDiv.stop().animate({ height: '150px' });}, 
		  function () {newsDiv.stop().animate({ height: '30px' });}
		);
		newsDiv.find(".main .ntit .eff").mousemove(function() {
	 		c_page(this, newsDiv.find(".main .ntit .eff"), newsDiv.find(".main .nshow .eff"), 'se') ;
		});
    });
}

// 小广告滚动 gg_obj滚动的对像gg_lbtn 左转 gg_rbtn 右转  gd_sno显示的个数  gd_w宽度   gd_gno滚动的个数
function set_xgg_gd(gg_obj,gg_lbtn,gg_rbtn,gd_sno,gd_w,gd_gno){
	//gg_obj = $(".rel ul");
	gg_no = gg_obj.find("li").length;
	if(gg_no>gd_sno){				
		do_xgg_gd = function (rec_ggobj,rec_ggno,rec,rgd_sno,rgd_w,rgd_no) {
			rec_ggobj.stop(true,true);	clearTimeout(xgg_t);
			gg_w=-1*rgd_w*rgd_no;
			var startno = parseInt(rec_ggobj.css('left'))/gg_w;
			//alert(startno)
			switch (rec) {case 'L': 
				if (startno == 0) {rec_ggobj.css('left', rec_ggno * gg_w / rgd_no + 'px');
				rec_ggobj.animate({left : (rec_ggno/4-1) * gg_w + "px"}, "slow");
				} else {startno--;
				rec_ggobj.animate({left : startno * gg_w + "px"}, "slow");}
			break;case 'R':
				if (startno == rec_ggno/rgd_no) {rec_ggobj.css('left', 0 + 'px');	
				rec_ggobj.animate({left : 1 * gg_w + "px"}, "slow");
				} else {startno++;
				rec_ggobj.animate({left : startno * gg_w + "px"}, "slow");}
			break;}
			xgg_t = setTimeout(function() { do_xgg_gd(rec_ggobj,rec_ggno,'R',rgd_sno,rgd_w,rgd_no)}, 6000);
		}	
		gg_obj.find("li:lt("+gd_sno+")").each(function(i) { gg_obj.append('<li>' + $(this).html() + '</li>'); });
		gg_lbtn.click(function() { do_xgg_gd(gg_obj,gg_no,'L',gd_sno,gd_w,gd_gno); });//$(".rel .btnl")
		gg_rbtn.click(function() { do_xgg_gd(gg_obj,gg_no,'R',gd_sno,gd_w,gd_gno); });//$(".rel .btnr")
		xgg_t = setTimeout(function() { do_xgg_gd(gg_obj,gg_no,'R',gd_sno,gd_w,gd_gno)}, 6000);
	}
}


// 图片缩放
function ImgSize() {
	var _ImgSize=function (ImgD,theO){
		var is_oimg = $(ImgD);
		var is_modimg = new Image();
		is_modimg.src = is_oimg.attr("src");
		// 自动缩放图
		var iwidth=is_oimg.width(),iheight=is_oimg.height(),ImgD_width=0,ImgD_height=0;
		//alert(iwidth+'--'+iheight+'--'+i);
		var autoScaling = function() {				
			if(iwidth<0 || iheight<0) return;	
			if(is_modimg.width/is_modimg.height  >= iwidth / iheight){
				ImgD_width=iwidth;
				ImgD_height=Math.floor((is_modimg.height*iwidth)/is_modimg.width);		
				//alert('1 '+oimage.width+'--'+oimage.height+'--'+iwidth+'--'+iheight+'--'+ImgD_width+'--'+ImgD_height);
			}else{					
				ImgD_width=Math.floor((is_modimg.width*iheight)/is_modimg.height);
				ImgD_height=iheight;   			
				//alert('2 '+oimage.width+'--'+oimage.height+'--'+iwidth+'--'+iheight+'--'+ImgD_width+'--'+ImgD_height);		
			}			
			var runw=Math.floor((iwidth-ImgD_width)/2) , runh=Math.floor((iheight-ImgD_height)/2); 
			is_oimg.width(ImgD_width).height(ImgD_height).attr("alt",is_modimg.width+"×"+is_modimg.height);
			if(theO=='O')
			is_oimg.css('margin',runh+'px '+ runw+'px');
			else
			is_oimg.parent().css('margin',runh+'px '+ runw+'px');
			
		}
		// 处理ff下会自动读取缓存图片
		if (is_modimg.complete) {autoScaling();return;}
		$(is_modimg).load(function() {autoScaling();});
	}
	$(".autoSize img").each(function(i) {_ImgSize(this,'O');});
	$(".autoSizeP img").each(function(i) {_ImgSize(this,'P');});
}
// 窗口换页
function c_page(c_ifid, sci_obj, sci_sobj, sci_cssn) {
	sci_no = sci_obj.index(c_ifid);
	sci_obj.removeClass(sci_cssn).eq(sci_no).addClass(sci_cssn);
	sci_sobj.removeClass(sci_cssn).eq(sci_no).addClass(sci_cssn);
}
//修正图片地址
function imgFixPath(img_basepath){
	if(img_basepath!='/'){
		$("img").each(function(index) {
			img_oadd=$(this).attr('src');
			if(img_oadd.substr(0,1)=='/'){
				img_newadd=$(this).attr('src').replace(/\/Uploads\/upload/,img_basepath+"Uploads/upload");
				$(this).attr('src',img_newadd);
			}
		 });
	}
}
