/**
 * @author michal
 */
function FrameTab(me){

	var added = false;
	
	var el = new Ext.Button({
		text: textTrim(me.title, 20),
		iconCls: me.icon ? '' : 'frame_tab',
		icon: me.icon,
		handler: me.onClick
	});
	
	this.setIcon = function(icon){
		if (added) {
			var header = Ext.get(Ext.get(el.el).query('.x-btn-text'));
			if (icon) {
				header.setStyle('background-image', 'url(' + icon + ')');
				header.removeClass('frame_tab');
				header.addClass('favicon');
			}
			else {
				header.setStyle('background-image');
				header.removeClass('favicon');
				header.addClass('frame_tab');
			}
		}
		else {
			el.iconCls = icon ? '' : 'frame_tab';
			el.icon = icon;
		}
	}
	
	this.show = function(){
		if (added == false) {
			me.renderTo.add(el);
			me.renderTo.doLayout();
			
			added = true;
		}
		else {
			el.show();
		}
	}
	
	this.hide = function(){
		el.hide();
	}
	
	this.press = function(){
		el.toggle(true);
	}
	
	this.unpress = function(){
		el.toggle(false);
	}
	
	this.setText = function(title){
		el.setText(textTrim(title, 20));
		me.renderTo.doLayout();
	}
	
	this.destroy = function(){
		me.renderTo.remove(el);
		me.renderTo.doLayout();
	}
	
	function textTrim(text, len){
		// odstranit http:// a pod
		text = text.replace(/^.*\/{2}/, '');
		// odstranit www.
		text = text.replace(/^www\./, '');
		// odstranit parametry za otaznikem
		text = text.replace(/\?.*$/, '');
		// odstranit koncove lomitko
		text = text.replace(/\/*$/, '');
		
		// "w" je prilis siroke, proto je potreba zkratit retezec
		var pos = text.search(/www/);
		if (pos > -1) {
			len -= 2;
		}
		
		if (len > 0 && text.length > len) {
			// zkratit
			text = text.substring(len - 1, 0);
			// odstranit pripadnou tecku na konci
			text = text.replace(/\.$/, '');
			text += '…';
		}
		
		return text;
	}
}


