(function() {
var YUD = YAHOO.util.Dom;
var YUE = YAHOO.util.Event;

var carousel = function(el,config) {
    this.init(el);
    this.parseConfig(config);
}

carousel.prototype = {
    elBase:null,
    elCurrentThumb:null,
    elFocusList:null,
    init:function(el) {
        if ( typeof el === "string" ) {
            this.elBase = YUD.get (el);
        } else {
            this.elBase = el;
        }
        this.elFocuseList = YUD.getElementsByClassName("focus-list","ul",this.elBase).shift();
        this.elCurrentThumb = YUD.getElementsByClassName("selected","img",this.elBase).shift();
        YUE.on(this.elBase,"click",this._handleClick,this,true);
    },
    parseConfig:function() {
    },
    switchImg:function(elThumb,offset) {
        this.switchThumbHighlight(elThumb);
        this.changeFocusImg(offset);
    },
    switchThumbHighlight:function(elThumb) {
        YUD.removeClass(this.elCurrentThumb,"selected");
        YUD.addClass(elThumb,"selected");
        this.elCurrentThumb = elThumb;
    },
    changeFocusImg:function(offset) {
        var m;
        m = (parseInt(offset,10) - 1) * -400;
        this.elFocuseList.style.marginLeft = m+"px";
    },
    _handleClick:function(evt) {
        var idx;
        var target = evt.target || evt.srcElement;
        if ( YUD.hasClass(target,"select-thumb" ) ) {
            idx = target.className.match(/thumb-num-(\d+)/)[1];
            if ( idx ) {
                this.switchImg(target,idx);
            }
        }
    }
}

var c = new carousel("ex-carousel");

}());
