	Ext.namespace('Sourceflow.Wellpoint.AgentApp');

	Sourceflow.Wellpoint.AgentApp.createExtTabs = function() {
		var smTabs = Ext.query('div#smTabs');
		var items = [];
		var toRemove = [];
		var id = 'smTabs';
		var oldContainer;
		var isMultiSubmarket = true;
		var activeId;
		if (smTabs.length>0) {
			
			
			var lis = Ext.query('div#smTabs ul li');
			for (var j=0;j<lis.length;j++) {

				var id = lis[j].id;
				var as = Ext.query('a',lis[j]);
				var lbl = as[0].innerHTML;
				var divId = id.substring(3);
				var dvs = Ext.query('div#'+divId);
				dvs[0].style.display='block';
	
				var content = {};
				if (j==0) activeId = divId;
				content.contentEl = divId;
				content.title=lbl;
				content.rel = as[0].rel;
				items.push(content);
				
			}
			//smtabs remnant should go away
			var originaluls = Ext.query('div#smTabs ul');
			//for (var j=0;j<originaluls.length;j++) toRemove.push(originaluls[j]);
		}
		else {
			//only one submarket here
			isMultiSubmarket = false;
			smTabs = Ext.query('div#submarket');
			
			var content = {};
			id = 'submarket';
			var h2 = Ext.query("h2.section",smTabs[0]);
			
			//need to set visible
			Ext.query('div#tabContent')[0].style.display='block';
			activeId= 'tabContent';
			content.contentEl = 'tabContent';
			content.title=h2[0].innerHTML.trim();
			content.rel = '';
			items.push(content);
			
			toRemove.push(h2[0]);

		}
		Ext.select('.tabcontent').setVisible(true);
		//find max height
		var maxHeight=0;//tabs.getInnerHeight();//tabs.getBox().height;
		var dvs = Ext.query('.tabcontent');
		for (var j=0;j<dvs.length;j++) {
			var dv = dvs[j];
			var ds = dv.style.display;
			dv.style.display='block';
			var h =Ext.get(dv).getComputedHeight();//Ext.util.TextMetrics.measure(dvs[0],dv.innerHTML).height;//Utilities.trimPx(dv.style.height);

			dv.style.display=ds;
			
			if (h>maxHeight) maxHeight = h;
		}
		for (var j=0;j<dvs.length;j++) {
			var dv = dvs[j];
			
			dv.style.height = maxHeight+'px';
			if (Utilities.trimPx(dv.parentNode.style.height) < maxHeight) dv.parentNode.style.height= maxHeight+'px';
		}
		
		
		oldContainer = smTabs[0];
		oldContainer.className='';
		
		var dv = document.createElement('div');
		dv.id=Ext.id();
		dv.className='smContent';
		
		oldContainer.parentNode.appendChild(dv);
		var tabs = new Ext.TabPanel({
			plain:true,
		    renderTo: dv,
		    shadow:true,
	            autoHeight:true,
		    shadowOffset:6,
		    activeTab: 0,
		    width:502,
		    deferredRender: false, 
		    hasBeenLoaded:false,
		    items:items
		});

		tabs.on('beforerender',new function(){
			oldContainer.parentNode.removeChild(oldContainer);
			var extras = Ext.query('div#tabcontentcontainer');
			if (extras.length>0) extras[0].parentNode.removeChild(extras[0]);
		});
		tabs.on('afterrender',new function(){
			tabs.setPosition(0,0);
		
		});
				
		tabs.on('tabchange', function(x) {
			var index = tabs.items.findIndex('id',tabs.getActiveTab().id);
			for (var j=0;j<tabs.items.length;j++)
			{
				var photoId = tabs.items.get(j).rel;
				var imgs = Ext.query('#'+photoId);
				if (imgs.length>0) imgs[0].style.display = (j==index ? '' : 'none');
			}
			
		});

		for (var j=0;j<toRemove.length;j++)
		{
			toRemove[j].parentNode.removeChild(toRemove[j]);
		}
		
		
		
			//correct shadow for missing background on header panel
			var smContent = Ext.query('div.smContent');
			var shadow = Ext.query('.x-shadow',smContent[0]);
			if (Ext.isIE) {
				shadow = Ext.query('.x-ie-shadow',smContent[0]);
			}
			shadow = shadow[0];

			if (shadow) {
				var tp = Utilities.trimPx(shadow.style.top);
				var oldHeight = Utilities.trimPx(shadow.style.height);

				if (!shadow.style) shadow.style={};


				if (Ext.isIE===false) {
					shadow.style.height=(maxHeight+30)+'px';
					shadow.style.top=(tp+(oldHeight - maxHeight-20))+'px';
					var shadowinner = Ext.query('.xsc',shadow);
					shadowinner = shadowinner[0];
					if (!shadowinner.style) shadowinner.style={};
					shadowinner.style.height=(maxHeight+10)+'px';
				} else {
					var nh = (maxHeight+13);
					shadow.style.height=nh+'px';
					shadow.style.top=(tp+(oldHeight - nh))+'px';
				}
			}
	}

