﻿/*
 *write by waitingbar
 * time 2011.02.21
 *
 */

$(document).ready(function(){
	$(".star img").css("opacity","0.3");
	$(".star1 img").css("opacity","0.95");
	$(".to_lr_btn .star").css("cursor","pointer");

	$(".gorightbtn img ,.goleftbtn img").css("opacity","0.3");
	$(".gorightbtn img ,.goleftbtn img").hover(function(){
         $(this).css("opacity","1"); 
      },function(){
         $(this).css("opacity","0.4");
    })
});


(function($){
	//扩展这个方法到jquery;
	$.fn.extend({   
		//将可选择的变量传递给方法
		slideimg: function(options) {  
			
			//参数和默认值
			var defaults = {
			   tol_class:'.goleftbtn',       //获得点击左按钮的class
			   tor_class:'.gorightbtn',      //获得点击右按钮的class
			   slide_class:'.slide_tolr',    //获得滑动层的class
			   center_class:'.star',         //获得中间点的class
			   maxnum:'6'   //最多滑动次数；
			}; 
			
			var options = $.extend(defaults, options); 
			var count;
			var checkname;
			
			//遍历匹配元素的集合
			return this.each(function() {
			var o =options;
		    
			//获得最外层的ID; 
			var thisid = $(this).attr("id");
			var slidebar = $($(this).find(o.slide_class),$(this));
			var goleftbtn = $($(this).find(o.tol_class),$(this));
			var gorightbtn = $($(this).find(o.tor_class),$(this));
			var clickCenter = $($(this).find(o.center_class),$(this));
			
			//设置可见层的宽
			o.slide_wid = slidebar.parent().width()
			//设置滑动层的宽；
			slidebar.css("width",(o.slide_wid*o.maxnum+900)+"px");

			$(goleftbtn).click(function(){
				if(count > 1){
				  count--;
				  $("#"+ thisid +" "+o.center_class+" img").css("opacity","0.3");
				   $("#"+ thisid +" "+o.center_class + count + " img").css("opacity","0.95");
				  slidebar.animate({left:'-' + o.slide_wid*(count-1)},{queue:false});
				}else{
				  count = o.maxnum;
				  slidebar.animate({left:'-' + o.slide_wid*(count-1)},{queue:false});
				  $("#"+ thisid +" "+o.center_class+" img").css("opacity","0.3");
				   $("#"+ thisid +" "+o.center_class + count + " img").css("opacity","0.95");
				}
			});
			 
			$(gorightbtn).click(function(){
				if( count < o.maxnum){
				  count++;
				  slidebar.animate({left:'-' + o.slide_wid*(count-1)},{queue:false});
				  $("#"+ thisid +" "+o.center_class+" img").css("opacity","0.3");
				   $("#"+ thisid +" "+o.center_class + count + " img").css("opacity","0.95");	  
				}else{
				  slidebar.animate({left:'0'},{queue:false});
				  count = 1;
				  $("#"+ thisid +" "+o.center_class+" img").css("opacity","0.3");
				   $("#"+ thisid +" "+o.center_class + count + " img").css("opacity","0.95");
				}
			});
			
			$(clickCenter).click(function(){     
				   checkname = $(this).attr("name");
				   count = checkname;
				   slidebar.animate({left:'-' + o.slide_wid*(count-1)},{queue:false});
				   $("#"+ thisid +" "+o.center_class+" img").css("opacity","0.3");
				   $("#"+ thisid +" "+o.center_class + count + " img").css("opacity","0.95");
			});
			
		    });  
		}  
	});  
})(jQuery);
