//<!--
(function($) {
    $.fn.contentSlider = function(options){
        // default configuration properties
        var defaults = {
            fx:                     'fade',
            speed: 			1000,
            auto:			false,
            pause:			3000,
            continuous:		false
        };
        var options = jQuery.extend(defaults, options);
        this.each(function() {
            var obj = jQuery(this);
            var s = jQuery("a.one", obj).length;
            var w = jQuery("a.one", obj).width();
            var h = jQuery("a.one", obj).height();
            var elements = jQuery("a.one",obj);        
            var ts = s-1;
            var t = 0;
            if(options.fx == 'fade'){
                for (var i = 0; i < elements.length; i++) {
                    jQuery(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
                };
            }
            if(options.fx == 'slide'){
                jQuery("a.one", obj).css('float','left');
            }
            jQuery("a","#"+options.nextId).mouseover(function(){
                animate("next",true);
            });
            jQuery("#li_1").mouseover(function(){
                animate("one",true);
            });
            jQuery("#li_2").mouseover(function(){
                animate("two",true);
            });
            jQuery("#li_3").mouseover(function(){
                animate("three",true);
            });
            jQuery("#li_4").mouseover(function(){
                animate("four",true);
            });
             jQuery("#li_5").mouseover(function(){
                animate("five",true);
            });
            function animate(dir,clicked){
                var ot = t;
                switch(dir){
                    case "next":
                        t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;
                        break;
                    case "one":
                        t = 0 ;
                        clearTimeout(timeout);
                        timeout =  setTimeout(function() {
                            animate("next",false);
                        }, options.pause);
                        break;
                    case "two":
                        t = 1 ;
                        clearTimeout(timeout);
                        timeout =  setTimeout(function() {
                            animate("next",false);
                        }, options.pause);
                        break;
                    case "three":
                        t = 2;
                        clearTimeout(timeout);
                        timeout =  setTimeout(function() {
                            animate("next",false);
                        }, options.pause);
                        break;
                    case "four":
                        t = 3;
                        clearTimeout(timeout);
                        timeout =  setTimeout(function() {
                            animate("next",false);
                        }, options.pause);
                        break;
                    case "five":
                      t = ts;
                        clearTimeout(timeout);
                        timeout =  setTimeout(function() {
                            animate("next",false);
                        }, options.pause);
                        break;
                    default:
                        break;
                };
                jQuery("#li_"+(ot+1).toString()).attr("class","");
                jQuery("#li_"+(t+1).toString()).attr("class","selected_color");
                var diff = Math.abs(ot-t);
                var speed = diff*options.speed;
                op = (ot*w*-1);
                p = (t*w*-1);
                if(options.fx == 'fade'){
                    jQuery(elements[ot]).fadeOut(options.speed);
                    jQuery(elements[t]).fadeIn(options.speed);
                }
                if(options.fx == 'slide'){
                    if(p == 0){ // 返回到第一张图片 , 变class
                        jQuery("#li_1").attr("class","selected_color");
                        speed = speed/4 ; // 加快第4张到第一张间的滑动速度
                    }
                    jQuery("div.index_ad_content",obj).animate(
                    {
                        marginLeft: p
                    },
                    speed
                    );
                }
                // if(clicked) clearTimeout(timeout); // 点击后 停止滚动
                if(options.auto && dir=="next" && !clicked){;
                    timeout = setTimeout(function(){
                        animate("next",false);
                    },diff*options.speed+options.pause);
                };
            };
            // init
            var timeout;
            if(options.auto){;
                jQuery(elements[0]).show();
                timeout =  setTimeout(function() {
                    animate("next",false);
                }, options.pause);
            };
        });
    };
})(jQuery);
  
jQuery(document).ready(function(){
    jQuery("#li_1").attr("class","selected_color");  
    jQuery("#index_ad_images").contentSlider({
        fx: 'fade', // 效果 , fade 渐隐 , slide 滑动
        auto: true, // 自动播放
        continuous: true , // 一次循环后是否继续循环
        speed: 1100, // 单张图片滑动速度
        pause: 8000 // 间隔停顿时间 , 毫秒
    });
});
 // -->