jQuery(function($) {
$.fn.cx_slider = function(options){		
	var defaults = {
		siteWidth:'',
		imgHeight:'',
		speed:500,
		waitTime:3000
	}
	var options = $.extend(defaults, options);
	var base = this;
	count = 0;
	//options.pos
		$(base).css({"position":"relative","overflow":"hidden","height":options.imgHeight});
		$(base).append("<span class=\"arr_left\"><img src=\"./layouts/xeview_layout/images/arr_left.png\" /></span><span class=\"arr_right\"><img src=\"./layouts/xeview_layout/images/arr_right.png\" /></span>");
		$(".arr_left",base).css({"position":"absolute","left":"10px","top":"45%","opacity":"0","marginTop":0,"cursor":"pointer"});
		$(".arr_right",base).css({"position":"absolute","right":"10px","top":"45%","opacity":"0","marginTop":0,"cursor":"pointer"});
		$("ul",base).css({"position":"relative","width":"100000px"});
		$("ul li",base).css({"float":"left","marginLeft":""});
		$("ul li img",base).height(options.imgHeight)
		$(base).hover(function(){$(".arr_left , .arr_right",base).stop(true,true).animate({"opacity":0.8},300)},function(){$(".arr_left , .arr_right",base).stop(true,true).animate({"opacity":0},300)});
		$(".arr_right",base).click(function(){
			count += 1;
			if(count>=$("ul li",base).length){
				count=0;	
			}
			$("ul",base).stop(true,true).animate({"marginLeft":-$("ul li img",base).width()*count},options.speed);
		})
		$(".arr_left",base).click(function(){
			if(count<=0){
				count=$("ul li",base).length;	
			}
			count -= 1;
			$("ul",base).stop(true,true).animate({"marginLeft":-$("ul li img",base).width()*count},options.speed);
		})
		function auto_play(){
			count += 1;
			if(count>=$("ul li",base).length){
				count=0;	
			}
			$("ul",base).stop(true,true).animate({"marginLeft":-$("ul li img",base).width()*count},options.speed);
		}
		wait = setInterval(auto_play,options.waitTime);
		$(base).hover(function(){
			clearTimeout(wait)						   
		},function(){
			wait = setInterval(auto_play,options.waitTime);				   
		})
			sw();
			$(window).resize(function(){
				sw();
			})
			function sw(){
			//$(window).width()
				$("ul",base).animate({"marginLeft":0},options.siteWidth);
				count=0
				if($(window).width()<=options.siteWidth){
					$(base).css({"width":"100%"});
					$("ul li img",base).css({"width":$(window).width()});
				}else{
					$(base).css({"width":options.siteWidth});
					$("ul li img",base).css({"width":options.siteWidth});
				}	
				if($(window).width()<=600){
					$(".arr_left img",base).css({"width":"30px","marginTop":"-0"})
					$(".arr_right img",base).css({"width":"30px","marginTop":"-0"})
				}else{
					$(".arr_left img",base).css({"width":"51px","marginTop":"-0"})
					$(".arr_right img",base).css({"width":"51px","marginTop":"-0"})
				}	
			}
	}

});