﻿/********************************************************************
 * tabpage
 ********************************************************************/
tabpage = function(name,tab)
{
this.name = name;
this.tab = typeof(tab)=='string'?document.getElementById(tab):tab;
this.lists = new Array();
this.pages = new Array();
this.links = new Array();
this.cur = -1;//the current page
this.pre = -1;//the previous page
this.isblend = false;
this.delt = 30;//the deltal time
this.cura = 0;//the current alpha
this.prea = 0;//the previous alpha
this.curh = 0;//the current height
this.desh = 0;//the destination height
this.times = 10;//the blend times
this.delta = 0;//
this.delth = 0;//
this.contain = null;
this.time = null;
this.tab.className = 'tabpage';
divs = this.tab.getElementsByTagName('div');
for (i=0;i<divs.length;i++)
{
o = divs[i];
if (o.id=='$nav') { 
o.className = 'tabnavstyle'; 
lis = o.getElementsByTagName('li'); 
for (k=0;k<lis.length;k++){ li=lis[k]; this.lists[parseInt(li.id)] = li; }
}
if (o.id=='$back') { o.className = 'tabnavback';}
if (o.id.substring(0,7)=='$layer_') { o.className = 'tabpagestyle'; j = parseInt(o.id.substring(7,o.id.length)); this.pages[j]=o;}
if (o.id=='$contain') { o.className = 'tabcontain'; this.contain = o;}
if (o.id=='$other') { o.className = 'tabother';}
}
this.add = function(li,page){ 
this.lists[this.lists.length] = typeof(li)=='string'?document.getElementById(li):li;
this.pages[this.pages.length] = typeof(page)=='string'?document.getElementById(page):page;
};
this.click = function(i){
if (this.cur==i || this.isblend) return;
this.pre = this.cur;
this.cur = i;
this.cura = 0;
this.prea = 100;
this.isblend = true;
this.curh = 0;
if (this.pre>=0) this.curh = this.pages[this.pre].offsetHeight;
this.desh = this.pages[this.cur].offsetHeight;
this.delta = 100/this.times;
this.delth = Math.floor((this.desh - this.curh)/(this.times));
this.pages[this.cur].style.visibility = 'visible';
this.morelink = document.getElementById('$tab_more_link');
this.morelink.href = this.links[i];
this.show();
};
this.over = function(){};
this.out  = function(){};
this.show = function(){
//-----------------close the timer-------------------------
if (this.time)
{
try{
clearTimeout(this.time);
this.time = 0;
}catch(e){ this.time = 0;}
}
//---------------------------------------------------------
var div = this.lists[this.cur].getElementsByTagName('div')[0];
var p = this.lists[this.cur].getElementsByTagName('p')[0];
var pdiv = null;
var pp = null;
if (this.pre>=0) 
{
pdiv = this.lists[this.pre].getElementsByTagName('div')[0];
pp = this.lists[this.pre].getElementsByTagName('p')[0];
}
//----------------when alpha>100---------------------------
this.cura = this.delta + this.cura;
if (this.cura>=100) {
this.cura = 0; 
this.alpha(div,100);
this.alpha(p,0);
this.alpha(this.pages[this.cur],100);
if (this.pre>=0){ 
this.alpha(pdiv,0); 
this.alpha(pp,100);
this.alpha(this.pages[this.pre],0); 
this.pages[this.pre].style.visibility = 'hidden'; }
this.pre = -1;
this.time = 0;
this.contain.style.height = this.desh+'px';
this.curh = 0;this.desh = 0;this.delth = 0;
this.isblend = false;
return; 
}
//----------------when alpha>100---------------------------
//----------------when alpha<100---------------------------
this.alpha(this.pages[this.cur],this.cura);
this.alpha(div,this.cura); 
this.alpha(p,100-this.cura); 
//the height
this.curh = Math.floor(this.curh*0.5+this.desh*0.5); 
if (this.delth>0 && this.curh>this.desh) this.curh = this.desh;
if (this.delth<0 && this.curh<this.desh) this.curh = this.desh;
this.contain.style.height = this.curh+'px';
//the height
if (this.pre>=0){ 
this.prea = this.prea - this.delta; 
if (this.prea<=0) {
this.prea = 0; 
this.alpha(pdiv,0);
this.alpha(pp,100); 
this.alpha(this.pages[this.pre],0); 
this.pages[this.pre].style.visibility = 'hidden';
this.pre = -1;
} 
else 
{
this.alpha(pp,100-this.prea);
this.alpha(this.pages[this.pre],this.prea);
this.alpha(pdiv,this.prea);
}
}
//----------------when alpha<100---------------------------
this.time = setTimeout(this.name+'.show()',this.delt);
};
this.init = function(){
for (m=0;m<this.lists.length;m++)
{ li = this.name+'.lists['+m+'].onclick = function(){ '+this.name+'.click('+m+');};';
eval(li); 
var div = this.lists[m].getElementsByTagName('div')[0];
if (div)
{
this.alpha(div,0);
}
var p = this.lists[m].getElementsByTagName('p')[0];
if (p)
this.alpha(this.pages[m],0);
this.pages[m].style.visibility = 'hidden';
}
//this.tab.style.width = (screen.width-80) + 'px';
};
this.alpha = function (element, opacity){
var isIE = (window.navigator.userAgent.indexOf("MSIE") != -1)?true:false;
var isGO = (window.navigator.userAgent.indexOf("Chrome") != -1)?true:false;
var isFF = (window.navigator.userAgent.indexOf("Firefox") != -1)?true:false;
if (isIE){ element.style.filter = "alpha(opacity=" + opacity + ")";}
else if(isGO) {
element.style.Opacity = opacity/100;
}
else {
element.style.MozOpacity = opacity/100;
}
};
this.reset = function(){
if (this.isblend) return;
if (this.cur<0) this.cur = 0;
this.contain.style.height = (this.pages[this.cur].offsetHeight) + 'px';
};
};