YAHOO.namespace( 'YAHOO.Hack' ).FixIESelectWidth = new function()
{	
	
	var pageSection;
	var oSelf = this; 
	var YUE = YAHOO.util.Event;
	var YUD = YAHOO.util.Dom;
	var oTimer = {};
	var oAnim = {};
	var nTimerId =  0 ;
	var dLastFocalItem;
	var cnt = 0;
	var ie7 = !!(document.uniqueID  &&   typeof(XMLHttpRequest)!='undefined' )
	
	function multiClick(mclick) 
	{
	mclick.style.zIndex = '20';
	}
	
	function init(el)
	{
		
		el = el || this;
		var multi = el.parentNode.getElementsByTagName("a")[0];
		if (multi != null)
		{
			var leftchange = multi.offsetLeft;
			multi.style.position = 'relative';
			multi.runtimeStyle.left = leftchange + 'px';
			multi.runtimeStyle.width = '100px';
			multi.runtimeStyle.top = '-15px';
			multi.style.display = 'inline-block';
			multi.style.zIndex = '-1';
		}
		
		
		if( el.tagName.toLowerCase() != 'select')
		{
			throw Error('element [' + el.id + '] is not <select>');
			return;
		};	
		

		
		var oRs = el.runtimeStyle;
		var oPRs = el.parentNode.runtimeStyle;
		
		
		oPRs.fonSize = 0;
		
		var sDisplay = el.parentNode.currentStyle.display.toLowerCase() ;
		if(  sDisplay=='block' ||  sDisplay=='inline' ||  sDisplay=='inline-block' )
		{
			
			var position = 'absolute';
			oPRs.display = 'inline-block';
			oPRs.width = 'auto';
			
			oPRs.height = el.offsetHeight + 'px';
			
			/*oPRs.position = 'relative';*/
			
			if(pageSection!="JOBSEARCH"||pageSection!="ALERTPERSON") 
			{
				oRs.height = el.offsetHeight + 'px';
				oRs.width = el.offsetWidth +'px';
				position = 'relative';
			}
			oPRs.margin = '0px 0px 10px 0px';
			if(cnt == 0)
			{
				oPRs.margin = '5px 0px 10px 0px';
			}
			cnt++;
		};
		
		
		
		
		
		el._timerId = ( nTimerId+=1 );

		el.selectedIndex = Math.max( 0 , el.selectedIndex );
		
		oTimer[ '_' + el._timerId ] = setTimeout('void(0)',0);
		oAnim [ 'A' + el._timerId ] = setTimeout('void(0)',0);
		
		YUE.on( el, 'mouseover' , onFocus);
		YUE.on( el, 'focus' , onFocus);
		YUE.on( document, 'click' ,onClick , el, true);
		YUE.on( el, 'change' ,onClick , el, true);
		YUE.on(  el, 'blur' ,collapseSelect , el, true);
	}


	function collapseSelect(e)
	{
		status++;
		this.runtimeStyle.width = '';
	}

	function onFocus(e )
	{
	
		var el = this;	
		if(dLastFocalItem && dLastFocalItem !=el)
		{
			 onClick.call( dLastFocalItem , e );
		};

		var sTimerId ='_' +  el._timerId ;
		var sAniId = 'A' + el._timerId ;
		clearTimeout( oTimer[ sTimerId ] );

		

		var onTween = function()
		{
			clearTimeout( oAnim [  sAniId  ] );
			if( Math.abs( nEndWidth - nStartWidth ) > 3 )
			{
				nStartWidth += (nEndWidth - nStartWidth ) /3;
				el.runtimeStyle.width = nStartWidth + 'px';
				oAnim [  sAniId  ] = setTimeout( onTween ,0 );
			}
			else if ( Math.abs( nEndWidth - nStartWidth ) == 0){
			el.runtimeStyle.width = nEndWidth + 'px';
			}
			else
			{
				el.runtimeStyle.width = 'auto';
				el.selectedIndex = Math.max( 0 , el.selectedIndex );
			}
		}

		var nStartWidth =  el.offsetWidth ;
		el.runtimeStyle.width = 'auto';
		if( (el.offsetWidth-nStartWidth) < 0 ){
			var	nEndWidth = nStartWidth;
		}
		else var nEndWidth  = el.offsetWidth;
		

		clearTimeout( oAnim [  sAniId  ] );
		onTween();

		el.focus();		
		dLastFocalItem = el;
	}

	function onClick(e , el )
	{
		el = ( e.srcElement || e.target );
		
		
		
		if( el == this && e.type!='focus' )
		{
			status++;
			YUE.stopEvent(e);
			return false;
		};
		
		
		el = this;
		
		clearTimeout( oAnim [ 'A' + el._timerId ] );
	
		
		var sTimerId ='_' +  el._timerId ;
		var doItLater = function()
		{
			el.runtimeStyle.width = '';			
		};
		if( e.type=='focus')
		{ doItLater();}
		else{
			oTimer[ sTimerId ] = setTimeout(doItLater,100);
		}
	}

	

	function constructor(sId, section)
	{
		pageSection = section;
		sId = [ sId , ''].join('');
		//Only fix for IE55 ~ IE7
		
		if(document.uniqueID && window.createPopup )
		{			
			YUE.onAvailable(sId ,init );
			return true;

		}else{return false};
	};

	return  constructor;
}
