﻿//==========
//jon编写===
//==========
function _get(name){return document.getElementById(name);}
// 功能：修改 window.setTimeout，使之可以传递参数和对象参数 使用方法： setTimeout(回调函数,时间,参数1,,参数n)
var __sto = setTimeout;
window.setTimeout = function(callback,timeout,param)
{
    var args = Array.prototype.slice.call(arguments,2);
    var _cb = function(){ if(typeof(callback) == 'function'){ callback.apply(null,args);}else{eval(callback);}}
    __sto(_cb,timeout);
}

function _getPosition(obj,type)
{
	var size=0;
	if(type=="t"){size=obj.style.top.replace("px","");}
	if(type=="l"){size=obj.style.left.replace("px","");}
	if(type=="h"){size=obj.offsetHeight;}
	if(type=="w"){size=obj.offsetWidth;}
	if(size==""){size=0;}	
	return size;
}
//f：form 开始  t:to目标：time 时间 {obj:_get("div1"),to:100,f:0,callback:aa,param:["a","bb"]}
function Alpha(obj)
{ 	
	obj.time=(obj.time==undefined?0:obj.time)
	if(obj.obj.filters==undefined){obj.obj.style.filter="alpha(opacity=100)";}
	obj.f=(obj.f==undefined?obj.obj.filters.alpha.opacity:obj.f);	
	if(obj.t<obj.f){obj.f--;}else{obj.f++;}
	if(obj.f!=obj.t){window.setTimeout(Alpha,obj.time,obj);}
	else{if(obj.callback!=undefined){obj.callback.apply(null,obj.param);}}
	obj.obj.style.filter="alpha(opacity="+obj.f+")";
}

function Place(obj)
{
	obj.time=(obj.time==undefined?0:obj.time);
	obj.f=(obj.f==undefined?{t:_getPosition(obj.obj,"t"),l:_getPosition(obj.obj,"l")}:obj.f);		
	obj.size=(obj.size==undefined?1:obj.size);	
	if((obj.f.t<obj.t.t+3)&&(obj.f.t>obj.t.t-3)){obj.f.t=obj.t.t;}else{
	if(obj.f.t>obj.t.t){obj.f.t=obj.f.t-obj.size;}else{obj.f.t=obj.f.t+obj.size;}}	
	if((obj.f.l<obj.t.l+3)&&(obj.f.l>obj.t.l-3)){obj.f.l=obj.t.l;}else
	{if(obj.f.l>obj.t.l){	obj.f.l=obj.f.l-obj.size;}else{	obj.f.l=obj.f.l+obj.size;}}	
	if(obj.f.t!=obj.t.t||obj.f.l!=obj.t.l){window.setTimeout(Place,obj.time,obj);}
	else{if(obj.callback!=undefined){obj.callback.apply(null,obj.param);}}	
	obj.obj.style.top=	obj.f.t;
	obj.obj.style.left=	obj.f.l;
}

function Size(obj)
{
	obj.time=(obj.time==undefined?0:obj.time);
	obj.f=(obj.f==undefined?{h:_getPosition(obj.obj,"h"),w:_getPosition(obj.obj,"w")}:obj.f);		
	obj.size=(obj.size==undefined?1:obj.size);	
	if((obj.f.h<obj.t.h+3)&&(obj.f.h>obj.t.h-3)){obj.f.h=obj.t.h;}else
	{if(obj.f.h>obj.t.h){	obj.f.h=obj.f.h-obj.size;}else{	obj.f.h=obj.f.h+obj.size;}}	
	if((obj.f.w<obj.t.w+3)&&(obj.f.w>obj.t.w-3)){obj.f.w=obj.t.w;}else
	{if(obj.f.w>obj.t.w){obj.f.w=obj.f.w-obj.size;}else{	obj.f.w=obj.f.w+obj.size;}}	
	if(obj.f.h!=obj.t.h||obj.f.w!=obj.t.w){window.setTimeout(Size,obj.time,obj);}
	else{if(obj.callback!=undefined){obj.callback.apply(null,obj.param);}}	
	obj.obj.style.height=obj.f.h;
	obj.obj.style.width=obj.f.w;
}
//滚动
function Trundle(obj)
{
    obj.h=(obj.h==undefined?_getPosition(obj.template,"h"):obj.h); 
    obj.fatherH=(obj.fatherH==undefined?obj.father.style.height.replace("px",""):obj.fatherH); 
    if(obj.fatherH>=obj.h){return;}
    if(obj.mirror.innerHTML==""){obj.mirror.innerHTML=obj.template.innerHTML;}   
    if(obj.debug!=undefined){obj.mirror.style.background="#FF0000";obj.template.style.background="#0099FF";}    
    if(obj.size==undefined){obj.size=1;}
    if(obj.time==undefined){obj.time=10;}
   
    if(obj.father.obj==undefined){obj.father.obj=obj;}
    if(obj.father.onmouseover==null){obj.father.onmouseover=function(){this.obj.stop=true;} }
    if(obj.father.onmouseout==null){obj.father.onmouseout=function(){this.obj.stop=false;} }

    obj.stop=(obj.stop==undefined?false:obj.stop); 
    obj.t=(obj.t==undefined?obj.father.scrollTop:obj.t); 
    obj.Ntime=obj.time;
     if(!obj.stop)
    {  
        obj.t=obj.t+obj.size;
        if(obj.h<=obj.t){obj.t=0;}
        obj.father.scrollTop=obj.t;    
        if(obj.stopTime!=undefined)
        {
             var h=obj.t%obj.fatherH;             
            if((h<=(obj.fatherH+obj.size))&&(h>=(obj.fatherH-obj.size)))             
             {
                obj.Ntime=obj.stopTime;
             }            
        }      
    }
    window.setTimeout(Trundle,obj.Ntime,obj);
}