/**
 * @author {tiger}
 */
var Class = {create:function(){return function(){this.init.apply(this,arguments)}}}
function bindFun(o,fun){var ar=Array.prototype.slice.call(arguments).slice(2);return function(){return fun.apply(o,ar);};};
function addEvent(o,s,fun){o.attachEvent?o.attachEvent("on"+s,fun):o.addEventListener(s,fun,false);}

var scrollDom= Class.create(); 
scrollDom.prototype = {
	init:function(el,node,options){
		this.o=$(el);
		this.tar = $(el,node)[0];
		this.opt = options || {};
		this.time = this.opt.time || 5000;
		this.autoPlay = this.opt.autoPlay || true;
		this.path = this.opt.path || 'top';
		this.from =null;
		this.to=null;
		this.n=0;
		this.t = 32;
		this.complete=false;
		this.distance = this.opt.distance || ((this.path == 'left' || this.path=='right') ? this.o.offsetWidth : this.o.offsetHeight);
		this.max = (this.path == 'left' || this.path=='right') ? this.tar.offsetWidth-this.o.offsetWidth : this.tar.offsetHeight-this.o.offsetHeight;
	},
	move:function(){
		this.from = parseInt(this.tar.style[this.path]) || this.tar['offset'+this.path.replace(/^[a-z]/,function(m){return m.toUpperCase();})];
		this.from = this.trans(this.from,this.to,this.n,this.t);
		this.tar.style[this.path] = Math.floor(this.from) +'px';
		this.n++;
		if(this.n==this.t){
			this.from = this.from.toString().replace(/^\-/,'');
			if(this.from >= this.max ){
				this.complete = true;
			}
			this.from= null;
			this.n=0;
			this.start();
			return;
		}
		setTimeout(bindFun(this,function(){
			this.move();
		}),32)
	},
	trans:function(from,to,n,t){
		from = (to-from) * (n+1)/t*(2-(n+1)/t) + from;
		return from;
	},
	start:function(){
		
		this.from = parseInt(this.tar.style[this.path]) || this.tar['scroll'+this.path.replace(/^[a-z]/,function(m){return m.toUpperCase();})];
		if(this.complete){this.reset();}
		this.to = this.path == 'left' || this.path =='top' ? this.from-this.distance : this.from+this.distance;
		if(this.autoPlay){
			this.timer = setTimeout(bindFun(this,function(){
				this.tar.style[this.path]=this.from+'px';
				this.move();
			}),this.time);
		}
	},
	reset:function(){
		this.from = this.path == 'left' || this.path =='top' ? this.distance : -this.distance;
		this.complete=false;
	}
}


var star = Class.create();
star.prototype = {
	init:function(el){
		this.o = $(el);
		this.starts = this.o.getElementsByTagName('a');
		this.input = this.o.getElementsByTagName('input')[0];
		this.lable = this.o.getElementsByTagName('em')[0];
		this.current = -1;
		for(var i=0,l=this.starts.length;i<l;i++){
			if(this.starts[i].className.indexOf('on')>=0){this.current = i}
			this.handle(this.starts[i],i)
		}
	},
	binFn:function(o,fn){return function(){fn.apply(o,arguments)}},
	handle:function(obj,n){
		addEvent(obj,'click',this.binFn(this,function(){this.current = n;this.click(obj)}))
		addEvent(obj,'mouseover',this.binFn(this,function(){ this.mouse(obj,'over')}))
		addEvent(obj,'mouseout',this.binFn(this,function(){ this.mouse(obj);}))
	},
	click:function(o){
		if(o.className.indexOf('on')<0)o.className = o.className +' on';
		this.input.value = o.getAttribute('alt');
		if(this.lable){ this.lable.style.display='block'; this.lable.innerHTML = o.title}
	},
mouse:function(el,type){
		if(this.lable){ this.lable.style.display='block'; this.lable.innerHTML = el.title;}
		if(type){
			if(this.current != -1) this.starts[this.current].className = this.starts[this.current].className.replace(/on/g,'').replace(/\s+/g,' ');
		}else{
			if (this.current != -1) {
				this.starts[this.current].className = this.starts[this.current].className + ' on';
				if(this.lable) this.lable.innerHTML = this.starts[this.current].title;
			}else{
				this.lable.style.display="none";
			}
		}
	
	}
}



