function ImageLoader(className,Options){
    this._ImageLoadStack = null;
    this._currrentLoading = "";
    this._FinalRun = false;
    this.numLoaded = 0;
    this.ClassName = className; 
    if(typeof(Options)=="undefined") Options = {};
    if(isNaN(Options.Timeout) || Options.Timeout < 0 ||  Options.Timeout >100000){
        this.EnableTimeout = false;
    }else {
        this.EnableTimeout = true;
        this.Timeout = Options.Timeout;
    }
    if(typeof(Options.func)=="undefined"){
        this.AfterFunction = null;
    }else{
        this.AfterFunction = Options.func;
    }
    if(typeof(Options.display)=="undefined"){
        this.disDiv = null;
    }else if(typeof(Options.display)=="string"){
        this.disDiv = document.getElementById(Options.display); 
    }else if(typeof(Options.display)=="object"){
        this.disDiv = Options.display;
    }else{
        this.disDiv = null; 
    }
    if(typeof(Options.process)=="undefined"){
        this.procDiv = null;
    }else if(typeof(Options.process)=="string"){
        this.procDiv = document.getElementById(Options.process); 
    }else if(typeof(Options.process)=="object"){
        this.procDiv = Options.process;
    }else{ 
        this.procDiv = null; 
    }
    if(typeof(document.imageArray)=="undefined") document.imageArray = new Array();
    this.Load = function(){
        var args = this.Load.arguments;
        if(args.length!=0){
            this._ImageLoadStack = new Array();
			for(i=0; i<args.length; i++){
				 if(args[i].indexOf("#")!=0){
                    this._ImageLoadStack.push(args[i]);
                }
			}
        }else if(this._ImageLoadStack == null){this._runFinal();}
        this.numTotal = this._ImageLoadStack.length;
        this._LoadAImage();
    }
    this._LoadAImage = function(){
        if(this._ImageLoadStack.length!=0){
            var sURL = this._ImageLoadStack.shift();
            if(this.disDiv!=null) this.disDiv.innerHTML = sURL;
            this._currrentLoading = sURL;
            var j = document.imageArray.length;
            document.imageArray[j] = document.createElement("IMG");
            document.imageArray[j].Owner = this;
            document.imageArray[j].onload = function(){
                this.Owner._LoadAImage();
                this.onload = null;
            }
            document.imageArray[j].onerror = function(){
                this.Owner._LoadAImage();
                this.onload = null;
            }
            if(this.EnableTimeout){
                window.setTimeout("if(this._currrentLoading==\""+sURL+"\"){"+this.ClassName+"._LoadAImage()}",this.Timeout); 
            }
            document.imageArray[j].src = sURL;
			if(this.procDiv!=null){
                this.numLoaded++;
                var percentage = Math.floor(this.numLoaded * 100 / this.numTotal); 
                this.procDiv.innerHTML = percentage + "%"; 
            }
        }else{this._runFinal();}
    } 
    this._runFinal = function(){
            if(this._FinalRun == false){
                this._FinalRun = true;
                if(typeof(this.AfterFunction)=="function"){
                    this.AfterFunction(); 
                }else if(typeof(this.AfterFunction)=="string"){
                    if (window.execScript){
                        window.execScript(this.AfterFunction); 
                    }else{
                        window.eval(this.AfterFunction);  
                    }
                }
            }
    }
    this.setLoadImages = function(imageArray){
        if(typeof(imageArray)!="object") return; 
        this._ImageLoadStack = imageArray;
    }
}

