//jquery plugins	幻灯
/*********************************
slideId : 幻灯盒子
speed : 幻灯速度

v 1.0
*********************************/
/*********************************
例子:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="jquery_dongSlide_1.0.js"></script>
<script>
$(document).ready(function(){
	jQuery.dongSlide("slide", 2000);
});
</script>
<style>
.slide, .slide .pic img {width:338px; height:229px;}

.slide { position:relative; overflow:hidden; }
.slide ul, .slide li { margin:0; padding:0; list-style-type:none; position:absolute; }
.slide .num li { position:absolute; width:25px; height:15px; z-index:99; }
.slide .num li.over img { visibility:hidden; }

.rollBox{position:relative;}
.bg { position:absolute; top:0; left:0; width:338px; height:229px; z-index:20; }
</style>
</head>
<body>
<div class="rollBox">
  <div class="slide">
    <ul class="pic">
  <div class="bg"><img src="images/index_roll_bg.gif" width="338" height="229" /></div>
      <li><img src="images/1.jpg" /></li>
      <li><img src="images/2.jpg" /></li>
      <li><img src="images/3.jpg" /></li>
      <li><img src="images/4.jpg" /></li>
    </ul>
    <ul class="num">
      <li style="background:url(images/pl1a.gif) no-repeat;"><img src="images/pl1.gif" /></li>
      <li style="background:url(images/pl2a.gif) no-repeat;"><img src="images/pl2.gif" /></li>
      <li style="background:url(images/pl3a.gif) no-repeat;"><img src="images/pl3.gif" /></li>
      <li style="background:url(images/pl4a.gif) no-repeat;"><img src="images/pl4.gif" /></li>
    </ul>
  </div>
</div>
</body>
</html>

*********************************/
jQuery.extend({
	dongSlide : function(slideId, speed ){
		var time=null;
		var over=false;
		var numNow=0;
		var numPre=0;
		//
		var picWidth = $("."+ slideId +" .pic>li").width();
		var boxWidth = $("."+ slideId +"").width()-10;
		var boxHeight = $("."+ slideId +"").height()-5;
		var numLiWidth = $("."+ slideId +" .num>li").width();
		var numLiHeight = $("."+ slideId +" .num>li").height();
		var numLiLength = $("."+ slideId +" .num>li").length;
		var liLen = numLiLength-1;
		//pic li
		$.each( $("."+ slideId +" .pic>li"), function(i, n){
			var t = $(n);
			t.css({"left":picWidth, "z-index":0, opacity: 0});
			if (i==0){
				t.css({"left": 0, "opacity": 1});
			}
		});
		//number li
		var x = boxWidth-numLiWidth*numLiLength;
		var y = boxHeight-numLiHeight;
		$.each( $("."+ slideId +" .num>li"), function(i, n){
			var t = $(n);
			t.css({"left":x, "top":y});
			x=x+t.width();
			//number li hover
			t.hover(
				function(){
					clearTimeout(time);
					numPre=numNow;
					numNow=i;
					over=true;
					doPage();
				},
				function(){
				}
			);
		});
		//slide box hover
		$("."+ slideId +"").hover(
			function(){
				clearTimeout(time);
				over=true;
			},
			function(){
				over=false;
				doPage();
			}
		);
		//main animate
		function doPage(){
			clearTimeout(time);
			
			if (over==false){
				numPre=numNow;
				numNow++;
			}
			if (numNow>liLen){
				numNow=0;
			}
			//
			var prevImgLi = $("."+ slideId +" .pic>li:eq("+ (numPre) +")");
			var prevNumLi = $("."+ slideId +" .num>li:eq("+ (numPre) +")");
			var nextImgLi = $("."+ slideId +" .pic>li:eq("+ (numNow) +")");
			var nextNumLi = $("."+ slideId +" .num>li:eq("+ (numNow) +")");
			//
			prevNumLi.removeClass("over");
			nextNumLi.addClass("over");
			//
			prevImgLi.css({"z-index": 1});
			nextImgLi.css({"z-index": liLen+1});
			//
			bgSrc(nextImgLi)
			//
			if (liLen>1){
				//
				nextImgLi.animate(
					{left: 0, opacity: 1}, 
					"slow",
					function(){
						prevImgLi.css({left: picWidth, opacity:0});
						if(over==false){
							time=setTimeout(doPage,speed);
						}else{
							clearTimeout(time);
						}
					}
				);
			}
		}
		//main
		
		function bgSrc(li){
			var href = li.children("a").attr("href");
			var bgImg = $("."+ slideId +" .pic>.bg>img");
			bgImg.css({cursor:"pointer"});
			bgImg.click(function(){window.location.href=href});
			//alert(href);
		}
		
		$("."+ slideId +" .num>li:eq(0)").addClass("over");
		//
		if (liLen>=0){
			bgSrc($("."+ slideId +" .pic>li:eq(0)"));
			//doPage();
			time=setTimeout(doPage,speed);
		}
	}
});