var CountTime = Class.create();
CountTime.prototype = {
	init:function(el,node,tarTime){
		this.o=$(el,node);
		this.tar = new Date(tarTime);
		this.now = null;
		this.timer = null;
		this.l = this.o.length;
		this.leave = null;
		this.run();
	},
	run:function(){
		this.now = new Date();
		this.leave = this.tar.getTime() - this.now.getTime();
		if(this.leave<=0){
			this.complete();
			return;
		}
		this.day = Math.floor(this.leave/(1000*60*60*24));
		this.hour = Math.floor(this.leave / (1000 * 3600)) - (this.day * 24);
		this.min = Math.floor(this.leave / (1000 * 60)) - (this.day * 24 * 60) - (this.hour * 60);
		this.sec = Math.floor(this.leave / (1000)) - (this.day * 24 * 60 * 60) - (this.hour * 60 * 60) - (this.min * 60);
		
		var arr = [this.sec,this.min,this.hour,this.day];
		for(var i=this.l-1;i>=0;i--){
			this.o[this.l-1-i].innerHTML = arr[i];
		}
		if(this.leave>0) setTimeout(bindFun(this,this.run),1000)
	},
	complete:function(){
		clearTimeout(this.timer);
		this.timer = null;
		for(var i=0;i<this.l;i++){
			this.o[i].innerHTML = 00;
		}
		return;
	}
}




function textInfo(el){
	var o = document.getElementById(el);
	if(!el) return;
	var btn = o.getElementsByTagName('span')[0],div = o.getElementsByTagName('div')[0];
	btn.onclick = function(){
		if(btn.className == 'on'){
			btn.className = '';
			div.style.display = 'none';
		}else{
			btn.className = 'on';
			div.style.display = 'block';
		}
	}
}

function apply(){
	var arr=[],tar=[],tar2=[];
	arr = document.getElementById('apply').getElementsByTagName('span');
	tar = [document.getElementById('try'),document.getElementById('try2')];
	tar2 = document.getElementById('apply').getElementsByTagName('dd');
	return toggleShow(arr,tar,tar2);
}
function zige(){
	var arr=[],tar=[];
	arr=document.getElementById('zige').getElementsByTagName('span');
	tar = document.getElementById('zigeCon').getElementsByTagName('div');
	return toggleShow(arr,tar);
}

function toggleShow(objs,tars,tars2){
	for(var i=0,l=objs.length;i<l;i++){
		show(i);
	}
	function show(n){
		addEvent(objs[n],'mouseover',function(){
			for(var i=0,l=objs.length;i<l;i++){
				if(tars[i]) tars[i].style.display = 'none';
				if(tars2 && tars2[i])tars2[i].style.display = 'none';
				objs[i].className = '';
			}
			if(tars && tars[n]) tars[n].style.display = 'block';
			if(tars2 && tars2[n])tars2[n].style.display = 'block';
			objs[n].className = 'on';
		})
	}
}


function selMenu(el,node,tar,css){
	var o = $(el),t=$(o,node)[0],tNode=null;
	if(tar) tNode = $(o, tar)[0];
	addEvent(t,'mouseover',function(){
		t.style.display="block";
		if(tNode) tNode.className = css;
	})
	addEvent(t,'mouseout',function(){
		t.style.display = 'none';
		if(tNode) tNode.className = '';
	})
	if (!tar) {
		addEvent(o, 'mouseover', function(){
			t.style.display = 'block';
		})
		addEvent(o, 'mouseout', function(){
			t.style.display = 'none';
		})
		return;
	}
	addEvent(tNode,'mouseover',function(){
		t.style.display = 'block';
		tNode.className = css;
	})
	addEvent(tNode,'mouseout',function(){
		t.style.display = 'none';
		tNode.className = '';
	})

}

function inputHandle(el,v){
	if(!document.getElementById(el)) return;
	var o = $(el);
	addEvent(o,'focus',function(){
		if( o.value==v){
			o.value='';
		}
		o.className ='emailon'
	})
	addEvent(o,'blur',function(){
		if(o.value!=v && o.value!=''){
			return;
		}
		o.value=v;
		o.className ='email'
	})
}

