@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>




@implementation RMTabView : CPView {
	
	CPDictionary buttDict;
	CPButton buttPrev;

	id dele;

	CPColor menuColo;
	CPColor menuSwitColo;
	CPView menuView;
}


- (id) initWithFrame:(CPRect)fram {
	self = [super initWithFrame:fram];

	buttDict = [[CPDictionary alloc] init];
	buttPrev = NULL;

	[self setBackgroundColor:[CPColor orangeColor]];

	var coloStri = [CPString stringWithFormat:@"%x%x%x%x%x%x",
		Math.floor(Math.random()*15.99),Math.floor(Math.random()*15.99),Math.floor(Math.random()*15.99),
		Math.floor(Math.random()*15.99),Math.floor(Math.random()*15.99),Math.floor(Math.random()*15.99)
		];
	menuColo = [CPColor colorWithHexString:@"EEEEEE"];
	menuSwitColo = [CPColor colorWithHexString:@"AABBEE"];

	var menuFram = CPRectMake(0,0,fram.size.width,30);
	menuView = [[CPView alloc] initWithFrame:menuFram];
	[menuView setBackgroundColor:menuColo];
	[self addSubview:menuView];
	
	return self;
}



- (void) addTabViewItem:(RMTabViewItem)viewItem {
	[self addSubview:viewItem];

	//[viewItem setBackgroundColor:menuColo];

	var subvArra = [menuView subviews];
	var coun = [subvArra count];
	var x0 = coun*100;
	/*
	x0 = 0;
	for ( var i=0; i<coun; i++ )
		x0 += [[subvArra[i] title] length]*7;
	*/

	var buttFram = CPRectMake(x0,0,100,30);
	var butt = [[CPButton alloc] initWithFrame:buttFram];
	[butt setTarget:self];
	[butt setAction:@selector(setMainViewForButton:)];
	[butt setTitle:[viewItem label]];
	[butt setBordered:NO];
	[butt setBezelStyle:4];
	[menuView addSubview:butt];
	
	[buttDict setObject:viewItem forKey:butt];
	
	[self setMainViewForButton:butt];
}



- (void) setDelegate:(id)deleNew {
	dele = deleNew;
}



- (void) setMainViewForButton:(id)butt {
	
	var view = [buttDict objectForKey:butt];
	[view removeFromSuperview];
	
	var fram = [self frame];
	fram.origin.x = 0;
	fram.origin.y = 30;
	fram.size.height -= 30;
	[view setFrame:fram];
	
	//fram.origin.x = 10;
	fram.origin.y = 0;
	//fram.size.width -= 20;
	//fram.size.height += 30;
	var arra = [view subviews];
	[arra[0] setFrame:fram];

	[self addSubview:view];

	[buttPrev setBackgroundColor:menuColo];
	[butt setBackgroundColor:menuSwitColo];
	buttPrev = butt;
}



@end



@implementation RMTabViewItem : CPView {

	CPString iden;
	CPString labe;

}



- (id) initWithIdentifier:(CPString)idenNew {
	[super init];
	iden = [idenNew copy];
	return self;
}



- (CPString) label {
	return labe;
}



- (void) setLabel:(CPString)labeNew {
	labe = [labeNew copy];
}



- (void) setView:(CPView)viewNew {
	[self addSubview:viewNew];
}



- (void) viewWillMoveToSuperview:(CPView)supeView {
}



@end

