function cl_ad(obj){
	$('#'+obj).hide();
}

function reContent(con1,con2){
	$(con1).html($(con2).html());
	$(con2).html("");
}

function dl_ad(file,url,widthnum,heightnum,type,topnum,rightnum,id){//id =right_ad1
	if(type=="flash"){
		var fo = new SWFObject(file, id, widthnum, heightnum, "7");
		fo.addParam("wmode", "opaque");
		str = fo.getSWFHTML();
	}else if(type == "img"){
		var str = '<a href="' + url + '" target="_blank"><img src="' + file + '" width="' + widthnum + '" height="' + heightnum + '" border="0" /></a>';
	}
	heightnum += 20;
	var codes = '<div id="'+ id +'" style="position:absolute;top:'+ topnum +'px;width:'+ widthnum +'px;height:' + heightnum + 'px;z-index:10000;right: '+ rightnum +'px;"><div id="inner_'+id+'" style="width:100%;">'+ str +'</div><div style="line-height:20px; background:#E9E9E9; text-align:right; padding-right:10px; float:none;cursor:pointer" onclick="cl_ad(\''+id+'\')">关闭</div></div>';
	return codes;
}


/**
* 轮替广告
*/
var loopAd = function(config)
{
	var self = this;
	this.con    = document.getElementById(config.con) || '';
	this.adFile = config.adFile || [];
	this.width  = config.width || 0;
	this.height = config.height || 0;
	this.timer  = config.timer || 1000;
	if (!this.con) {
		return false;
	}
	var ad = [];
	var i = 0;
	var show = function()
	{
		i = i < self.adFile.length ? i : 0;
		ad[i] = ad[i] || getAdHtml(self.adFile[i]);
		self.con.innerHTML = ad[i];
		i++;
	};
	
	var getAdHtml = function(adFile)
	{
		if (adFile.type == 'img') {
			return '<img src="' + adFile.src + '" width="' + self.width + '" height="' + self.height + '">';
		} else if (adFile.type == 'swf') {
			return (new SWFObject(adFile.src, '', self.width, self.height, '7')).getSWFHTML();
		} else {
			return false;
		}
	};
	
	this.run = function()
	{
		show();
		window.setInterval(show, this.timer);
	};
};


//添加收藏夹　兼容IE6.0、IE7.0、FIREFOX、Opera7＋
function add_favorite(obj){
	var url=document.location.href;
	var title=document.title;
	if (window.sidebar)
	{
		window.sidebar.addPanel(title,url,"");
	}
	else if( window.opera && window.print )
	{
		obj.setAttribute('rel','sidebar');
		obj.setAttribute('href',url);
		obj.setAttribute('title',title);
	}
	else if (document.all) {
		window.external.AddFavorite(url,title);
	}
	return false;
}
//读取cookie
function getCookie(cookieName){
	   var cookieString = document.cookie;
	   var start = cookieString.indexOf(cookieName+"=");
		if (start ==-1) return null;
		start+=cookieName.length+1;
		var end = cookieString.indexOf(';', start);
		if (end == -1) return unescape(cookieString.substring(start));
		else return unescape(cookieString.substring(start, end));
}

window.onresize = function(){
	var groupoffsets = $('#group_link').offset();
	setDivPosition($("#group_list"),groupoffsets.left,groupoffsets.top+12);
}
function setDivPosition(obj,x,y){
	obj.css({left:x,top:y});
}

//显示|产品
function show_price(){
	var offsets = $('#price_area').offset();
	var g = $('#group');
	g.show();
	g.css({left: -600, top: offsets.top})
	g.animate({left:offsets.left,top:offsets.top , opacity: 0.95}, 1500);
}
function hide_price(){
	var offsets = $('#price_area').offset();
	$('#group').animate({left:offsets.left+880, opacity : 0}, 1000 , function(){ $('#group').hide()});
}

function ch_list(clickobj,chobj){
	$(chobj).slideToggle();
	$(clickobj).toggleClass("btn2");
}
//顶部CNET链接
$(function(){
	var gplist = $('#group_list');
	var gplinkoffset = $('#group_link').offset();
	if(typeof gplinkoffset == 'undefined') return;
	gplist.css({left:gplinkoffset.left,top:gplinkoffset.top+12});
	$('#group_link').hover(
		function(){gplist.slideDown();},
		function(){gplist.slideUp();})
	}
);

//左侧菜单
$(function(){ajaxtabs(["#onnb","#onmb","#onmp3","#oncpu","#onlcd"])});

//根据屏幕分辨率显示不同样式
$(function(){
	var user_width = window.screen.width;
	var rightad = $("div[id^=right_ad]");
	if(user_width<1100 && $("div[id^=right_ad]").length>0){
		var temptop = 45;
		rightad.each(function(i){
			var offsets = $(this).offset();
			if(offsets!=temptop){
				$(this).animate({top:temptop},1500);
			}
			temptop += this.offsetHeight+10;
		});
		$('.page_width,.pw').css({float:'left', margin:'0px 0px 0px 5px '});
		
	}else if(user_width>=1100){
		var temptop1 = temptop2 = 45;
		move_adnum = Math.floor(rightad.length/2);
		rightad.each(function(i){
			var offsets = $(this).offset();
			if(i>=rightad.length-move_adnum){
				$(this).animate({left:5,top:temptop2},1500);
				temptop2 += this.offsetHeight+10;
			} else {
				if(offsets!=temptop1){
					$(this).animate({top:temptop1},1500);
				}
				temptop1 += this.offsetHeight+10;
			}
		});
	}
});

//搜索提示
$(function(){
	$("#keywords").suggest("search.php?act=getsearchSuggest",{
		resultsClass: "suggest alpha95",
		selectClass: "over"
	})
})