/*--Javascript for www.CRIENGLISH.COM by chaozi--*/
function $(id) { return document.getElementById(id); }
function $$(strClassName, strTagName, oElm){var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);var arrReturnElements = new Array();strClassName = strClassName.replace(/\-/g, "\\-");var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");var oElement;for(var i=0; i<arrElements.length; i++){oElement = arrElements[i];if(oRegExp.test(oElement.className)){arrReturnElements.push(oElement);}}return (arrReturnElements)}
function IsNullOrEmpty(name){try{if($(name).innerHTML.Trim()!=""){return false;}}catch(e){return true;}return true;}
var IsPageFinished = false;window.onload = function(){IsPageFinished = true;};String.prototype.Trim=function(){ return this.replace(/(^\s*)|(\s*$)/g,"");}

String.prototype.Trim=function(){ return this.replace(/(^\s*)|(\s*$)/g,"");}


var expander={init:function(config){this.$container= $(config.containerID);this.$trigger= $(config.triggerID);this.$targetHeight=Math.abs(config.targetheight)||100;this.$Step=Math.abs(config.step)||5;this.$Speed=Math.abs(config.speed)||10;this.$expandCss=config.expandcss;this.$collapseCss=config.collapsecss;this.$animating=false;this.$Timer=null;this.$autocollapse=config.autocollapse;this.$currentHeight=0;this.$container.style.overflow="hidden";this.$isexpanded=true;this.docready();}, docready:function(){var oThis = this;clearTimeout(this.$Timer);if(IsPageFinished){this.$rawHeight = this.$container.offsetHeight;this.$trigger.onclick = function(){if(oThis.animating) return;oThis.change();};if(this.$autocollapse){this.collapse();}else{this.$trigger.className = this.$collapseCss;}}else{this.$Timer = setTimeout(function(){oThis.docready();},10);}},change:function(){if(this.$isexpanded){this.collapse();}else{this.expand();}},collapse:function(){if(this.$container.offsetHeight > this.$targetHeight && this.$animating != true){this.$animating = true;this.$currentHeight = this.$container.offsetHeight;this.Move("collapse");}},expand:function(){if(this.$container.offsetHeight < this.$rawHeight && this.$animating != true){this.$animating = true;this.$currentHeight = this.$container.offsetHeight;this.Move("expand");}},Move:function(method){clearTimeout(this.$Timer);var oThis = this;if(method=="collapse"){var iStep =this.GetStep(Math.abs(this.$currentHeight - this.$targetHeight));if(iStep != 0){this.$currentHeight = this.$currentHeight - iStep;this.$container.style.height =this.$currentHeight + "px";this.$Timer = setTimeout(function(){oThis.Move("collapse");},this.$Speed);}else{this.$container.style.height = this.$targetHeight + "px";this.$trigger.className = this.$expandCss;this.$isexpanded = false;this.Finished();}}else{iStep = this.GetStep(Math.abs(this.$rawHeight - this.$currentHeight)); if(iStep != 0){this.$currentHeight = this.$currentHeight + iStep;this.$container.style.height = this.$currentHeight + "px";this.$Timer = setTimeout(function(){oThis.Move("expand");},this.$Speed);}else{this.$container.style.height = this.$rawHeight + "px";this.$trigger.className = this.$collapseCss;this.$isexpanded = true;this.Finished();}}},Finished:function(){clearTimeout(this.$Timer);this.$animating = false;this.$currentHeight = 0;},GetStep:function(iNow){var iStep=iNow/this.$Step;if(iStep <= 0) {return 0};if(Math.abs(iStep) < 1){return 0};return iStep;}}
var navigationmenu={init:function(config){this.$container = $(config.container);this.$logo= $(config.logo);this.$logocss= config.logocss;this.$defaultlogocss= config.defaultlogocss;this.$primarymenu = $$("*",config.primarymenutag,$(config.primarymenu));this.$secondarymenu= $$("*",config.secondarymenutag,$(config.secondarymenu));this.$secondarymenuscene = $(config.secondarymenuscene);this.$default= config.defaultid;this.$Timer= null;this.$triggertype   = config.triggertype || "click";this.$current= -1;this.docready();},docready:function(){var oThis = this;clearTimeout(this.$Timer);if(IsPageFinished){this.setupmenus();if(this.$default >= 0){this.$current = this.$default;this.showsceondary();}}else{this.$Timer = setTimeout(function(){oThis.docready();},10);}},setupmenus:function(){var oThis = this;for(var i=0;i<oThis.$primarymenu.length;i++){oThis.$primarymenu[i].setAttribute("pindex",i);oThis.$primarymenu[i].setAttribute("rawcss",oThis.$primarymenu[i].className);if(oThis.$triggertype == "mouseover"){oThis.$primarymenu[i].onmouseover = function(){if(oThis.$current == this.getAttribute("pindex")) return;if(oThis.$current >= 0){oThis.$primarymenu[oThis.$current].className = oThis.$primarymenu[oThis.$current].getAttribute("rawcss");}oThis.$current = this.getAttribute("pindex");oThis.showsceondary();};}else{oThis.$primarymenu[i].onclick = function(){if(oThis.$current == this.getAttribute("pindex")) return;if(oThis.$current >= 0){oThis.$primarymenu[oThis.$current].className = oThis.$primarymenu[oThis.$current].getAttribute("rawcss");}oThis.$current = this.getAttribute("pindex");oThis.showsceondary();};}}},showsceondary:function(){if(this.$current < this.$primarymenu.length && this.$current >= 0){if(this.$current >= 0){this.$primarymenu[this.$current].className = this.$primarymenu[this.$current].getAttribute("rawcss")+"_selected";}if(this.$logocss != null && this.$logocss[this.$current]!= null){this.$logo.className = this.$logocss[this.$current];}else if(this.$defaultlogocss != null){this.$logo.className = this.$defaultlogocss;}this.$secondarymenuscene.innerHTML = (this.$secondarymenu[this.$current] == null)?"":this.$secondarymenu[this.$current].innerHTML;}}}


