//参数说明：
//tabList:包裹选项卡的父级层
//tabTxt :包裹内容层的父级层
//options.currentTab:激活选项卡的序列号
//options.defaultClass:当前选项卡激活状态样式名，默认名字为“active”
var isfocus,oldi=0;
$.fn.tabs = function(tabList,tabTxt,options){
	var _tabList = $(this).find(tabList);
	var _tabTxt = $(this).find(tabTxt);
	
	//为了简化操作，强制规定选项卡必须用li标签实现
	var tabListLi = _tabList.find("li");
	var defaults = {currentTab:0,defaultClass:"active"};
	var o = $.extend({},defaults,options);
	_tabList.find("li:eq("+o.currentTab+")").addClass(o.defaultClass);
	
	//强制规定内容层必须以div来实现
	_tabTxt.children("div").each(function(i){
		$(this).attr("id","div"+i);						  
	}).eq(o.currentTab).css({"display":"block"});
	
	tabListLi.each(
		function(i){
			$(tabListLi[i]).mouseover(
				function(){
					if($(this).className != o.defaultClass)
					{
						$(this).addClass(o.defaultClass).siblings().removeClass(o.defaultClass);
					}
					_tabTxt.children("div").eq(i).css({"display":"block"}).siblings().css({"display":"none"});
				}
			)
		}
	);
	return this;
};


function onloadimg(){
    $(".inrow li img,.inrow .img img,.inrow dt img,.listhot img").each(function(){ 
		var swidth = $(this).attr("width");
		var sheight = $(this).attr("height");

		if (swidth > 44 && sheight>50 &&swidth!=668&&swidth!=646) {
			$(this).attr("class","errorImagePic");
			//$(this).attr("src","1.jpg");
			$(this).error(function(){$(this).attr("class","errorImage");}); 
			$(this).load(function(){$(this).attr("class","emptyClass");});
		}
    });
}


//查找网页内宽度太大的图片进行缩放以及PNG纠正
function ReImgSize(){
	var maxwidth=600;   
    $(".cbox img").each(function(){ 
        if ($(this).attr("width") > maxwidth) {   
			$(this).attr("width","600");
			$(this).wrap("<a href='"+$(this).attr("src")+"' target='_blank' title='在新窗口打开图片'></a>");
		}
    });
 }

function focusBox(o){
	if(!o) return;
	var o='#'+o,i=0,delayRun=null,t=null,arr=[],len=$('.focusbox_list li').length;
	//增加按钮
	arr.push('<div class="focusbox_btn"><ul>');
	$(o).find('li a').each(function(i){
		arr.push('<li><a target="_blank" href="' + $(this).attr('href') + '">' + $(this).children('.title').html() +'</a></li>');
	});
	arr.push('</ul></div>');
	$(o).append(arr.join(''));
	
	var _ullist = $('.focusbox_list > ul');
	var _litag = $('.focusbox_btn li');
		_litag.each(function(ni,n){
			$(this).bind("mouseover",function(){
			   setTimeout(function(){addCurrent(ni)},50);
			});
		});
	var timeobj,autotime;

	function init(){
		ni=((i+1)<len)?i+1:0;
		addCurrent(ni);
	}
	//切换
	function addCurrent(ni){
		_litag.removeClass('current').eq(ni).addClass('current');
		var totop = -300*ni;
		clearInterval(timeobj);
		timeobj = setInterval(function(){
			var stop = parseInt(_ullist.css("margin-top"));
				setppx=Math.abs(totop-stop)/6;
				setppx=(setppx>3)?setppx:3;
				stop+=(totop>stop)?setppx:-setppx;
				stop = (Math.abs(totop-stop)<4)?totop:Math.round(stop);
				_ullist.css("margin-top",stop+"px");
			if (stop==totop)clearInterval(timeobj);
		},10);
		i=ni;
	}
	$(o).hover(function(){
		clearTimeout(autotime);
		},function(){
		autogo();
		});
	var autogo=function(){
		autotime = setTimeout(function(){init();autogo();},3000);
	}
	addCurrent(0);
	autogo();

}

function moveElement(elementID,final_x,final_y,interval) {
	  var elem = $(elementID);
	  clearTimeout(isfocus);
	  var xpos = parseInt(elem.css("left"));
	  var ypos = parseInt(elem.css("top"));
	  
		
	  if (xpos == final_x && ypos == final_y) {
			return true;
	  }
	  if (xpos < final_x) {
		var dist = Math.ceil((final_x - xpos)/10);
		xpos = xpos + dist;
	  }
	  if (xpos > final_x) {
		var dist = Math.ceil((xpos - final_x)/10);
		xpos = xpos - dist;
	  }
	  if (ypos < final_y) {
		var dist = Math.ceil((final_y - ypos)/10);
		ypos = ypos + dist;
	  }
	  if (ypos > final_y) {
		var dist = Math.ceil((ypos - final_y)/10);
		ypos = ypos - dist;
	  }
	  elem.css("left",xpos + "px");
	  elem.css("top",ypos + "px");
	  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
	  isfocus = setTimeout(repeat,interval);
}