function proBtn(el){
	if(!document.getElementById(el)) return;
	var o=$(el),span=null;
	span = $(o,'span');
	for(var i=0,l=span.length;i<l;i++){
		handle(i);
	}
	function handle(n){
		addEvent(span[n],'mouseover',function(){
			if( span[n].className !='sel') span[n].className='hover';
		})
		addEvent(span[n],'mouseout',function(){
			if( span[n].className !='sel') span[n].className=''
		})
		addEvent(span[n],'click',function(){
			canl();
			span[n].className='sel'
		})
	}
	function canl(){
		for(var i=0,l=span.length;i<l;i++){
			span[i].className='';
		}
	}
}



function ScrollPics(id,dlist,leftbut,rightbut,path,page,autoPlayTime,nowClass,rate){
var nowPage=0,setout,setIn,speed,remain,now_num,target_num,obj=id.split("/"),xy="+",rate=rate||10;
var scrollId=$(obj[0]);
var orunimg=$(dlist,"img");
if(nowClass){page=1;$(obj[0],"div")[0].innerHTML+=$(obj[0],"div")[0].innerHTML;} //如果有当前样式，复制内容
var scroll_List=$(obj[0],obj[1]);
var scroll_List_Total=scroll_List.length; //列表总数
if(Math.ceil(scroll_List_Total/page)-1 == 0){
	$(leftbut).style.display='none';
	$(rightbut).style.display='none';
	$(dlist).style.display='none';
	return;
}
for(var i=orunimg.length-1;i>=0;i--){
	if(i >= Math.floor(scroll_List_Total/page)){orunimg[i].style.display="none"}
}
var offset_scrollId=(path=="scrollLeft")?scrollId.offsetWidth:scrollId.offsetHeight; //取外容器宽或高
var offset_single=(path=="scrollLeft")?scroll_List[0].offsetWidth:scroll_List[0].offsetHeight; //取内部单个列表宽或高
var frameInList=Math.round(offset_scrollId/offset_single); //外容器可见区域列表数
if(nowClass){scroll_List[nowPage+nowClass].className="nowclass";}
$(leftbut).onmousedown=function(){xy="-";ScrollSpace();};
$(rightbut).onmousedown=function(){xy="+";ScrollSpace();};
if(autoPlayTime){ScrollAutoPlay();}
function ScrollAutoPlay(){if(remain!=0){setout=setTimeout(ScrollSpace,autoPlayTime);}} //自动播放函数
function ScrollSpace(){  //执行函数
	clearInterval(setIn);
	clearInterval(setout);
	remain=(xy=="+")?scroll_List_Total-frameInList-nowPage:nowPage; //计算左右被隐藏的剩余列表数
	if(xy=="+"){nowPage=remain<page?nowPage+remain:nowPage+page;}else{nowPage=remain<page?remain-nowPage:remain-page;} //加向左,减向右
	setIn=setInterval(ScrollBuffer,5);
	if(nowClass){ //加当前样式
		if(xy=="+"&&scroll_List_Total/2+1<=nowPage){scrollId[path]=0;nowPage=1;}
		if(xy=="-"&&nowPage<=0){scrollId[path]=scroll_List_Total*offset_single/2+offset_single;nowPage=scroll_List_Total/2;}
		for(var n=0;n<scroll_List_Total;n++){scroll_List[n].className="";}
		scroll_List[nowPage+nowClass].className="nowclass";
	}
	for(var im=0;im<orunimg.length;im++){
		orunimg[im].src=orunimg[im].src.replace("_.gif",".gif");
		$(leftbut).src=$(leftbut).src.replace("_.gif",".gif");
		$(rightbut).src=$(rightbut).src.replace("_.gif",".gif");
	}
	orunimg[Math.ceil(nowPage/page)].src=orunimg[Math.ceil(nowPage/page)].src.replace(".gif","_.gif");
	if(nowPage/page==0){$(leftbut).src=$(leftbut).src.replace(".gif","_.gif");}
	if(Math.ceil(nowPage/page)==Math.ceil(scroll_List_Total/page)-1){$(rightbut).src=$(rightbut).src.replace(".gif","_.gif");}
}
function ScrollBuffer(){ //缓冲函数
	now_num=scrollId[path]; //当前值
	target_num=nowPage*offset_single; //目标值
	speed=(target_num<now_num)?Math.floor((target_num-now_num)/rate):Math.ceil((target_num-now_num)/rate); //目标值-当前值
	scrollId[path]+=speed;
	if(speed==0){clearInterval(setIn);ScrollAutoPlay();}
}
}