var fotoslidercontent={

init:function(config){
	
	this.$container 	= $(config.containerID);	//容器
	this.$tabbar		= $(config.tabbarID);		//TAB 容器
	this.$frame			= $(config.frameID);		//幕布容器
	this.$content		= $(config.contentID);		//內容容器
	this.$imgitemID		= config.imgitemID;			//圖片模組ID
	this.$imgitem		= $(config.imgitemID);		
	
	this.$tabcss		= config.tabcss;			//{"start","center","end","only"} 頭、中、尾和唯一TAB樣式
	this.$tabitems		= config.tabitems;			//{"read","community","audio","video","photos"} TAB內容單元ID
	this.$tabitemscss	= config.tabitemscss;		//{"","","","",""}								TAB按鈕個性CSS
	this.$nullcss		= config.nullcss;			//												無TAB項默認CSS
	
	this.$imgframecss	= config.imgframecss;		// 圖片模組圖片展示區樣式
	this.$imgtoolbarcss	= config.imgtoolbarcss;		// 圖片模組工具欄樣式
	this.$imgbtncss		= config.imgbtncss;			// 圖片模組圖片切換按鈕樣式
	this.$imgindex		= 0;						// 圖片模組默認選中圖片
	this.$normalcontent = $(config.normalcontent);
	this.$normalHTML	= (this.$normalcontent == null)?"":this.$normalcontent.innerHTML;
	
	this.$borderoffset	= Math.abs(config.borderoffset) || 0;
	this.$Timer			= null;
	this.$DisplayType	= "Null";					//"Null"|"Only"|"Multi"
	this.$tabarray		= new Array();
	this.$conarray		= new Array();
	this.$cssarray		= new Array();
	this.$imgsarray 	= new Array();
	if(this.detect())
	{
		this.docready();
	}
	else
	{
		var divbar = document.createElement("div");
		divbar.className = this.$tabcss[3]+"_selected";
		var divitem = document.createElement("div");
		divitem.className = this.$nullcss+"_selected";
		
		divbar.appendChild(divitem);
		
		this.$tabbar.innerHTML = "";
		this.$tabbar.appendChild(divbar);
		
		this.$frame.innerHTML = this.$content.innerHTML;
		this.$content.innerHTML = "";
	}

	
},
docready:function()
{
	var oThis = this;
	clearTimeout(this.$Timer);
	if(IsPageFinished)
	{
		this.setup();
	}
	else
	{
		this.$Timer = setTimeout(function(){oThis.docready();},10);
	}
},
detect:function()
{
	for(var i=0;i<this.$tabitems.length;i++)
	{
		if(!IsNullOrEmpty(this.$tabitems[i]))
		{
			return true;
		}
	}
	return false;
},


setup:function()
{
	if(this.$tabitems.length > 0)
	{
		for(var i=0;i<this.$tabitems.length;i++)
		{
			if(!IsNullOrEmpty(this.$tabitems[i]))
			{
				this.$cssarray.push(this.$tabitemscss[i]);
				
				if(this.$tabitems[i] == this.$imgitemID)
				{
					this.$imgsarray = $$("*","img",this.$imgitem);							
				}	
				this.$tabarray.push(this.$tabitems[i]);				
				this.$conarray.push($(this.$tabitems[i]).innerHTML);
				$(this.$tabitems[i]).innerHTML="";
			}
		}
		if(this.$conarray.length == 1)
		{
			this.$DisplayType = "Only";
		}
		if (this.$conarray.length > 1)
		{
			this.$DisplayType = "Multi";
		}
	}
	
	if(this.$DisplayType!="Null")
	{
		this.TabTo(0);
	}
	else
	{
		var divbar = document.createElement("div");
		divbar.className = this.$tabcss[3]+"_selected";
		var divitem = document.createElement("div");
		divitem.className = this.$nullcss+"_selected";
		
		divbar.appendChild(divitem);
		
		this.$tabbar.innerHTML = "";
		this.$tabbar.appendChild(divbar);
		
		this.$frame.innerHTML = this.$content.innerHTML;
	}
	
},
getImgFrame:function(){
	
	var div = document.createElement("div");
	
	if(this.$imgsarray.length > 0)
	{
		var _frame = document.createElement("div");
		_frame.className = this.$imgframecss;
		var _toolbar = document.createElement("div");
		_toolbar.className = this.$imgtoolbarcss;
		
		
		//var _ul =  document.createElement("ul");
		
		for(var i=0;i<this.$imgsarray.length;i++)
		{
			//var _li =  document.createElement("li");
			var _a = document.createElement("a");
			_a.className = this.$imgbtncss;
			_a.innerHTML = i+1;
			_a.setAttribute("index",i);
			if(i == this.$imgindex)
			{
				_a.className = this.$imgbtncss + "_selected";
			}
			else
			{
				var oThis = this;
				_a.onclick = function(){oThis.$imgindex = this.getAttribute("index");oThis.getImgFrame();}
			}
			
			_toolbar.appendChild(_a);
		}
		//_toolbar.appendChild(_ul);
		_frame.appendChild(this.$imgsarray[this.$imgindex]);
		
		var _content =  document.createElement("div");
		_content.innerHTML = this.$normalHTML;
		
		div.appendChild(_frame);
		div.appendChild(_toolbar);
		div.appendChild(_content);
	}
	else
	{
		div.innerHTML = this.$imgitem.innerHTML+ "<div>"+this.$normalHTML+"</div>";
	}
	
	this.$frame.innerHTML = "";
	this.$frame.appendChild(div);
},
TabTo:function(index){
	if(index >= this.$conarray.length)
	{
		return;
	}
	
	
	if(this.$DisplayType == "Multi")
	{
		
		var ulobj = document.createElement("ul");
		var oThis = this;
		var liobj;var divobj;
		
		//first
		liobj = document.createElement("li");
		liobj.className = (index == 0)?this.$tabcss[0]+"_selected":this.$tabcss[0];
		liobj.style.width = this.getNormalWidth()+"px";
		liobj.setAttribute("index",0);
		if(index != 0)
		{liobj.onclick = function(){oThis.TabTo(this.getAttribute("index"));}}

		divobj = document.createElement("div");
		divobj.className = (index == 0)?this.$cssarray[0]+"_selected":this.$cssarray[0];

		//divobj.innerHTML = 0;

		liobj.appendChild(divobj);
		ulobj.appendChild(liobj);
		
		//center
		for(var i=1;i<this.$conarray.length-1;i++)
		{
			liobj = document.createElement("li");
			liobj.className = (index == i)?this.$tabcss[1]+"_selected":this.$tabcss[1];
			liobj.style.width = this.getNormalWidth()+"px";
			liobj.setAttribute("index",i);
			if(index != i)
			{liobj.onclick = function(){oThis.TabTo(this.getAttribute("index"));}}
			
			
			divobj = document.createElement("div");
			divobj.className = (index == i)?this.$cssarray[i]+"_selected":this.$cssarray[i];

			//divobj.innerHTML = this.$cssarray[i];

			liobj.appendChild(divobj);
			ulobj.appendChild(liobj);

		}
		
		//end
		var end = this.$conarray.length - 1;
		var width = this.getNormalWidth()+this.getRestPix();
 
		liobj = document.createElement("li");
		liobj.className = (index == end)?this.$tabcss[2]+"_selected":this.$tabcss[2];
		liobj.style.width = width+"px";
		
		liobj.setAttribute("index",end);
		if(index != end)
		{liobj.onclick = function(){oThis.TabTo(this.getAttribute("index"));}}
			
		divobj = document.createElement("div");
		divobj.className = (index == end)?this.$cssarray[end]+"_selected":this.$cssarray[end];
		
		//divobj.innerHTML = end;
		
		liobj.appendChild(divobj);
		ulobj.appendChild(liobj);

		this.$tabbar.innerHTML = "";
		this.$tabbar.appendChild(ulobj);
	}
	else if(this.$DisplayType == "Only")
	{
		var divbar = document.createElement("div");
		divbar.className = this.$tabcss[3]+"_selected";
		var divitem = document.createElement("div");
		divitem.className = this.$cssarray[0]+"_selected";
		divbar.appendChild(divitem);
		
		this.$tabbar.innerHTML = "";
		this.$tabbar.appendChild(divbar);
	}
	
	if(this.$tabarray[index] == this.$imgitemID)
	{
		this.getImgFrame();
	}
	else
	{
		this.$frame.innerHTML = this.$conarray[index];//+ "<div>"+this.$normalHTML+"</div>";
	}
},
getNormalWidth:function()
{	
	var l = this.$tabbar.offsetWidth - this.$borderoffset*(this.$conarray.length - 1);
	
	return (l - (l % this.$conarray.length))/this.$conarray.length;
},
getRestPix:function()
{
	var l = this.$tabbar.offsetWidth - this.$borderoffset*(this.$conarray.length - 1);
	return l % this.$conarray.length;
}

}

