// JavaScript Document

	function roll_play(par,iul,ptcr){
	$(function(){
		// 先取得必要的元素並用 jQuery 包裝
		// 再來取得 $block 的高度及設定動畫時間
		var $block = $('#'+par),
			$slides = $('ul.'+iul, $block),
			_width = $block.width(),
			$li = $('li', $slides),
			_animateSpeed = 600, 
			// 加入計時器, 輪播時間及控制開關
			timer, _showSpeed = 1000, _stop = false;

		//1. 產生in_pctrl  li 選項
		var _str = '';		
		for(var i=0, j=$li.length;i<j;i++){
			// 每一個 li 都有自己的 className = in_pctrl_號碼
			_str += '<li class="in_pctrl_' + (i+1) + '">'+(i+1) +'</li>';
		}

		//获取号码 ul 並把 li 選項加到其中
		var $_pctrl=$("."+ptcr);
		$(_str).appendTo($_pctrl);

		
		// 幫 li 加上 click 事件
		var $_pctrlLi = $_pctrl.find('li').click(function(){
			var $this = $(this);
			$this.addClass('current').siblings('.current').removeClass('current');

			clearTimeout(timer);
			// 移動位置到相對應的號碼
			$slides.stop().animate({
				left: _width * $this.index() * -1
			}, _animateSpeed, function(){
				// 當廣告移動到正確位置後, 依判斷來啟動計時器
				if(!_stop) timer = setTimeout(move, _showSpeed);
			});
			

			return false;
		}).eq(0).click().end();

		// 如果滑鼠移入 $block 時
		$block.hover(function(){
			// 關閉開關及計時器
			_stop = true;
			clearTimeout(timer);
		}, function(){
			// 如果滑鼠移出 $block 時
			// 開啟開關及計時器
			_stop = false;
			timer = setTimeout(move, _showSpeed);
		});
		
		// 計時器使用
		function move(){
			var _index = $('.current').index();
			$_pctrlLi.eq((_index + 1) % $_pctrlLi.length).click();
		}
	});
	}
	
// JavaScript Document

	function roll(par,iul,ptcr){
	$(function(){
	var $_ad = $('#'+iul+' li'),
		showIndex = 0,			
		fadeOutSpeed = 800,	
		fadeInSpeed = 1000,		
		defaultZ = 10,			
		isHover = false,
		timer, speed = 2000;	
 
	
	$_ad.css({
		opacity: 0,
		zIndex: defaultZ - 1
	}).eq(showIndex).css({
		opacity: 1,
		zIndex: defaultZ
	});
 
	
	var str = '';
	for(var i=0;i<$_ad.length;i++){
		str += '<a>' + (i + 1) + '</a>';
	}
	var $_ctrl = $('#'+par).append($('<div class="'+ptcr+'">' + str + '</div>').css('zIndex', defaultZ + 1)).find('.'+ptcr+' a');
	
	$_ctrl.click(function(){
		
		showIndex = $(this).text() * 1 - 1;
 
		
		$_ad.eq(showIndex).stop().fadeTo(fadeInSpeed, 1, function(){
			if(!isHover){
				
				timer = setTimeout(autoClick, speed);
			}
		}).css('zIndex', defaultZ).siblings('li').stop().fadeTo(fadeOutSpeed, 0).css('zIndex', defaultZ - 1);
		
		$(this).addClass('current').siblings().removeClass('current');
 
		return false;
	}).focus(function(){
		$(this).blur();
	}).eq(showIndex).addClass('current');
 
	$_ad.hover(function(){
		isHover = true;
		
		clearTimeout(timer);
	}, function(){
		isHover = false;
		
		timer = setTimeout(autoClick, speed);
	})
	$_ctrl.hover(function(){
		isHover = true;
		
		clearTimeout(timer);
	}, function(){
		isHover = false;
		
		timer = setTimeout(autoClick, speed);
	})
 
	
	function autoClick(){
		if(isHover) return;
		showIndex = (showIndex + 1) % $_ctrl.length;
		$_ctrl.eq(showIndex).click();
	}
 
	
	timer = setTimeout(autoClick, speed);
});
	}
	