function HtmlDecode(text){return text.replace(/&amp;/g,'&').replace(/&quot;/g,'\"').replace(/&lt;/g,'<').replace(/&gt;/g,'>')}
function opCard(objName,htmlContainer){	
	this.obj = objName;
	this.container = htmlContainer || 'focusImg';
	this.bind = new Array();
	this.index = 0;
	this.style = new Array();
	this.overStyle = false;
	this.overChange = false; // onclick
	this.menu = false;
	this.nesting = [false,false,"",""];
	this.auto = [false, 1000];
	this.timerID = null;
	this.timerID2 = null;
	this.menutimerID = null;
	this.m_TopImgs = new Array();
	this.completed = false;
	this.arrMenu;
	this.arrInfo;
	this.showStat = false;		
}
function TopImgItem (strUrl,imgMaxUrl,imgMinUrl,strText){
	this.strUrl = strUrl;
	this.imgMaxUrl = imgMaxUrl;
	this.imgMinUrl = imgMinUrl;	
	this.strText = HtmlDecode(strText);
}
opCard.prototype.AddImgItem = function (strUrl,imgMaxUrl,imgMinUrl,strText){
	this.m_TopImgs[this.m_TopImgs.length] = new TopImgItem(strUrl,imgMaxUrl,imgMinUrl,strText);
}
opCard.prototype.show = function(){
	//var loader = new ImageLoader("loader",{Timeout:4000,func: final,display:"display",process:$("process")});
	var loader = new ImageLoader("loader",{Timeout:4000});
	var strMaxUrl="",strMinUrl="",strAllUrl="",imageArray = new Array();
	for (var i=0;i<this.m_TopImgs.length;i++){
		strMaxUrl += this.m_TopImgs[i].imgMaxUrl + ",";
		strMinUrl += this.m_TopImgs[i].imgMinUrl + ",";
	}
	strAllUrl = strMaxUrl + strMinUrl;
	strAllUrl = strAllUrl.substring(0,strAllUrl.length-1);
	imageArray = strAllUrl.split(",");
	loader.setLoadImages(imageArray);
	loader.Load();
	var str='<ul id="'+ this.obj +'_s" class="ul">';
	for (var i=0;i<this.m_TopImgs.length;i++){
		str += '<li';
		if (i!=0){str += ' style="display:none"'}
		str += '><a href="'+ this.m_TopImgs[i].strUrl +'" target="_blank"><img src="'+ this.m_TopImgs[i].imgMaxUrl +'" alt="'+this.m_TopImgs[i].strText+'" /></a><p class="titbg"></p><p class="tita"><a href="'+ this.m_TopImgs[i].strUrl +'" title="'+ this.m_TopImgs[i].strText +'" target="_blank">'+ this.m_TopImgs[i].strText +'</a></p></li>';
	}
	str +='</ul><ul id="'+ this.obj +'_a" class="ul">';
	for (var i=0;i<this.m_TopImgs.length;i++){
		str += '<li><a href="'+ this.m_TopImgs[i].strUrl +'" target="_blank"><img src="'+ this.m_TopImgs[i].imgMinUrl +'" alt="'+ this.m_TopImgs[i].strText +'" /></a></li>';
	}
	str +='</ul>';	
	this.completed = true;
	document.getElementById(this.container).innerHTML=str;
	this.showStat = true;
}
opCard.prototype.creat = function(func){
	this.arrMenu = document.getElementById(this.bind[0]).getElementsByTagName(this.bind[1]);
	this.arrInfo = document.getElementById(this.bind[2]).getElementsByTagName(this.bind[3]);
	var self = this,i;
	argLen = arguments.length;
	var arrM = new Array();
	if(this.nesting[0] || this.nesting[1]){
		this.arrMenu = this.nesting[0]?this.getChilds(this.arrMenu,this.bind[0],2):this.arrMenu;
		this.arrInfo = this.nesting[1]?this.getChilds(this.arrInfo,this.bind[2],3):this.arrInfo;
	}
	var l = this.arrMenu.length;
	if(l!=this.arrInfo.length){alert("菜单和内容必须拥有相同的数量\n如果需要，你可以放一个空的在那占位。")}
	if(this.menu){this.auto=false;this.overChange=true;}
	for(i=0;i<l;i++){
		this.arrMenu[i].cName = this.arrMenu[i].className;
		this.arrMenu[i].className = (i!=this.index || this.menu)?this.getClass(this.arrMenu[i],this.style[0]):this.getClass(this.arrMenu[i],this.style[1]);
		if(self.arrMenu[i].getAttribute("skip")){
			if(this.overStyle || this.overChange){
				this.arrMenu[i].onmouseover = function(){self.styleOver(this);}
				this.arrMenu[i].onmouseout = function(){self.styleOut(this);}
			}
			this.arrMenu[i].onclick = function(){if(argLen==1){func()}}
			this.arrInfo[i].style.display = "none";
			continue;
		}
		if(i!=this.index || this.menu){this.arrInfo[i].style.display="none"};
		this.arrMenu[i].index = i;
		this.arrInfo[i].index = i;
		if(this.overChange){
			this.arrMenu[i].onmouseover = function(){
				var self2 = this;
				if (self.showStat){self.changeOver(self2);}else{self.timerID2 = setTimeout(function(){self.changeOver(self2);},200);}
			}
			self.arrMenu[i].onmouseout = function(){
				if(self.timerID2){clearTimeout(self.timerID2);}
				var self2 = this;
				self.changeOut(self2);
			}
		}else{
			this.arrMenu[i].onclick  = function(){self.changeClick(this);if(argLen==1){func()};}	
			if(this.overStyle){
				this.arrMenu[i].onmouseover = function(){self.styleOver(this);}
				this.arrMenu[i].onmouseout = function(){self.styleOut(this);}
			}else{
				if(self.auto[0]){
					this.arrMenu[i].onmouseover = function(){self.autoOver();}
					this.arrMenu[i].onmouseout = function(){self.autoOut();}
				}
			}
		}
		if(this.auto[0] || this.menu){
			this.arrInfo[i].onmouseover = function(){self.autoinfOver();}
			this.arrInfo[i].onmouseout = function(){self.autoinfOut();}
		}
	}
	if(this.auto[0]){this.timerID = setTimeout(function(){self.autoMove();},this.auto[1])}
}
opCard.prototype.autoMove = function(){
	var n,l,self = this;
	l= this.arrMenu.length;
	n = this.index + 1;	
	if(n==l){n=0};
	while(this.arrMenu[n].getAttribute("skip")){n += 1;if(n==l){n=0};}
	this.changeOption(this.arrMenu[n]);
	this.timerID = setTimeout(function(){self.autoMove();},this.auto[1]);
}
opCard.prototype.autoStop = function(num){var self = this;if(!this.auto[0]){return;};num == 0 ? clearTimeout(this.timerID) : this.timerID = setTimeout(function(){self.autoMove();},this.auto[1]);}
opCard.prototype.getClass = function(o,s){if(o.cName==""){return s}else{return o.cName + " " + s}}
opCard.prototype.changeOption = function(obj){	
	this.arrMenu[this.index].className = this.getClass(this.arrMenu[this.index],this.style[0]);	
	this.arrInfo[this.index].style.display = "none";
	obj.className = this.getClass(obj,this.style[1]);
	this.arrInfo[obj.index].style.display = "";
	this.index = obj.index;	
}
opCard.prototype.changeMenu = function(num){var self = this;if(!this.menu){return;}num==0?this.menutimerID = setTimeout(function(){self.menuClose();},1000):clearTimeout(this.menutimerID);}
opCard.prototype.menuClose = function(){this.arrInfo[this.index].style.display = "none";this.arrMenu[this.index].className = this.getClass(this.arrMenu[this.index],this.style[0]);}
opCard.prototype.changeOver = function(obj){if(this.timerID){clearTimeout(this.timerID);};this.changeOption(obj);this.menu?this.changeMenu(1):this.autoStop(0);}
opCard.prototype.changeOut = function(obj){if(this.timerID){clearTimeout(this.timerID);};this.menu?this.changeMenu(0):this.autoStop(1);}
opCard.prototype.changeClick = function(obj){this.changeOption(obj);this.autoStop(0);	}
opCard.prototype.changeTitle = function(obj,num){if(!this.overStyle){return;};if(obj.index!=this.index){obj.className = this.getClass(obj,this.style[num])}}
opCard.prototype.styleOver = function(obj){this.changeTitle(obj,2);this.autoStop(0);}
opCard.prototype.styleOut = function(obj){this.changeTitle(obj,0);this.autoStop(1);}
opCard.prototype.autoOver = function(){this.autoStop(0);}
opCard.prototype.autoOut = function(){this.autoStop(1);}
opCard.prototype.autoinfOver = function(){this.menu?this.changeMenu(1):this.autoStop(0);}
opCard.prototype.autoinfOut = function(){this.menu?this.changeMenu(0):this.autoStop(1);}
opCard.prototype.getChilds = function (arrObj, id, num){
	var depth = 0;
	var firstObj = this.nesting[num]==""?arrObj[0]:document.getElementById(this.nesting[num]);
	do{
		if(firstObj.parentNode.getAttribute("id")==id){break}else{depth+=1}
		firstObj = firstObj.parentNode;
	}while(firstObj.tagName.toLowerCase()!="body")
	var t;
	var arr = new Array();
	for(i=0;i<arrObj.length;i++){
		t = arrObj[i], d = 0;
		do{
			if(t.parentNode.getAttribute("id")==id && d == depth){
				arr.push(arrObj[i]);break;
			}else{
				if(d==depth){break};d+=1;
			}
			t = t.parentNode;
		}
		while(t.tagName.toLowerCase()!="body")
	}
	return arr;
}
if (!Array.prototype.push) {
	Array.prototype.push = function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
}
if (!Array.prototype.pop) {
	Array.prototype.pop = function array_pop() {
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
}
