/* 
	* Fadehover 1.0 
	* Date: 2011-09-25
	* Name: chenweigang
	* 按钮渐变效果
*/
(function($) {
		  
		  $.fn.Fadehover = function (Fadehover) {
			  var _Fadehover = $(this).find(Fadehover);
			  var _FadeNav = _Fadehover.find ("li>a[title]")
			  
			  $(_FadeNav).wrapInner('<span class="hover"></span>').each(function () {
				$('span.hover').css('opacity', 0).hover(function () {
					$(this).stop().fadeTo(500, 1);
				}, function () {
					$(this).stop().fadeTo(500, 0);
				});
			});    
	}
		  
})(jQuery);


/*

	* fadeScroll 1.0 
	* Date: 2011-08-08
	* Name: chenweigang
	* 渐隐式轮播 鼠标点击或者滑过时 图片淡入淡出效果
	* 思路是：所有图片通过绝对定位 重叠在一起 设置当前显示的图片的透明度与层级

*/

(function($) {
		  
	$.fn.fadeScroll = function (adG) {
		// 预设各项默认值
		var adG = $(this).find(adG),
			showIndex = 0,
			fadeOutSpeed = 500,
			fadeInSpeed = 500,
			defaultZ = 10,
			isHover = false,
			timer, speed = 3000;

		//设置当前图片的透明度为1 其余为0
		adG.css({
			opacity: 0,
			zIndex: defaultZ - 1
		}).eq(showIndex).css({
			opacity: 1,
			zIndex: defaultZ
		});

		//创建数字编号
		var str = '';
		for(var i=0;i<adG.length;i++){
			str += '<a href="#">' + (i + 1) + '</a>';
		}
		
		//把创建的数字编号添加到页面指定位置 
		var control = $(this).append($('<div class="control">' + str + '</div>').css('zIndex', defaultZ + 1)).find('.control a');
		
	// 若要变成滑鼠滑入來切换时, 可以把 click 换成 mouseover
	control.mouseover(function(){

		// 取得目前点击的号码
		showIndex = $(this).text() * 1 - 1;
 
		// 显示相应的区域
		adG.eq(showIndex).stop().fadeTo(fadeInSpeed, 1, function(){
			if(!isHover){
				// 启动计时器
				timer = setTimeout(autoClick, speed);
			}
		}).css('zIndex', defaultZ).siblings('a').stop().fadeTo(fadeOutSpeed, 0).css('zIndex', defaultZ - 1);
		// 当前数字编码添加class "on"
		$(this).addClass('on').siblings().removeClass('on');		
 		
		return false; //注意此处的 false
	}).focus(function(){
		$(this).blur();
	}).eq(showIndex).addClass('on');
 
	$(this).hover(function(){
		isHover = true;
		// 停止计时器
		clearTimeout(timer);
	}, function(){
		isHover = false;
		// 启动计时器
		timer = setTimeout(autoClick, speed);
	})
	
	// 自动轮播到下一个
	function autoClick(){
		if(isHover) return;
		showIndex = (showIndex + 1) % control.length;
		control.eq(showIndex).mouseover();
		clearTimeout(timer);
	}

	// 启动计时器
	timer = setTimeout(autoClick, speed);
	
	}
})(jQuery);


$(function(){

	$(".header").Fadehover(".unify_nav");
	$("#abgne_fade_pic").fadeScroll("a.adG");
	$(".seclect").hover(function(){
		if(!$("#note").is(':visible')){
		$("#note").css({display:"block",top:"0"}).animate({top:'+=15'},500);
		}
	},function () {
		$("#note").fadeOut();
	});
	
	  $("a.picShow").hover(function(){
           this.myHref = this.href;
		   this.myRel = this.rel;   
        var picShow = "<a id='picShow' href=' "+ this.myHref +" '><img src=' "+ this.myRel +" '><\/a>"; //创建 div 元素
		$(".large_pic,.inner_large_pic").empty()
        $(".large_pic,.inner_large_pic").append(picShow);    //把它追加到文档中
        $("#picShow").fadeIn("fast");
		return false
    })
	
	$("ul#level_one > li:has(ul)").hover(function(){
			//$(this).find("ul").stop(true,true).slideDown("fast");
			if(!$(this).hasClass('current')){
				$("ul#level_one > li:has(ul)").removeClass('current');
				$(this).addClass('current');
			}
		});

		// lunbo
		var $block = $('#abgne-block'),
			$slides = $block.find('ul.abgne-list'),
			_width = $block.width(),
			$li = $slides.find('li'),
			$control = $block.find('.abgne-control'), 
			_animateSpeed = 600, 
			// 加入計時器, 輪播時間及控制開關
			timer, _showSpeed = 5000, _stop = false;
		
		// 設定 $slides 的寬(為了不讓 li 往下擠)
		$slides.css('width', ($li.length + 1) * _width);
		// 產生 li 選項
		var _str = '';
		for(var i=0, j=$li.length;i<j;i++){
			// 每一個 li 都有自己的 className = playerControl_號碼
			_str += '<li class="abgne-player-control_' + (i+1) + '"><span>' + (i+1) + '</span></li>';
		}

		// 產生 ul 並把 li 選項加到其中
		var $number = $('<ul class="numbers"></ul>').html(_str).appendTo($control), 
			$numberLi = $number.find('li');

		// 並幫 .numbers li 加上 click 事件
		$numberLi.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();
		
		// 幫 .arrows li 加上 click 事件
		$control.find('ul.arrows li').click(function(){
			var _index = $numberLi.filter('.current').index();
			$numberLi.eq((this.className.indexOf('next')>-1?_index+1:_index-1+$numberLi.length)%$numberLi.length).click();

			return false;
		});
		
		// 當滑鼠移到 $control li 上時, 加上 .hover 效果
		// 反之則移除
		$control.find('li').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});

		// 如果滑鼠移入 $slides 時
		$slides.hover(function(){
			// 關閉開關及計時器
			_stop = true;
			clearTimeout(timer);
		}, function(){
			// 如果滑鼠移出 $block 時
			// 開啟開關及計時器
			_stop = false;
			timer = setTimeout(move, _showSpeed);
		});
		
		// 計時器使用
		function move(){
			$control.find('ul.arrows li.next').click();
		}

		
})

