﻿	$(document).ready(function(){	      
        $("#epaper_email").one("click",function(){$(this).val('');});
        $("#set_epaper").click(function(){
           $("#epaper").toggle();
        });
		var $block = $('#abgneBlock'),
			$slides = $('#player ul.list', $block),
			_height = $slides.find('li').height(),
			$li = $('li', $slides),
			_animateSpeed = 400, 
			timer, _speed = 7000;
		var _str = '';
		for(var i=0, j=$li.length;i<j;i++){
			_str += '<li class="playerControl_' + (i+1) + '">' + (i+1) + '</li>';
		}
		var $controlLi = $('<ul class="playerControl"></ul>').html(_str).appendTo($slides.parent()).find('li');
		$controlLi.mouseover(function(){
			clearTimeout(timer);
			var $this = $(this);
			$this.addClass('current').siblings('.current').removeClass('current');
			$slides.stop().animate({
				top: _height * $this.index() * -1
			}, _animateSpeed, function(){
				if(!_isOver) timer = setTimeout(moveNext, _speed);
			});

			return false;
		}).eq(0).mouseover();	

		

		var _isOver = false;
		$block.mouseenter(function(){
			clearTimeout(timer);
			_isOver = true;
		}).mouseleave(function(){
			_isOver = false;
			timer = setTimeout(moveNext, _speed);
		});
		function moveNext(){
			var _now = $controlLi.filter('.current').index();
			$controlLi.eq((_now+1) % $controlLi.length).mouseover();
		}	

	    get_hotproduct($("#tabs").find("li").eq(0));


        //Editor_Choice
        $("#go_nextec").click(function(){
           $.ajax({
              url : 'AJAX/Editor_Choice.aspx?nid=' + $("#EditorChoice1_NECList").val() + '&id=' + $("#EditorChoice1_ECList").val(),
              success : function(res){
                 $("#editor_choice_content").html(res.substr(1,res.length));
                 $("#EditorChoice1_NECList").val(res.substr(0,1))
              }
           });
        });
   
        $("#sub_epaper").click(function(){
           if($("#epaper_email").val() != "") {
 
               $.ajax({
                  url : 'AJAX/set_epaper.aspx?email=' + $("#epaper_email").val(),
                  success : function(res){
                     if(res == "1") {
                         alert('已完成訂閱!')
                     } else {
                        alert('已取消訂閱!')
                     }
                  }
               });           
           } else {
              alert('請輸入emal!');
           }

        });

			
	});
	
	
	function get_hotproduct(obj) {
	    $("#tabs > li").attr("class","active");
	    $(obj).attr("class","");	    
        $.ajax({
           url : 'AJAX/Hot_Product.aspx?kind=' + $(obj).attr("kind"),
           success : function(res){
              $("#hot_carousel").html(res);
           },error : function(err){
              alert(err.responseText)
           }
        })		
	}
	
	