function getid(id){return document.getElementById(id);}
function gettag(tag,obj){if(obj){return getid(obj).getElementsByTagName(tag)}else{return document.getElementsByTagName(tag)}}

function state(id1,id2){var con=getid(id2);getid(id1).onclick=function(){con.offsetWidth==0?con.style.display='block':con.style.display=''}}

function fadetip(id1,id2){
	
var h=getid(id1),t=getid(id2),Tran=0,out3,out2,out;t.style.display='none';t.style.opacity=0;t.style.filter ='alpha(opacity=0)';
	
h.onmouseover=function(){clear();display();out3=setTimeout(function(){hidden()},3000)}
	
h.onmouseout=function(){clear();hidden()}
		
		
function hidden(){Tran=Tran-4;ffTran=Tran/100;		
		if(Tran>0)
			{t.style.opacity=ffTran;t.style.filter ='alpha(opacity='+Tran+')'}	
		else
			{t.style.display="none";return;}		
		out=setTimeout(function(){hidden()},1*25)
		}
	
	
function display(){t.style.display="";Tran=Tran+4;ffTran=Tran/100;
		if(Tran<100)
			{t.style.opacity=ffTran;t.style.filter ='alpha(opacity='+Tran+')'}	
		else
			{t.style.opacity=1;t.style.filter ='alpha(opacity=100)';return;}			
		out2=setTimeout(function(){display()},1*25)
		}		


function clear(){clearTimeout(out3);clearTimeout(out2);clearTimeout(out)}

}


function Canvassing(id, value) {

    var par = $(id);
	if (par==document)
	{
		return;
	}
	var a = $(id, 'a')[0],
		box = $(id, 'div')[0],
		step = 30,
		timeout,
		timeout2,
		copy = $(box, 'a')[0],
		input = $(box, 'input')[0],
		to = 285,
		ie = !document.all;

    function move(n, step){
        return (to * (2 - n / step) * (n / step))
    }

    function show(n){
        n++;
        if(n > step){
			return;
        }
        
		box.style.width = move(n, step)+'px';        
		
		timeout = setTimeout(function(){show(n)},10);
    }

    a.onclick = function(){
        if (box.style.display == 'block'){
            return;
        }

        clearTimeout(timeout);
        input.value = value
        box.style.display = 'block';

        if (ie){
            input.style.width = '273px'
        } else {
            copy.innerHTML = '复制';
            input.style.width = '';
			
            copy.onclick = function() {
                clearTimeout(timeout2);
                input.select();
                window.clipboardData.setData("Text", value);
                input.style.width = '153px'
                copy.innerHTML = '已复制，请直接粘贴';
            }
        }
        input.select();
        show(0);
    }
	
    input.onblur = function(){timeout2 = setTimeout(function(){box.style.display = '';},500);}
}

function gotoTop(el,h,t){
    if (!document.getElementById(el)) {
        return
    }
    var o = document.getElementById(el), 
		w = parseInt(o.offsetWidth), 
		ww = document.documentElement.clientWidth, 
		wh = document.documentElement.clientHeight, 
		sTop = document.body.scrollTop || document.documentElement.scrollTop, 
		ie6 = navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.split(';')[1].indexOf('MSIE 6.0') > 0 ? true : false;
    o.style.cssText = 'top:' + (wh - 50) + 'px;right:' + ((ww - 1000) / 2 - w) + 'px;'
    h = h || 0;
	t = t || 0;
	if (sTop <= h) {
        o.style.display = "none"
    }
    window.onscroll = function(){
        sTop = document.body.scrollTop || document.documentElement.scrollTop
        if (ie6 == true) {
            o.style.cssText = 'left:' + parseInt((ww - 1000) / 2 + 1000 + w - 20) + 'px;top:' + parseInt(document.documentElement.clientHeight + document.documentElement.scrollTop - 40) + 'px;'
        }
        if (sTop > h) {
            o.style.display = 'block'
        }
        if (sTop <= h) {
            o.style.display = "none"
        }
    }
    o.onclick = function(){
        document.body.scrollTop = t;
        document.documentElement.scrollTop = t;
    }
}
