
var DesignWidgets_ToolbarItem = Class.create({
	id: '',
	pushButton: true,
	toggleButton: false,
	pushed: false,
	normalIcon:'',
	overIcon:'',
	pushedIcon:'',
	normalTextColor:'',
	overTextColor:'',
	pushedTextColor:'',

	onClickAction: function(toolbarItem) {},
	
	initialize: function(id,pushButton,toggleButton,pushed,normalIcon,normalText,overIcon,overText,pushedIcon,pushedText) {
		this.id = id;
		this.pushButton = pushButton;
		this.toggleButton = toggleButton;
		this.pushed = pushed;
		this.normalIcon = normalIcon;
		this.normalTextColor = normalText;
		this.overIcon = overIcon;
		this.overTextColor = overText;
		this.pushedIcon = pushedIcon;
		this.pushedText = pushedText;
	},
	
	click: function() {
		if (!this.pushButton) return;
		if (this.toggleButton) {
			this.pushed = !this.pushed;
		}
		this.onClickAction(this);
		this.out();
	},
	
	over: function() {
		if (!this.pushButton) return;
		$(this.id).style.color = this.overTextColor;

		if (this.toggleButton && this.pushed) return;
		$(this.id).style.backgroundImage = 'url(' + this.overIcon + ')';
	},
	
	out: function() {
		if (!this.pushButton) return;
		if (this.pushed) {
			$(this.id).style.backgroundImage = 'url(' + this.pushedIcon + ')';
			$(this.id).style.color = this.pushedTextColor;
		}
		else {
			$(this.id).style.backgroundImage = 'url(' + this.normalIcon + ')';
			$(this.id).style.color = this.normalTextColor;
		}
	},
	
	toggle: function(isPushed) {
		this.pushed = isPushed;
//		if (this.toggleButton) {
//			this.pushed = !this.pushed;
//		}
		this.out();
	}
});

var DesignWidgets_Toolbar = Class.create({
	items: {},

	addItem: function(item,action) {
		this.items[item.id] = item;
		item.onClickAction = action;
	},
	
	onItemClick: function(itemId) {
		var item = this.items[itemId];
		if (item) {
			item.click();
		}
	},
	
	onItemOver: function(itemId) {
		var item = this.items[itemId];
		if (item) {
			item.over();
		}
	},
	
	onItemOut: function(itemId) {
		var item = this.items[itemId];
		if (item) {
			item.out();
		}
	},
	
	onItemToggle: function(itemId,isToggled) {
		var item = this.items[itemId];
		if (item) {
			item.toggle(isToggled);
		}
	}
});

var DesignWidgets_Window = Class.create({
	close: function() {
		window.close();
	}
});

var DesignWidgets = Class.create({
	toolbar: new DesignWidgets_Toolbar(),
	mainWindow: new DesignWidgets_Window()
});

var designWidgets = new DesignWidgets();

