// JavaScript Document
function init_Index_Tabs(){
	//资讯切换
/*	TabsSwitcher({
		TabSelect: DefaultTabStyle.TabSelect,
		TabCommon: DefaultTabStyle.TabCommon,
		Tabs: "#knowledge .title li",
		Contents: "#knowledge .content .content01"
	});
*/
	//商业机会切换
	TabsSwitcher({
		TabSelect: 's',
		Tabs: "#Main_Business .TitleNav .Title li",
		AttachEvent: function(){
			GetAjaxData_BusinessInfo(escape($(this).attr('id').replace("bcid_", "")));
		}	
	});
	
	//资讯切换
	TabsSwitcher({
		TabSelect: 's',
		Tabs: "#Main_App .MenuNav li",
		Contents: "#Main_App .ContentNav .Content"
	});


	//Onload时显示所有类别的商业机会
	GetAjaxData_BusinessInfo(0);
}


/**
TabsSwitcher v1.0 QXV0aG9yOiBOb3JtIFJlbg== On jQuery
Eg:
	DefaultValue JSON Object:
		var DefaultTabStyle = {
			TabSelect: 'OnSelectCssStyle',
			TabCommon: 'UnOnSelectCssStyle'
		};
	How to invoke:
		TabsSwitcher({
			TabSelect: 'OnSelectCssStyle',
			TabCommon: 'UnOnSelectCssStyle',
			Tabs: "jQuery Select String For Tabs",
			Contents: "jQuery Select String For Contents",
			AttachEvent: function(){
				Some Function.
			}
		});
*/
var DefaultTabStyle = {
	TabSelect: 'li2',
	TabCommon: 'li1'
};
function TabsSwitcher(option){

	var TabSelect = 'OnSelect';	//选中时的样式
	var TabCommon = null;		//未选中时的样式
	var NewsTabs = null;		//菜单项集合
	var NewsContents = null;	//内容项集合
	if(option.TabSelect!=undefined&&option.TabSelect!=''){
		var TabSelect = option.TabSelect;
	}
	if(option.TabCommon!=undefined&&option.TabCommon!=''){
		var TabCommon = option.TabCommon;
	}
	if(option.Contents!=undefined&&option.Contents!=''){
		NewsContents = $(option.Contents);
	}
	if(option.Tabs!=undefined&&option.Tabs!=''){
		NewsTabs = $(option.Tabs);	
	}
	else{
		return;	
	}
	NewsTabs.css({cursor:'pointer'});
	NewsTabs.mouseover(function(){
		NewsTabs.removeClass(TabSelect);
		if(TabCommon!=null){
			NewsTabs.removeClass(TabCommon);
			NewsTabs.not(this).addClass(TabCommon);
		};
		$(this).addClass(TabSelect);
		if(NewsContents!=null){
			NewsContents.not('.'+this.id).hide();
			$('.'+this.id).show();
		}
	});
	if(option.AttachEvent!=null){
		NewsTabs.mouseover(option.AttachEvent);
	};

}

var BusinessInfoClassId = null; //当前选中的商机id
var businessInfoOutputCount = 0;
var subSiteId = 0;
function GetAjaxData_BusinessInfo(tBCid){
	if(tBCid==BusinessInfoClassId){
		return;
	}
	else{
		BusinessInfoClassId = tBCid;
	}
	if(businessInfoOutputCount == 0 || subSiteId == 0){
	    var config = eval("("+$("#business_config").html()+")");
	    businessInfoOutputCount = config.count;
	    subSiteId = config.siteid;
	}
	//用ajax方法实现获得数据
	var bid = tBCid;
	var ContentRenderObj = $("#bs-con");

	$.ajax({
		url:"http://" + document.domain + "/ajax/BusinessHandler.ashx",
		data:"categoryid="+bid+"&siteid="+subSiteId+"&count="+businessInfoOutputCount,
		async:true,

		beforeSend:function(){
			ContentRenderObj.html('<li>数据加载中，请稍候...</li>');
		},
		success:function(_html){
			ContentRenderObj.html(_html);
			ContentRenderObj.slideDown("10000");
		},
		error:function(o){
			ContentRenderObj.html('<li>数据加载失败...</li>');
		}	
	});	
}

function init_SearchBox(){
	$("#SearchBox").autocomplete("/Ajax/Search_Helper.asp", {
		delay: 10,
		minChars: 1,
		matchSubset: 1,
		matchContains: 1,
		cacheLength: 10,
		formatItem: function(row){
			return row[0];
		}
	});
}




