// JavaScript Document
$(document).ready(function(){
    init_nav();
    jGund("#gund");  
 }
);
function init_nav(){
   $("#left_nav h2").click(
     function(){
	  h2_click($(this));
	 }
   );
}
function h2_click(tt){
   tt.toggleClass("active");
   tt.next().slideToggle("fast");
   tt.prevAll("h2").removeClass("active");
   tt.nextAll("h2").removeClass("active");
   tt.prevAll(".left_sub").slideUp("faset");
   tt.next().nextAll(".left_sub").slideUp("faset");
}
//单行滚动js
  function goUpOne(obj,pp1,pp2,num){
	    var target=document.getElementById(obj)
		var p1=document.getElementById(pp1);
		var p2=document.getElementById(pp2);
		var setUpOne;
		var setUpT; 
		var i=0;
	//	alert(p1.offsetHeight);
	    if(target==null){
			  return null;
			}
		else{
			  if(Number(p1.offsetHeight)>=Number(target.offsetHeight)){
				    p2.innerHTML=p1.innerHTML;
				  }
			  setUpT=setTimeout(function(){goUp();},2000);
			}
	    target.onmouseover=function(){clearInterval(setUpOne);clearTimeout(setUpT);}
		target.onmouseout=goUp;
	   function goUp(){
							  setUpOne=setInterval(function(){upup();},50);
										  }
		function upup(){
					  target.scrollTop=(i+=29);
					  if(i>=Number(p1.offsetHeight)){
						    i=0;
						  }
					  if(i%num==0){
						    clearInterval(setUpOne);
							clearTimeout(setUpT);
							setUpT=setTimeout(function(){goUp();},2000);
						  };
					}
 }


function jGund(obj){
	  if($(obj).html()==null){
		  return null; 
		 }
	  var pics=document.getElementById(obj.substring(1)).getElementsByTagName("ul");
	  var h=pics[0].offsetHeight;//高
	  
	  var gundT;
	  var gundNum=pics[0].getElementsByTagName("li").length;
	  var gundN=1;
	  $(obj+">div>p").eq(0).addClass="nowp";
	  
	  var nowPic=$(obj+">ul>li:first");
	  nowPic.fadeIn("fast");
	 
      $(obj+">div>p").mouseover(function(){
								//alert(w);
							  //alert($(this).html());
							  clearInterval(gundT);
							  var n=Number($(this).html());//数字
							  gundN=n;
							  if($(this).attr('class')!="nowp"){
								   $(this).addClass("nowp");
								  }
							  $(this).nextAll().removeClass("nowp");
							  $(this).prevAll().removeClass("nowp");
							 // $(obj+">ul").scrollTop((n-1)*h); 简单变化
							  /*animation*/
							 nowPic.fadeOut("fast",
													  function(){
													 	 $(obj+">ul>li").eq(n-1).fadeIn("fast");
														 nowPic=$(obj+">ul>li").eq(n-1);
													  }
													  );
							  /*animation over*/
							}); 
	  $(obj+">div>p").mouseout(function(){										 
								 gundT=setInterval(function(){
									   goByTime();
									 },2000);
							});
	  function goByTime(){
		  gundN++;
			if(gundN>gundNum){
				 gundN=1;
				}
		  /*animation*/
		   nowPic.fadeOut("fast",
													  function(){
													 	 $(obj+">ul>li").eq(gundN-1).fadeIn("fast");
														 nowPic=$(obj+">ul>li").eq(gundN-1);
													  }
											);
		  /*animation over*/
		   $(obj+">div>p").eq(gundN-1).addClass("nowp");
		   $(obj+">div>p").eq(gundN-1).nextAll().removeClass("nowp");
		   $(obj+">div>p").eq(gundN-1).prevAll().removeClass("nowp");			
		  }
	 gundT=setInterval(function(){
								   goByTime();
						
						 },2000); 
	 
	}

//insert flash to Pages.
//By Stones4 2010.04.09
//It is OK in IE6-8 and FF3
 function setFlash(url,w,h){
  var flashHTML='';
  flashHTML+='<object type="application/x-shockwave-flash" data="'+url+'" width="'+w+'" height="'+h+'">';
  flashHTML+='<param name="quality" value="high" />';
  flashHTML+='<param name="movie" value="'+url+'" />';
  flashHTML+='<param name="wmode" value="transparent" />'
  flashHTML+='<param name="swfversion" value="9.0.45.0" />';
  flashHTML+='<param name="expressinstall" value="scripts/expressInstall.swf" />';
  flashHTML+='<embed src="'+url+'" quality="high"   width="'+w+'" height="'+h+'"    type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
  flashHTML+='New FlashPlayer is needed'; 
  flashHTML+='</object>';
 document.write(flashHTML); 
 }
 
 
   function rightBox(obj,n){
	    var target=document.getElementById(obj);
		
		var targetH= n;
	    if(target==null){
			  return null;
			}
		target.style.display="block";
		
/*		  function setBS(){
			   var scrollTop=new Number(document.body.scrollTop || document.documentElement.scrollTop);
			   document.getElementById("scrolltop").innerText=scrollTop;
			   var newOffsetTop=targetH+scrollTop;
			   var oldOffsetTop=target.offsetTop;
			   if(newOffsetTop!=oldOffsetTop){
					target.style.top=oldOffsetTop+(newOffsetTop-oldOffsetTop)*0.1;
				}
		  }*/
		  
		  function rightBh(){
			    if(parseInt(target.offsetHeight)<targetH){
					// target.style.height=Number(parseInt(target.offsetHeight)+1)+"px";
					target.style.height=Number(parseInt(target.offsetHeight)+ (targetH-target.offsetHeight)*0.09 )+"px";
					
					  if(parseInt(target.offsetHeight)+2>targetH)
					    {
							target.style.height=targetH+"px";
							}
					
				}/*else{ 
					  clearInterval(rightBoxhi);
					  rightBoxhi=setInterval(function(){ setBS(); },10);
					}*/
				
			  }
		   var rightBoxhi=setInterval(function(){ rightBh(); },10);
	  }
 
 function closeW(obj){
	  document.getElementById(obj).style.display="none";
	}
