// JavaScript Document
jQuery(function(){
  var i=0;
  var j=0;
  var k=0;
  var nownum=0;
  var spacing=980;
  var hspacing=546;
  var maxnum=23;
  var bluricon = "-64px";
  var focusicon = ['-65px','-152px','-192px','-230px','-274px','-313px','-347px','-379px','-416px','-452px','-491px','-527px','-562px','-590px','-621px','-657px','-694px','-737px','-778px','-815px','-856px','-901px','-934px'];
  var images = new Array();
       images[0]='./images/content1.jpg';
	   images[1]='./images/content2.jpg';
	   images[2]='./images/content3.jpg';
	   images[3]='./images/content4.jpg';
	   images[4]='./images/content5.jpg';
	   images[5]='./images/content6.jpg';
	   images[6]='./images/content7.jpg';
	   images[7]='./images/content8.jpg';
	   images[8]='./images/content9.jpg';
	   images[9]='./images/content10.jpg';
	   images[10]='./images/content11.jpg';
	   images[11]='./images/content12.jpg';
	   images[12]='./images/content13.jpg';
	   images[13]='./images/content14.jpg';
	   images[14]='./images/content15.jpg';
	   images[15]='./images/content16.jpg';
	   images[16]='./images/content17.jpg';
	   images[17]='./images/content18.jpg';
	   images[18]='./images/content19.jpg';
	   images[19]='./images/content20.jpg';
	   images[20]='./images/content21.jpg';
	   images[21]='./images/content22.jpg';
	   images[22]='./images/content23.jpg';
  var maxs = jQuery(images).length;
   if(maxs>0)
   {
	   LoadImage(0,maxs);
   }
   function LoadImage(index,maxs){
       if(index<maxs){
		  var curr = jQuery("#no-nav div#portfolio_"+index);
		  var img = new Image();
		  //load Img
		  jQuery(img).load(function() {
		      jQuery(this).css('display','none');
			  //jQuery(curr).removeClass('loading').append(this);
			  if(index==0){
				  jQuery(curr).removeClass('loading').addClass('imgbg').append('<div id="onecontent" style="position:relative; width:186px; height:247px; top:111px; left:217px; overflow:hidden;"onmouseover="stopmoves(1);" onmouseout="startmoves(-1);"><div style="width:186px; height:247px; float:left;"><img src="images/gexingzhuti.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/shipinbofang.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/tiyuzhibo.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/hudongyouxi.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/suofangmoshi.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/luntanmoshi.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/jisutiyan.jpg" border="0" /></div><div style="width:186px; height:247px; float:left;"><img src="images/chaoshengliuliang.jpg" border="0" /></div></div><div id="smallbutton" style="position:relative; top:233px; left:178px; width:263px; height:47px; clear:both;" onmouseover="stopmoves(1);" onmouseout="startmoves(-1);"><div id="leftbutton" style="background:url(images/leftbutton.jpg) no-repeat; float:left; width:36px; height:47px; cursor:pointer;"></div><div id="centertext" style="overflow:hidden; position:relative; background-image:url(images/centerbutton.jpg); background-repeat:no-repeat; float:left; width:191px; height:47px;"><div style="float:left; width:191px; height:47px;"><img src="images/gxzt.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/wysp.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/tyzb.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/hdyx.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/sfms.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/ltms.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/jsty.png" border="0" /></div><div style="float:left; width:191px; height:47px;"><img src="images/csll.png" border="0" /></div></div><div id="rightbutton" style="background:url(images/rightbutton.jpg) no-repeat; background-repeat:no-repeat; width:36px; height:47px; cursor:pointer;"></div></div>');
				  setonecontent();
			  }else{
				  jQuery(curr).removeClass('loading').append(this);
			  }
			  jQuery(this).fadeIn('slow',function(){
				  LoadImage(index+1,maxs);
				  j=j+1;
			  });
		  }).error(function(){
		     jQuery(curr).remove();
			 LoadImage(index+1,maxs);
		  }).attr('src',images[index]);
	   }
   }
  jQuery('#no-nav').css({
    'width':spacing,
	'height':hspacing,
	'overflow':'hidden'
  }).find('div').css({
    'float':'none',
	'position':'absolute',
	'left':1000
  });
  var setUpCovers=function() {
      var jQuerycovers=jQuery('#no-nav>div');
	  var jQuerylinknum=jQuery('.feature a');
  //left img turn right
  jQuerycovers.eq(0).css('left',0);
  jQuerylinknum.eq(0).css("background-position",focusicon[0]+" "+bluricon);
  /*jQuerycovers.each(function(index){
	 jQuerycovers.eq(index).click(function(event){
	     if(index==(maxnum-1))
		 {
		    i=0;
	        k=0;
	        ssc=0;
		 }else{
		    i=parseInt(index+1);
	        k=parseInt(index+1);
	        ssc=parseInt(index+1);
		 }
		 for(var i=0;i<maxnum;i++){
		     if(index==(maxnum-1)){
				 jQuerycovers.eq(i).animate({'left':spacing*(i)},'fast');
				 if(i==0){
					jQuerylinknum.eq(i).css("background-position",focusicon[i]+" "+bluricon);
				 }else{
					 jQuerylinknum.eq(i).css("background-position",focusicon[i]+" 0px");
				 }
			 }else{
			   jQuerycovers.eq(i).animate({'left':spacing*(i-1-index)},'fast');
			   if((i-1-index)==0){
				   jQuerylinknum.eq(i).css("background-position",focusicon[i]+" "+bluricon);
			   }else{
				   jQuerylinknum.eq(i).css("background-position",focusicon[i]+" 0px");
			   }
			 }
	     }
	    event.preventDefault(); 
	 });
  });*/
  jQuerylinknum.each(function(index){
     jQuerylinknum.eq(index).click(function(event){
	      i=index;
	      k=index;
		  ssc=index;
		  /*var curr = jQuery("#no-nav div#portfolio_"+index);
		  var img = new Image();
		  jQuery(img).load(function() {
		      jQuery(this).css('display','none');
			  //jQuery(curr).removeClass('loading').append(this);
			  if(index==0){
				  jQuery(curr).removeClass('loading').addClass('imgbg').append('<div id="onecontent" style="position:relative; width:183px; height:245px; margin-top:112px; margin-left:219px; overflow:hidden;"><div style="width:183px; height:245px; float:left;">dddddd</div><div style="width:183px; height:245px; float:left;">ssssss</div></div><div id="smallbutton" style="margin-top:123px; margin-left:178px; width:263px; height:47px; clear:both;"><div id="leftbutton" style="background-image:url(images/leftbutton.jpg); background-repeat:no-repeat; float:left;"></div><div id="centertext" style="background-image:url(images/centerbutton.jpg); background-repeat:no-repeat;"></div><div id="rightbutton" style="background-image:url(images/rightbutton.jpg); background-repeat:no-repeat; float:left;"></div></div>');
				  setonecontent();
			  }else{
				  jQuery(curr).removeClass('loading').append(this);
			  }
			  jQuery(this).fadeIn('slow');
		  }).attr('src',images[index]);*/
		for(var i=0;i<maxnum;i++){
			jQuerycovers.eq(i).animate({'left':spacing*(i-index)},'fast');
			if((i-index)==0){
				jQuerylinknum.eq(i).css("background-position",focusicon[i]+" "+bluricon);
			}else{
				jQuerylinknum.eq(i).css("background-position",focusicon[i]+" 0px");
			}
		}
		event.preventDefault();
	 });
  });
	};
	setUpCovers();
	/*setInterval(function(){
	  var autocovers=jQuery('#no-nav>div');
	  var linknum=jQuery('.feature a');
	  if(i>=j-1) {i=j;}
	  if(k>j-1) {i=k;}
	  if(ssc>=0) {i=ssc;}
		for(var j=0;j<maxnum;j++){
			autocovers.eq(j).animate({'left':spacing*(j-i)},'fast');
			if((j-i)==0){
				linknum.eq(j).css("background-position",focusicon[j]+" "+bluricon);
			}else{
				linknum.eq(j).css("background-position",focusicon[j]+" 0px");
			}
		}
	  i++;
	  if(i>(maxnum-1)){i=0;}
	},5000);*/
  var setonecontent=function(){ 
  jQuery('#onecontent').find('div').css({
    'float':'none',
	'position':'absolute',
	'cursor':'pointer',
	'left':200
  });
  jQuery('#centertext').find('div').css({
    'float':'none',
	'position':'absolute',
	'cursor':'pointer',
	'left':200
  });
  jQuery('#leftbutton').mousedown(function(){
		jQuery('#leftbutton').css("background","url(images/leftdownbutton.jpg) no-repeat");
  }).mouseup(function() {
		jQuery('#leftbutton').css("background","url(images/leftbutton.jpg) no-repeat");
  }).mouseout(function() {
		jQuery('#leftbutton').css("background","url(images/leftbutton.jpg) no-repeat");
  });
  jQuery('#rightbutton').mousedown(function(){
		jQuery('#rightbutton').css("background","url(images/rightdownbutton.jpg) no-repeat");
  }).mouseup(function() {
		jQuery('#rightbutton').css("background","url(images/rightbutton.jpg) no-repeat");
  }).mouseout(function() {
		jQuery('#rightbutton').css("background","url(images/rightbutton.jpg) no-repeat");
  });
  jQuery('#leftbutton').click(function(){
									   
  });
  var onecover=jQuery('#onecontent>div');
  onecover.eq(0).css('left',0);
  var onetext=jQuery('#centertext>div');
  onetext.eq(0).css('left',0);
	var k=0;
	var onemax=8;
	var onespacing=186;
	var ontextspacing=191;
	setInterval(function(){
		var onecover=jQuery('#onecontent>div');
		var onetext=jQuery('#centertext>div');
		if(onesc==1){k=nownum;}
		for(var h=0;h<onemax;h++){
			onecover.eq(h).animate({'left':onespacing*(h-k)},'fast');
			onetext.eq(h).animate({'left':ontextspacing*(h-k)},'fast');
		}
		k++;
		nownum=k-1;
		if(k>(onemax-1)){k=0;}
	},3000);
  jQuery('#leftbutton').click(function(){
		var strtmp=nownum+1;
		if(strtmp<onemax){
			for(var i=0;i<onemax;i++)
			{
				onecover.eq(i).animate({'left':onespacing*(i-strtmp)},'fast');
				onetext.eq(i).animate({'left':ontextspacing*(i-strtmp)},'fast');
			}
			k=strtmp;
			nownum=strtmp;
		}else{
			strtmp=0;
			k=0;
			nownum=0;
			for(var i=0;i<onemax;i++)
			{
				onecover.eq(i).animate({'left':onespacing*(i-strtmp)},'fast');
				onetext.eq(i).animate({'left':ontextspacing*(i-strtmp)},'fast');
			}
		}
  });
  jQuery('#rightbutton').click(function(){
		var strtmp=nownum-1;
		if(strtmp>=0){
		    for(var i=0;i<onemax;i++)
			{
				onecover.eq(i).animate({'left':onespacing*(i-strtmp)},'fast');
				onetext.eq(i).animate({'left':ontextspacing*(i-strtmp)},'fast');
			}
			k=strtmp;
			nownum=strtmp;
		}else{
			strtmp=onemax-1;
			k=onemax-1;
			nownum=onemax-1;
			for(var i=0;i<onemax;i++)
			{
				onecover.eq(i).animate({'left':onespacing*(i-strtmp)},'fast');
				onetext.eq(i).animate({'left':ontextspacing*(i-strtmp)},'fast');
			}
		}
  });
  }
	//clearInterval(intervalId);
});