/*$(function(){
	$('#adblock ul.link li a').each(function(i){
		// 把選單排好位置
		$(this).css('top', i * 50);
	});
});
*/
$(function(){
	// 大廣告圖片的高度及動畫時間
	var adHeight = 200,
		animateSpeed = 400;
	$('#adblock ul.link li a').each(function(i){
		// 把選單排好位置
		$(this).css('top', i * 50);
	}).mouseover(function(){
		var $this = $(this),
			// 找出目前 li 是在選單中的第幾個(jQuery 1.4)
			no = $this.parent().index();

		// 先移除有 .selected 的超連結的樣式
		$('#adblock ul.link li a.selected').removeClass('selected');
		// 再把目前點擊到的超連結加上 .selected
		$this.addClass('selected');

		// 把 ul.showbox 的 top 移到相對應的高度
		$('#adblock ul.showbox').stop().animate({
			top: adHeight * no * -1
		}, animateSpeed);
	}).focus(function(){
		$(this).blur();
	}).eq(0).mouseover();
});

$(function(){
	// 大廣告圖片的高度及動畫時間
	// 計時器及輪播時間(毫秒)
	var adHeight = 250,
		animateSpeed = 400,
		timer,
		speed = $('#home_broadcast_sec').val();

	function showNext(){
		// 找出目前是第幾個選項被展示出來(jQuery 1.4)
		var $li = $('#adblock ul.link li'),
			no = $li.has('a.selected').index();

		// 計算出下一個要展示的廣告選項
		no = (no + 1) % $li.length;

		// 觸髮指定選項的 mouseover 事件
		$li.eq(no).children('a').mouseover();

		// 再啟動計時器
		timer = setTimeout(showNext, speed);
	}

	$('#adblock ul.link li a').each(function(i){
		$(this).css('top', i * 50);
	}).hover(function(){
		var $this = $(this),
			// 找出目前 li 是在選單中的第幾個(jQuery 1.4)
			no = $this.parent().index();

		// 先移除有 .selected 的超連結的樣式
		$('#adblock ul.link li a.selected').removeClass('selected');
		// 再把目前點擊到的超連結加上 .selected
		$this.addClass('selected');

		// 把 ul.showbox 的 top 移到相對應的高度
		$('#adblock ul.showbox').stop().animate({
			top: adHeight * no * -1
		}, animateSpeed);

		// 移除計時器
		clearTimeout(timer);
	}, function(){
		// 啟動計時器
		timer = setTimeout(showNext, speed);
	}).focus(function(){
		$(this).blur();
	}).eq(0).addClass('selected');

	// 當滑鼠移到廣告上時停止計時器..移出後啟動計時器
	$('#adblock ul.showbox li').hover(function(){
		clearTimeout(timer);
	}, function(){
		timer = setTimeout(showNext, speed);
	});

	// 啟動計時器
	timer = setTimeout(showNext, speed);

        //廣播
       // $('#news ul').cycle('fade');
  


});
//廣播2
//$(function(){
//		// 先取得 div#abgne_marquee ul
//		// 接著把 ul 中的 li 項目再重覆加入 ul 中(等於有兩組內容)
//		// 再來取得 div#abgne_marquee 的高來決定每次跑馬燈移動的距離
//		// 設定跑馬燈移動的速度及輪播的速度
//		var $marqueeUl = $('div#abgne_marquee ul'),
//			$marqueeli = $marqueeUl.append($marqueeUl.html()).children(),
//			_height = $('div#abgne_marquee').height() * -1,
//			scrollSpeed = 600,
//			timer,
//			speed = 3000 + scrollSpeed,
//			direction = 0,	// 0 表示往上, 1 表示往下
//			_lock = false;
//
//		// 先把 $marqueeli 移動到第二組
//		$marqueeUl.css('top', $marqueeli.length / 2 * _height);
//
//		// 幫左邊 $marqueeli 加上 hover 事件
//		// 當滑鼠移入時停止計時器；反之則啟動
//		$marqueeli.hover(function(){
//			clearTimeout(timer);
//		}, function(){
//			timer = setTimeout(showad, speed);
//		});
//
//		// 判斷要往上還是往下
//		$('div#abgne_marquee .marquee_btn').click(function(){
//			if(_lock) return;
//			clearTimeout(timer);
//			direction = $(this).attr('id') == 'marquee_next_btn' ? 0 : 1;
//			showad();
//		});
//
//		// 控制跑馬燈上下移動的處理函式
//		function showad(){
//			_lock = !_lock;
//			var _now = $marqueeUl.position().top / _height;
//			_now = (direction ? _now - 1 + $marqueeli.length : _now + 1)  % $marqueeli.length;
//
//			// $marqueeUl 移動
//			$marqueeUl.animate({
//				top: _now * _height
//			}, scrollSpeed, function(){
//				// 如果已經移動到第二組時...則馬上把 top 設回到第一組的最後一筆
//				// 藉此產生不間斷的輪播
//				if(_now == $marqueeli.length - 1){
//					$marqueeUl.css('top', $marqueeli.length / 2 * _height - _height);
//				}else if(_now == 0){
//					$marqueeUl.css('top', $marqueeli.length / 2 * _height);
//				}
//				_lock = !_lock;
//			});
//
//			// 再啟動計時器
//			timer = setTimeout(showad, speed);
//		}
//
//		// 啟動計時器
//		timer = setTimeout(showad, speed);
//
//		$('a').focus(function(){
//			this.blur();
//		});
//	});
