jQuery.noConflict();
jQuery(document).ready(function(){
								
jQuery('#resform select').each(function(){
	var jqTransformHideSelect = function(oTarget){
		var ulVisible = jQuery('.jqTransformSelectWrapper ul.jqoptions');
		ulVisible.each(function(){
			var oSelect = jQuery(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);
			//do not hide if click on the label object associated to the select
			if( !(oTarget && oSelect.oLabel && oSelect.oLabel.get(0) == oTarget.get(0)) ){jQuery(this).hide();}
		});
	};
	
function jqTransformGetLabel(objfield){
		var selfForm = jQuery(objfield.get(0).form);
		var oLabel = objfield.next();
		if(!oLabel.is('label')) {
			oLabel = objfield.prev();
			if(oLabel.is('label')){
				var inputname = objfield.attr('id');
				if(inputname){
					oLabel = selfForm.find('label[for="'+inputname+'"]');
				} 
			}
		}
		if(oLabel.is('label')){return oLabel.css('cursor','pointer');}
		return false;
	};
			var $select = jQuery(this);

			var oLabel  =  jqTransformGetLabel($select);
			/* First thing we do is Wrap it */
			var $wrapper = $select
				.addClass('jqTransformHidden')
				.wrap('<div class="jqTransformSelectWrapper"></div>')
				.parent()
				.css({zIndex: 10})
			;
			
			/* Now add the html for the select */
			$wrapper.prepend('<div><span></span></div><ul class="jqoptions"></ul>');
			var $ul = jQuery('ul', $wrapper).css('width',$select.width()).hide();
			/* Now we add the options */
			jQuery('option', this).each(function(i){
				var oLi = jQuery('<li><a href="#" index="'+ i +'">'+ jQuery(this).html() +'</a></li>');
				$ul.append(oLi);
			});
			
			/* Add click handler to the a */
			$ul.find('a').click(function(){
					jQuery('a.selected', $wrapper).removeClass('selected');
					jQuery(this).addClass('selected');	
					/* Fire the onchange event */
					if ($select[0].selectedIndex != jQuery(this).attr('index') && $select[0].onchange) { $select[0].selectedIndex = jQuery(this).attr('index'); $select[0].onchange(); }
					$select[0].selectedIndex = jQuery(this).attr('index');
					jQuery('span:eq(0)', $wrapper).html(jQuery(this).html());
					$ul.hide();
					return false;
			});
			/* Set the default */
			jQuery('a:eq('+ this.selectedIndex +')', $ul).click();
			jQuery('span:first', $wrapper).click(function(){jQuery("a.jqTransformSelectOpen",$wrapper).trigger('click');});
			oLabel && oLabel.click(function(){jQuery("a.jqTransformSelectOpen",$wrapper).trigger('click');});
			this.oLabel = oLabel;
			
			/* Apply the click handler to the Open */
			var oLinkOpen = jQuery($wrapper)
				.click(function(){
					//Check if box is already open to still allow toggle, but close all other selects
					if( $ul.css('display') == 'none' ) {jqTransformHideSelect();} 
					if($select.attr('disabled')){return false;}

					$ul.slideToggle('fast', function(){					
						var offSet = (jQuery('a.selected', $ul).offset().top - $ul.offset().top);
						$ul.animate({scrollTop: offSet});
					});
					return false;
				})
			;

			// Set the new width
			var iSelectWidth = $select.outerWidth();
			var oSpan = jQuery('span:first',$wrapper);
			var newWidth = (36);
			$wrapper.css('width',newWidth);
			$ul.css('width',newWidth-2);
			oSpan.css({width:"20px"});
		
			// Calculate the height if necessary, less elements that the default height
			//show the ul to calculate the block, if ul is not displayed li height value is 0
			$ul.css({display:'block'});
			var iSelectHeight = (jQuery('li',$ul).length)*(jQuery('li:first',$ul).height());//+1 else bug ff
			(iSelectHeight < $ul.height()) && $ul.css({height:iSelectHeight,'overflow':'hidden'});//hidden else bug with ff
			$ul.css({display:'none'});								
								
});
});
	
