(function(){
var categoryCtrlObj,categoryListObj,categoryListTitleObj,categoryCache = new Array(),fatherObj,totAlist,tempAobj;
var current = null;
var bingList;
var arrowup;
LetterCategory = {
/**
* 初始化类目筛选功能。
* categoryCtrlId String 类目筛选功能控制层ID
* categoryListId String 类目筛选功能显示层ID
*/
initAdv:function(categoryCtrlId,categoryListId,fatherId){
categoryCtrlObj = document.getElementById(categoryCtrlId);
categoryListObj = document.getElementById(categoryListId);
fatherObj = document.getElementById(fatherId);
arrowup = document.getElementById("arrowup");
this.eventBindingAdv(categoryCtrlObj,"li");
categoryListObj.onmouseover = function(){
this.style.display = "block"
}
categoryListObj.onmouseout = function(){
LetterCategory.hiddenResult();
}
categoryCtrlObj.onmouseout = function(){
LetterCategory.hiddenResult();
}
categoryCtrlObj.onmouseover = function(){
if(current) current.className = "c_l";
categoryListObj.style.display = "block";
arrowup.style.display = "block";
}
},
/**
* 给bindObj对象下的标签名为tagsName绑定onmouseover事件。
* bindObj Object
* tagsName String 标签名
*/
eventBindingAdv:function(bindObj,tagsName){
bingList = bindObj.getElementsByTagName(tagsName);
for(var i=0;i<bingList.length;i++){
bingList[i].setAttribute("pos",3+i*22);
bingList[i].onmouseover = this.showResult;
bingList[i].onclick = function(){
try{
aliclick(this,'?tracelog=chinaindex_leimu_sx_onclick');
}catch(e){}
}
}
},
/**
* 给bindObj对象下的标签名为tagsName绑定onmouseover和onmouseout事件。
* bindObj Object
* tagsName String 标签名
*/
eventBinding:function(bindObj,tagsName){
var bingList = bindObj.getElementsByTagName(tagsName);
for(var i=0;i<bingList.length;i++){
if(bingList[i].href){
bingList[i].onmouseover = this.showResult;
}
}
},
/**
* 显示类目结果层。
*/
showResult:function(){
if(current!=null){
current.className = "l";
}
categoryListObj.style.display = "block";
current = this;
var left = current.getAttribute("pos");

arrowup.style.left = left-4 + "px";
arrowup.style.display = "block";
current.className = "c_l";
current.style.height= "14px";
var categoryListStr_1 = LetterCategory.getCategoryListStr(current.innerHTML);
LetterCategory.setCategoryContent(categoryListStr_1,current.innerHTML);
},
/**
* 隐藏类目结果层。
*/
hiddenResult:function(){
categoryListObj.style.display = "none";
arrowup.style.display = "none";
if(current){
current.className = "l";
}
},
/**
* 根据字母获取相应的类目字符串,如果缓存中已经有这个类目字符串,
* 则从缓存中读取，如果没有则到页面中去提取新的数据，并把得到的新的数据放到缓存中.
* letter String 字母
*/
getCategoryListStr:function(letter){
var tempCategoryListStr = this.getCategoryListStrFromCache(letter);
if(tempCategoryListStr){
return tempCategoryListStr;
}else{
tempCategoryListStr = this.getCategoryListStrFromPage(letter);
this.addCategoryListStrToCache(tempCategoryListStr,letter);
if(tempCategoryListStr){
return tempCategoryListStr;
}
}
},
/**
* 根据字母从页面中提取相关数据.
* letter String 字母
*/
getCategoryListStrFromPage:function(letter){
if(!totAlist) totAlist = fatherObj.getElementsByTagName("a");
var tempCategoryListStr ="";
for(var i=0;i<totAlist.length;i++){
if(totAlist[i].className == "l_"+letter.substring(0,1)){
var tempUrl = "";
if(totAlist[i].href.indexOf("?")!=-1&&totAlist[i].href.indexOf("=")!=-1){
continue;
}else{
tempUrl = escape(totAlist[i].getAttribute("href")).substring(9,escape(totAlist[i].href).length);
}
tempCategoryListStr = tempCategoryListStr + "<a href=\"http://"+tempUrl+"\">"+totAlist[i].innerHTML+"</a>";
}
}
return tempCategoryListStr;
},
/**
* 根据字母从缓存中获取相应的类目字符串.
* letter String 字母.
*/
getCategoryListStrFromCache:function(letter){
for(var i=0;i<categoryCache.length;i++){
if(categoryCache[i].id == letter){
return categoryCache[i].value;
}
}
return null;
},
/**
* 把新的类目字符串加载到缓存中去.
* categoryListStr String 类目字符串.
* letter String 字母.
*/
addCategoryListStrToCache:function(categoryListStr,letter){
try{
categoryCache[categoryCache.length] = {id:letter,value:categoryListStr};
}catch(e){this.printError(e+":Set cache error!")}
},
/**
* 给类目结果层设置内容。
* categoryListStr String 类目列表字符串
*/
setCategoryContent:function(categoryListStr,letter){
if(categoryListObj){
if(!categoryListStr){categoryListStr = "<div style=\"text-align:center;\padding-top:3px;\">没有拼音字母\“<span style='color:#ff7300;font-size:16px;font-weight:bold'>"+letter+"</span>\”开头的类目！</div>";}
categoryListObj.innerHTML = categoryListStr;
this.addListen(categoryListObj);
}
},
addListen:function(categoryListObj){
var categoryAList = categoryListObj.getElementsByTagName("a");
for(var i=0;i<categoryAList.length;i++){
categoryAList[i].onclick = function(){
try{
aliclick(this,'?tracelog=chinaindex_leimu_sx');
}catch(e){}
};
}
},
/**
* 错误提示。
* errorMsg String 错误提示内容
*/
printError:function(errorMsg){
alert(errorMsg);
}
}
})();
