
createUISelects = function () {

// TODO Lösung für Problem beim einbinden unter SelectNode finden
//	if(navigator.userAgent.indexOf("MSIE 8") > -1) return;
	$('select.jsui').each(function() {
		
		var select = this;
		
		if ( $('#contentBox').length ) {
			$('#contentBox div').each(function() {
				var index = $('#contentBox div').index(this);
				$(this).css('zindex', 100 - index);
			});
		}
		
		var selectID = $('select.jsui').index(this);
		
		if ( $('#jsuiSelectFor'+selectID) ) {
			$('#jsuiSelectFor'+selectID).remove();
		}
		var $divSelect = $('<span></span>').addClass('jsuiSelect').attr('id', 'jsuiSelectFor'+selectID);
		var $divView = $('<span></span>').addClass('view');
		var $divRolloutBtn = $('<span></span>').addClass('rolloutBtn');
		var $divRolloutContainer = $('<span></span>').addClass('rolloutContainer');
		var $divRollout = $('<span></span>').addClass('rollout');
		
		var z = 10000 - selectID*100;
		$divSelect.css('zindex', z);
		$divView.css('zindex', z + 1);
		$divRolloutBtn.css('zindex', z + 5);
		$divRolloutContainer.css('zindex', z + 1);
		$divRollout.css('zindex', z + 2);
		
		$divSelect.append($divRolloutBtn);
		$divSelect.append($divView);
		$divRolloutContainer.append($divRollout);
		$divSelect.append($divRolloutContainer);
		
		$(select).children('option').each(function() {
			var index = $(select).children('option').index(this);
						
			var $span = $('<span>' + $(this).html() + '</span>');
			//span.update(el.innerHTML);
			var $link = $('<a></a>').attr('href', 'javascript:;');
			$link.html($span);
				
			if ( this.disabled == false ) {
				$link.click(function() {
					$divView.html($(this).html());
					$divRolloutBtn.trigger('click');
					select.selectedIndex = index;
					$(select).trigger('change');
				});
			} else {
				$link.addClass('jsuiSelectDisabled');
			}
				
			if ($(this).attr('selected')) $divView.html($(this).html());
			
			if (!$divSelect.cntOptions) $divSelect.cntOptions = 0;
			
			if ( this.disabled == false ) {
				$divRollout.append($link);
				$divSelect.cntOptions++;
			}
			
		});
		
		$divRolloutContainer.hide();
		$divSelect.rolledOut = false;
		
		var visibleChilds = Math.min($divSelect.cntOptions, 5);
		$divRolloutContainer.height(($divSelect.cntOptions * 20) + 6);
		$divRollout.height($divSelect.cntOptions * 20);
		
		$divRolloutBtn.onmouseover = function() {
			$divSelect.addClass('jsuiSelectOn');
		}
		$divRolloutBtn.onmouseout = function() {
			$divSelect.removeClass('jsuiSelectOn');
		}
		$divRolloutBtn.click(function() {
			if ($divSelect.rolledOut == false) {
				$divSelect.rolledOut = true;
				$divRolloutContainer.show();
			} else {
				$divSelect.rolledOut = false;
				$divRolloutContainer.hide();
			}
		});
		$(select).hide();
		$(select).before($divSelect);
	});
};

(function($) { $(function() {
	createUISelects();
}); })(jQuery)

