// JavaScript Document
/*
$(function(){


	$('#menu li a').mouseover(function(){
		$('embed').remove();
		$('body').append('<embed src="../images/click.mp3" autostart="true" hidden="true" loop="false">');
	});
}); 
*/
 
/*
$(function(){
	$("#menu li a").hover(function(){
		var _this = $(this),
			_height = _this.height() * -1;
		_this.stop().animate({
			backgroundPosition: "0px " + _height + "px",

		}, 200);
	}, function(){
		$(this).stop().animate({
			backgroundPosition: "0px 0px"
		}, 200);
	});
});
*/

$(function(){
	$("#Community li img")
		.css("opacity", 1)
	$("#Community li img").hover(function(){
		$(this).stop().animate({
			opacity: 0.8
		}, 200);
	}, function(){
		$(this).stop().animate({
			opacity: 1
		}, 200);
	});
});


$(function(){
	var $menu = $('#menu'),
		$move = $('#move'),
		$first = $menu.find('.x');
	
	$move.css({
		width: $first.outerWidth(),
		height: $first.outerHeight(),
		top: $first.position().top,
		left: 0,
	})
	$menu.find('a').mouseover(function(){
		var $this = $(this);
		
	$move.stop().animate({
			width: $this.outerWidth(),
			height: $this.outerHeight(),
			top: $this.position().top,
			left: 0,
		});

	});
});
$(function(){
	var timer, speed = 5000, _fadeInSpeed = 1000;
	var $news = $(".news").hover(function(){
		clearTimeout(timer);
		$(".news").stop().animate({
			top: $("#index_slideshow").height() - $(".news").height()
		});
	}, function(){
		$(".news").stop().animate({
			top: $("#index_slideshow").height() - $(".news_control").height()
		});
	}).css({
		opacity: 0, 
		top: $("#index_slideshow").height() - $(".news").height()
	}).animate({
		opacity: 0.9
	}, _fadeInSpeed);

	timer = setTimeout(function(){
		$news.mouseout();
	}, speed);
});	

	function slideSwitch() {
		var $active = $('#index_slideshow IMG.active');
	
		if ( $active.length == 0 ) $active = $('#index_slideshow IMG:last');
	
		var $next =  $active.next().length ? $active.next()
			: $('#index_slideshow IMG:first');
	
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 500, function() {
				$active.removeClass('active last-active');
			});
			
	}
	$(function() {
		setInterval( "slideSwitch()", 5000 );
	});


/*流程*/
$(function(){
	$('.work-slide').each(function(){
		// 先取得相關的元素及寬度等資料
		var $this = $(this), 
			$page = $this.find('.page'), 
			$btn = $this.find('.btn'), 
			_frameWidth = $this.find('.frame').width(), 
			$carousel = $this.find('ul'), 
			$items = $carousel.find('li'), 
			_itemLength = $items.length, 
			_set = Math.ceil(_frameWidth / $items.outerWidth(true)), 
			_count = _itemLength / _set, 
			_width = _set * $items.outerWidth(true) * -1, 
			_speed = 400, _opacity = 0.75, _index = 0;
		
		// 用來顯示目前已顯示及總資料筆數資訊
		$page.html(_set + ' / ' + _itemLength);
		// 幫每一個 li 加上標題及遮罩
		$items.each(function(){
			var $this = $(this), 
				_href = $this.find('a').attr('href'), 
				_title = $this.find('img').attr('title');
				
				$this.append('<div class="ovrly"></div>' +
				'<h5>' + 
					'<a href="' + _href + '" alt="' + _title + '" title="' + _title + '">' + _title + '</a>' + 
				'</h5>').find('.ovrly').css('opacity', _opacity);
			});
			
			// 當按了上下頁的按鈕時
		$btn.find('.prev, .next').click(function(e){
			// 計算要顯示第幾組
			_index = (e.target.className == 'prev' ? _index - 1 + _count : _index + 1) % _count;
			$page.html((_set * (_index + 1)) + ' / ' + _itemLength );
			
			// 進行動畫
			$carousel.stop().animate({
				left: _index * _width
			}, _speed);
		}).focus(function(){
			this.blur();
		});
	})
});

$(function(){
	$(".faq_Q").next().hide().eq(0).show();

	$(".faq_Q").click(function(){
		$(this).next().slideToggle();
	});
});

