$(function(){
	var $speed = 200; 
	
	$('._2MSystem select').each(function(){
		var $this = $(this);
		var $name = $this.attr('name');
		var $option = new Array();
		var $value = new Array();
		var $value_selected;
		
		var $selected = null;
		$style = $this.attr('style');
		
		var $i = 0;
		$this.children('option').each(function(){
			if($(this).attr('selected'))
				{
				$selected = $(this).text();
				$value_selected = $(this).attr('value');
				}
			$option[$i] = $(this).text();
			$value[$i] = $(this).attr('value');
			
			$i++;
		})
		if($selected == null)
			$selected = $option[0];
		$new = "<div class=\"select\" style=\""+$style+"\"><span>"+$selected+"</span><div class=\"select_rol\"></div><div class=\"option\">";
		for($i in $option)
			{
			$new += "<span class=\""+$value[$i]+"\">"+$option[$i]+"</span>";
			}
		if($value_selected != '')
			$new += "</div><input type=\"hidden\" value=\""+$value_selected+"\" name=\""+$name+"\"/></div>";
		else
			$new += "</div><input type=\"hidden\" value=\""+$selected+"\" name=\""+$name+"\"/></div>";
		$this.replaceWith($new);
		
	})
	
	$('._2MSystem  .select_rol').live('click',function(){
		var $this = $(this);
		var $option = $this.parent().children('.option');

		if($option.css('display') == "block")
			$option.hide($speed);
		else
			$option.show($speed);
	})	

	$('._2MSystem  .select .option span').live('click',function(){
		var $this = $(this);
		$this.parent().parent().children('span').empty().append($this.text());
		$this.parent().parent().children('input').val($this.attr('class'));
		$this.parent().parent().children('input').trigger('click');
		$this.parent().parent().children('.option').hide($speed);
		
		
	})

})