function shownav(){
	var isreclass = false;
	$('.nav li').hover(function(){
		if ($(this).attr("class")!="active") isreclass = true;
			$(this).addClass("active");
	},function(){
		if (isreclass)$(this).removeClass("active");
		isreclass = false;
	});
}

function searchbox(){
	var keystr;
	$("#searchkeyword").focus(function(){
	  keystr=$(this).val();
	  if (keystr=="请输入关键字..."){
		$(this).val("");
		//$(this).css("color","#fff");
	  }

	});
	$("#searchkeyword").blur(function(){
		keystr=$(this).val()*1;
	  if (keystr<1){
		$(this).val("请输入关键字...");
		$(this).css("color","#1363aa");
	  }
	});
}
function setstarconfig(){
	var arrstr = new Array("不详","一星","二星","三星","四星","五星");
	var arrlen = arrstr.length
	$(".star").each(function(){
		var strnum = 0;
		var nobj = $(this).find("div");
		var sstr = nobj.html();
		for (var i=0 ;i<arrlen;i++){
			if (arrstr[i]==sstr){
				strnum = i;
				break;
			}
		}
		strnum = strnum*2*10;
		nobj.css("width",strnum+"%");
	});
}


function AddFavorite(sURL, sTitle){
    try{
        window.external.addFavorite(sURL, sTitle);
    }

    catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }

        catch (e){
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//设为首页

function SetHome(obj,vrl){
	try{            
	   obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}
	catch(e){
		if(window.netscape) {
			try { 
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e) {
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
     }
}

function showbei(){
		sbei='<div id="beibox"><div class="bei b1 beil"></div>';
		sbei+='<div class="bei b2 beil"></div>';
		sbei+='<div class="bei b3 beir"></div>';
		sbei+='<div class="bei b4 beir"></div>';
		sbei+='<div class="bei b5 beir"></div></div>';
		$(".tbody").append(sbei);
		ishowbei();
}
function ishowbei(){
	var allwidth = $("body").width();
		$(".beil").css("margin-left",allwidth/2-480-80+"px");
		$(".beir").css("margin-left",allwidth/2+480+"px");
	if (allwidth>1120){
		$("#beibox").show();
	}else{
		$("#beibox").hide();
	}

}


function postBadGood(ftype,fid)
{
	var taget_obj = document.getElementById(ftype+fid);
	var saveid = GetCookie('badgoodid');
	if(saveid != null)
	{
		var saveids = saveid.split(',');
		var hasid = false;
		saveid = '';
		j = 1;
		for(i=saveids.length-1;i>=0;i--)
		{
			if(saveids[i]==fid && hasid) continue;
			else {
				if(saveids[i]==fid && !hasid) hasid = true;
				saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
				j++;
				if(j==10 && hasid) break;
				if(j==9 && !hasid) break;
			}
		}
		if(hasid) { alert('您刚才已表决过了喔！'); return false;}
		else saveid += ','+fid;
		SetCookie('badgoodid',saveid,1);
	}
	else
	{
		SetCookie('badgoodid',fid,1);
	}
	myajax = new DedeAjax(taget_obj,false,false,'','','');
	myajax.SendGet2("{dede:field name='phpurl'/}/feedback.php?aid="+fid+"&action="+ftype+"&fid="+fid+"&time="+new Date());
}

jQuery(function($) {
	setstarconfig();
	onloadimg();
	ReImgSize();
	showbei();
});

$(window).resize(function(){
	ishowbei();
});

function bnavm(typeid,topid,moresite){
	typeid = (!typeid)?0:typeid;
	if (topid='101'){
		$("#bn"+typeid).addClass("active");
	}else{
		var nowcatid=(typeid=='0')?0:(moresite=='0')?0:(topid!='0')?topid:typeid;
		$("#bn"+nowcatid).addClass("active");
	}
	$(".bnavm li").each(function(i,n){
		if ($(this).attr("class")!="active"){
			$(this).hover(function(){
				$(this).addClass("active");
			},function(){
				$(this).removeClass("active");
			});
			
		}
	});

}


//PNG图片透明
function correctPNG()  
{ 
for(var i=0; i<document.images.length; i++) 
{ 
  var img = document.images[i] 
  var imgName = img.src.toUpperCase() 
  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
  { 
   var imgID = (img.id) ? "id='" + img.id + "' " : "" 
   var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
   var imgStyle = "display:inline-block;" + img.style.cssText  
   if (img.align == "left") imgStyle = "float:left;" + imgStyle 
   if (img.align == "right") imgStyle = "float:right;" + imgStyle 
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
   var strNewHTML = "<span " + imgID + imgClass + imgTitle 
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
   img.outerHTML = strNewHTML 
   i = i-1 
  } //LIEHUO.NET
} 
} 
window.attachEvent("onload", correctPNG); 