function MyExpander(config){this.$container = $(config.containerID);this.$trigger = $(config.triggerID);this.$targetHeight= Math.abs(config.targetheight) || 100;this.$Step  = Math.abs(config.step) || 5;this.$Speed= Math.abs(config.speed) || 10;this.$expandCss= config.expandcss;this.$collapseCss= config.collapsecss;this.$animating = false;this.$Timer= null;this.$autocollapse= config.autocollapse;this.$currentHeight = 0;this.$container.style.overflow = "hidden";this.$isexpanded= true;this.docready();}MyExpander.prototype ={docready:function(){var oThis = this;clearTimeout(this.$Timer);if(IsPageFinished){this.$rawHeight = this.$container.offsetHeight;this.$trigger.onclick = function(){if(oThis.animating) return;oThis.change();};if(this.$autocollapse){this.collapse();}else{this.$trigger.className = this.$collapseCss;}}else{this.$Timer = setTimeout(function(){oThis.docready();},10);}},change:function(){if(this.$isexpanded){this.collapse();}else{this.expand();}},collapse:function(){if(this.$container.offsetHeight > this.$targetHeight && this.$animating != true){this.$animating = true;this.$currentHeight = this.$container.offsetHeight;this.Move("collapse");}},expand:function(){if(this.$container.offsetHeight < this.$rawHeight && this.$animating != true){this.$animating = true;this.$currentHeight = this.$container.offsetHeight;this.Move("expand");}},Move:function(method){clearTimeout(this.$Timer);var oThis = this;if(method=="collapse"){var iStep =this.GetStep(Math.abs(this.$currentHeight - this.$targetHeight));if(iStep != 0){this.$currentHeight = this.$currentHeight - iStep;this.$container.style.height =this.$currentHeight + "px";this.$Timer = setTimeout(function(){oThis.Move("collapse");},this.$Speed);}else{this.$container.style.height = this.$targetHeight + "px";this.$trigger.className = this.$expandCss;this.$isexpanded = false;this.Finished();}}else{iStep = this.GetStep(Math.abs(this.$rawHeight - this.$currentHeight)); if(iStep != 0){this.$currentHeight = this.$currentHeight + iStep;this.$container.style.height = this.$currentHeight + "px";this.$Timer = setTimeout(function(){oThis.Move("expand");},this.$Speed);}else{this.$container.style.height = this.$rawHeight + "px";this.$trigger.className = this.$collapseCss;this.$isexpanded = true;this.Finished();}}},Finished:function(){clearTimeout(this.$Timer);this.$animating = false;this.$currentHeight = 0;},GetStep:function(iNow){ var iStep = iNow / this.$Step; if(iStep <= 0) return 0;if (Math.abs(iStep) < 1) return 0;return iStep;}}
