//************滑鼠圖片切換************//
if(lemon == undefined)	var lemon = {};
if(lemon.cx == undefined)lemon.cx = {};
if(lemon.cx.json == undefined)lemon.cx.json = {};
lemon.cx.json.list=function(){}
getobj=function(n){return document.getElementById(n);}
lemon.cx.json.list.prototype={
	init:function(ids){
		oList = getobj(ids);
		oImg = oList.getElementsByTagName("img");
		nLength = oImg.length;
		for (i=0;i<nLength;i++) {
			Images= new Image();
			preloadimg = oImg[i].src.substr(0,oImg[i].src.length-5)+'0'+oImg[i].src.substr(oImg[i].src.length-4,oImg[i].src.length);
			Images.src = preloadimg;
		}
		YAHOO.util.Event.addListener(oImg ,'mouseover',this.onChgDarkImg);
		YAHOO.util.Event.addListener(oImg ,'mouseout',this.onChgLightImg);
	},
	onChgDarkImg:function(){
		this.src = this.src.substr(0,this.src.length-5)+'0'+this.src.substr(this.src.length-4,this.src.length);
	},
	onChgLightImg:function(event,args){
		this.src = this.src.substr(0,this.src.length-5)+'1'+this.src.substr(this.src.length-4,this.src.length);
	}
}

function onloaded(){
	//滑鼠圖片切換
	oList = new lemon.cx.json.list();
	oList.init('Home_content');
	//跑馬燈
	slideLine('ann_box','div',2000,40,24);//slideLine(外面div的id名稱,裡面的標籤類型,延遲毫秒數,速度,高度)
}

//************跑馬燈************//
function slideLine(box,stf,delay,speed,h){
	var slideBox = document.getElementById(box);	//取得id
	var delay = delay||1000; 						//delay:幾毫秒滾動一次(1000毫秒=1秒)
	var speed = speed||20;							//speed:數字越小越快
	var h = h||24;									//h:高度
	var tid = null;
	var pause = false;
	var s = function(){tid=setInterval(slide, speed);}//(執行slide,每speed秒)
	//主要動作的地方
	var slide = function(){
		if(pause) return;							//當滑鼠移到上面的時候就會暫停
		slideBox.scrollTop += 1;					//滾動條往下滾動 數字越大會越快但是看起來越不連貫，所以這邊用1
		if(slideBox.scrollTop%h == 0){				//滾動到一個高度(h)的時候就停止
			clearInterval(tid);						//跟setInterval搭配使用的
			slideBox.appendChild(slideBox.getElementsByTagName(stf)[0]);//將剛剛滾動上去的前一項加回到整列的最後一項
			slideBox.scrollTop = 0;  				//再重設滾動條到最上面
			setTimeout(s, delay);					//延遲多久再執行一次
		}
	}
	//滑鼠移上去會暫停 移走會繼續動
	slideBox.onmouseover=function(){pause=true;}
	slideBox.onmouseout=function(){pause=false;}
	setTimeout(s, delay);				//起始的地方，沒有這個就不會動囉
}

//************Onload************//
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {window.onload = func;} 
	else {window.onload = function() {oldonload();func();}}
}
addLoadEvent(onloaded);