//精确导航弹出框
function init_Index_Precise(){

	//定义模板
	var Template = {
		precise: "<ul><li class='cata_title'>你要找的是不是如下产品：</li>{T:Content}<li class='unlook'><a href='{T:Url}' target='_blank'>找不到请点击这里&gt;&gt;</a></li></ul>",
		item: "<li><a href='/Navigate/product.aspx?pid={T:TagId}' target='_blank'>{T:TagName}</a></li>"
	};
	
	//获取jQuery Object
	var PreObj = $('#shade');

	//设置鼠标事件 <div class="precise">
	$("#Main_Catalog .Content li:has([class='precise'])").hover(														 
		function(){
			var liStyle = $(this).attr('class');
				liStyle = liStyle.replace("li1","");
				liStyle = liStyle.replace("li2","")
				liStyle = liStyle.replace(" ","")

			//判断li选取状态
			if(liStyle !="s"){
				$(this).append(PreObj);
				$(this).addClass('s');
				
				//获取精确导航单击跳转链接
				var Url_Precise = $(this).find('.precise a').attr('href');
				
				//获取ClassId
				var ClassId = null? 0 : Url_Precise.match(/\d+$/);
				if($("#div_"+ClassId).length>0){
					var divHTML=$("#div_"+ClassId).html();
					PreObj.html(divHTML);
				}
				else{
				
				//设置弹出层位置
				PreObj.css({right:-2+'px', top:29+'px'})
					//Ajax读取数据
					$.ajax({
						url:"/ajax/Precise-Div.ashx",
						data:"Classid="+ClassId,
						dataType:'json',
						async:true,
						cache: false,
						beforeSend:function(){
							var template_this = Template.precise;
							template_this = template_this.replace('{T:Content}','<li style=\"width:100%\">数据加载中<img src="/skins/tools/loading.gif"/></li>');
							template_this = template_this.replace('{T:Url}','');
							PreObj.html(template_this);
						},
						success:function(msg){
							var Items = '';
							if(msg.IsExist==1){
								$.each(msg.Items,function bindItem(i, item){
									var template_tag = Template.item;
									template_tag = template_tag.replace('{T:TagId}',item.TagId);
									template_tag = template_tag.replace(/{T:TagName}/g,item.TagName);
									Items += template_tag;
								})
							}
							else{
								Items = '<li style=\"width:100%\">本类标签数据正在整理.</li>';
							}
							var template_this = Template.precise;
							template_this = template_this.replace('{T:Content}',Items)
							template_this = template_this.replace('{T:Url}',Url_Precise)
							PreObj.html(template_this);
							$("#precise_show").append("<div id='div_"+ClassId+"'>"+template_this+"</div>")
						},
						error:function(){
							var failMessage ='数据加载失败';
							var template_fail = Template.precise;
							template_fail = template_fail.replace('{T:Content}',failMessage);
							$('#shade').html(template_fail);
						}	
					});
				}
			}
		},
		function(){
			$('#Main_Catalog .Content li').removeClass('s');
			PreObj.remove();
		}
	);
}




//分类导航弹出LOGO
function init_Index_ShowLogo(){
	var msgbox = $('#ShowLogoNav');
	msgbox.html('<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="pop-lefttop"></td><td class="pop-top"></td><td class="pop-righttop"></td></tr><tr><td class="pop-left"></td><td id="pop-con"></td><td class="pop-right"></td></tr><tr><td class="pop-leftbottom"></td><td class="pop-bottom"><div class="pop-arrow"></div></td><td class="pop-rightbottom"></td></tr></table>');
	var ShowPosition;
	$('#Main_Catalog .ContentNav ul li .list a').hover(
		function(){
			if($(this).find('span:first').html()!=null){
				if ($.browser.msie){
					ShowPosition = {
						left:0,
						top:0
					};
				}else{
					ShowPosition = {
						left:0,
						top:-7
					};
				}
				proshow(this);
			}
		},
		function(){
			msgbox.hide();
		}
	)
	function proshow(_id){
		var linktop = $(_id).offset();
		msgbox.show();
		msgbox.css({position:'absolute'});
		$('#pop-con').html($(_id).find('span:first').html());
		msgbox.css({
			left:(linktop.left+($(_id).width()-msgbox.width())/2)+'px',
			top:(linktop.top-(msgbox.height()+ShowPosition.top))+'px'
		});
	}
	
	msgbox.hover(
		function(){
			msgbox.show();
		},
		function(){
			msgbox.hide();
		}
	)
}

// JavaScript Document
function copyToClipBoard(){
	var clipBoardContent='这网站不错，快到里面看看啦...http://www.66csb.cn'; 
	window.clipboardData.setData("Text",clipBoardContent); 
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
}