﻿﻿var theInt = null;
var curclicked = 0;
$(document).ready(function(){
  navHover();
  hoverEvent(".head .nav","nav-hover");
  hoverEvent(".more-box .more","more-hover");
  hotNews();
  gameInfo();
  autoPlay();
  autoNoticeScroll();
  navElement();
}) 


function scrollTop(){
  $(".scrolltext ul").children().clone().appendTo(".scrolltext ul");
  var outHeight = $(".scroll")
  var scrollHeight = $(".scrolltext").height();
  
}

function navHover(){
  $(".head .nav").each(function(){
    var left = $(this).position().left - 10;
    $(this).children(".subnav").css("left",left+"px");
  })
}

function hoverEvent(id,className){
	$(id).each(function(){
		$(this).hover(
			function(){
				$(this).addClass(className);
			},
			function(){
				$(this).removeClass(className);
			}
		);
	});
}

function hotNews(){
  $(".hot-tabs li:first").addClass("selected");
  $(".hot-list dd").hide();
  $(".hot-list dd:first").show();
  $(".hot-tabs li").each(function(e){
    $(this).hover(function(){
      $(".hot-tabs li").removeClass("selected");
      $(this).addClass("selected");
      $(".hot-list dd").hide();
      $(".hot-list dd:eq("+e+")").fadeIn();
    },function(){})
  })
}

function gameInfo(){
  $(".game-tabs li:first").addClass($(".game-tabs li:first").attr("class")+"-selected");
  $(".game-info-content dd").hide();
  $(".game-info-content dd:first").show();
  $(".game-tabs li").each(function(e){
    $(this).hover(function(){
      $(".game-tabs li").each(function(){
        if($(this).attr("class").indexOf(" ")> (-1)){
          var newClass = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" "));
          $(this).attr("class",newClass);
        }
      });
      $(this).addClass($(this).attr("class")+"-selected");
      $(".game-info-content dd").hide();
      $(".game-info-content dd:eq("+e+")").show();
    },function(){})
  })
}

function autoPlay(){
  $('#transparence').css('opacity','0.4');
	$('#pic_list img').css({'opacity':'0.6'});
	$('#pic_list img:eq(0)').css({'top':'0','opacity':'1'});
	$('#pic_list a').click(function(){return false});
	fun(0);
	$('#pic_list img').mouseover(function(){
		if($('#big_pic').attr('src') == $(this).attr('src')) return;
		fun($('#pic_list img').index($(this)));
	});
}

fun = function(i){
	clearInterval(theInt);
	if( typeof i != 'undefined' )
    curclicked = i;
		$('#big_pic').fadeOut(0).fadeIn(500).attr('src',$('#pic_list img').eq(i).attr('src'));
		$('#big_imgs').attr('href',$('#pic_list img').eq(i).parents('a').attr('href'));
		$('#big_imgs').attr('title',$('#pic_list img').eq(i).parents('a').attr('title'));
		$('#pic_list img').eq(i).parents('li').nextAll('li').find('img').animate({top:15,opacity:0.6},500);
		$('#pic_list img').eq(i).parents('li').prevAll('li').find('img').animate({top:15,opacity:0.6},500);
		$('#pic_list img').eq(i).animate({top:0},500).css('opacity','1');
    theInt = setInterval(function (){
      i++;
      if (i > $('#pic_list img').length - 1) {i = 0};
      $('#big_pic').fadeOut(0).fadeIn(500).attr('src',$('#pic_list img').eq(i).attr('src'));
      $('#big_imgs').attr('href',$('#pic_list img').eq(i).parents('a').attr('href'));
      $('#big_imgs').attr('title',$('#pic_list img').eq(i).parents('a').attr('title'));
      $('#pic_list img').eq(i).parents('li').nextAll('li').find('img').animate({top:15,opacity:0.6},500);
      $('#pic_list img').eq(i).parents('li').prevAll('li').find('img').animate({top:15,opacity:0.6},500);
      $('#pic_list img').eq(i).animate({top:0},500).css('opacity','1');
    },3000)
}

function autoNoticeScroll(){
  $(".scrolltext ul").hover(function(){
      clearInterval(automoving);
    },function(){
      automoving = setInterval("Moving()",3000)
    }).trigger("mouseleave");  
}

function navElement(){
	$(".col").hover(function(){
	  $(".col").removeClass("hover");
	  $(this).addClass("hover");
	  $(".col ul").hide();
	  $(this).children("ul").show();
	},function(){ $(".col ul").hide(); })
}

function Moving(){
  $(".scrolltext  ul li:first").animate({marginTop:"-24px"},"slow",function(){
    $(this).css("margin-top","0").appendTo($(this).parent());
  }); 
}

$.fn.reorder = function() {
 
  //random array sort from

//http://javascript.about.com/library/blsort2.htm 
  function randOrd() { return(Math.round(Math.random())-0.5); }
 
  return($(this).each(function() {
    var $this = $(this);
    var $children = $this.children();
    var childCount = $children.length;
 
    if (childCount > 1) {
      $children.remove();
 
      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      $.each(indices,function(j,k) { $this.append($children.eq(k)); });
 
    }
  }));
}
