/**
 *
 * ex.ui.tabs.js
 * 
 * @version 1.0
 * @author Tatsuhisa Ishikawa
 *
 */
 
(function(jQuery){
	ex.Tabs = ex.Class.create();
	Object.extend(ex.Tabs.prototype, (function(){
		return {
			defaults : {
				currentIndex : 0,
				classNames : {
					tab : 'tab',
					tabActive : 'tab_active',
					content : 'tab_content'
				}
			},
			tabs : undefined,
			tab_contents : undefined,
			opts : {},
			initialize : function (target, options){
				var s = this;
				s.opts = Object.extend(s.defaults, options);
				
				s.tabs = $(target).find('.' + s.opts.classNames.tab);
				s.tab_contents = $(target).find('.' + s.opts.classNames.content);
				var size = s.tabs.length;
				
				for(var i = 0; i < size; i++){
					var tab = s.tabs.get(i);
					var tab_content = s.tab_contents.get(i);
					tab.index = i;
					$(s.tab_contents.get(i)).css({display:'none'});
					$(tab).click(function(e){
						for(var j = 0; j < size; j++){
							$(s.tab_contents.get(j)).css({display:'none'});
						}
						$(s.tabs.get(s.opts.currentIndex)).removeClass(s.opts.classNames.tabActive);
						$(s.tab_contents.get(s.opts.currentIndex)).css({display:'none'});
						s.opts.currentIndex = this.index;
						$(this).addClass(s.opts.classNames.tabActive);
						$(s.tab_contents.get(s.opts.currentIndex)).css({display:'block'});
						return false;
					})
				}
				s.opts.currentIndex = 0;
				$(s.tabs.get(s.opts.currentIndex)).addClass(s.opts.classNames.tabActive);
				$(s.tab_contents.get(s.opts.currentIndex)).css({display:'block'});
			}
		}
	})());
	
	jQuery.fn.exTabs = function(options){
		return this.each(function(){ 
			new ex.Tabs(this, options); 
		});
	}
})(jQuery);
