
(function($j){
// by hp 2011.5.20
    $j.fn.cooSlide = function(options){
        var defaults = {
                auto    :   true,
                speed   :   5000
            }, 
            options = $j.extend(defaults, options),
            _this = this,
            _timer = null,
            _container = $j("#slide_container"),
            _cur = parseInt($j("#slide_container").css("marginLeft"), 10)/177 + 1,
            _index = _this.find(".current").index(),
            _len = _this.find("span").length;
        if(options.auto){
            _timer = setInterval(function(){
                next(true);
            }, options.speed);
        }
        
        _this.hover(function(){
                if(_timer){
                    clearInterval(_timer);
                }
            }, function(){
                if(options.auto){
                    _timer = setInterval(function(){
                        next(true);
                    }, options.speed);
                }
            });
        
        _this.find(".left").bind('click', function(){pre();});
        _this.find(".right").bind('click', function(){next();});
        
        _this.find("span").bind("mouseover", function(){
            _index = _this.find("span").index(this);
            animate(_index);
        });
        
        function animate(index){
            if(index < _cur){
                _container.animate({"marginLeft": index * 177 * -1});
                _cur = index;
            } else if(index >= _cur + 2){
                _container.animate({"marginLeft": (index - 2) * 177 * -1});
                _cur = index - 2;
            }
            
            _this.find(".current").removeClass("current");
            
            if(index <= 0){
                _this.find(".left").css("background-position", "0 -25px");
            } else {
                _this.find(".left").css("background-position", "0 0");
            }
            
            if(index >= _len - 1){
                _this.find(".right").css("background-position", "0 -75px");
            } else {
                _this.find(".right").css("background-position", "0 -50px");
            }
            
            _this.find(".slider").animate({"top": (index) * 192 * -1}, 500)
            _container.find("span").eq(index).addClass("current");
        }
        
        function pre(){
            --_index;
            _index = _index < 0 ? 0 : _index;
            animate(_index);
        }
        function next(loop){
            _index++;
            if(loop){
                _index = _index % _len;
            } else {
                if(_index >= _len){
                    _index = _len - 1;
                }
            }
            animate(_index);
        }
    };
})(jQuery);

$j(document).ready(function(){
    $j("#Fouce").cooSlide();
	var spans = $j("#main_top").find("span");
	spans.bind("mouseover", function(){
		sqg($j(this).text());
	});
});

