var iaz_preserved_elements = [];
var iaz_preserved_zindexes = [];

function ie_apply_zindex(element_id, zindex, context_id){
	// default values
	if (undefined == zindex) {
		zindex = 1;
	}
	var context = (undefined == context_id ? $(context_id) : $(document.body));
	var element = $('#'+element_id);
	
	// undo past ie_apply_zindex()
	for (i = iaz_preserved_elements.length - 1; i >= 0; i--) {
		iaz_preserved_elements[i].css({
			'z-index': iaz_preserved_zindexes[i]
		});
	}
	iaz_preserved_elements = [];
	iaz_preserved_zindexes = [];

	// find relative-positioned ancestors of element within context
	element.parents().each(function(){
		ancestor = $(this);
		if ('relative' == ancestor.css('position')) {
			// preserve ancestor's current z-index
			iaz_preserved_elements.push(ancestor);
			iaz_preserved_zindexes.push(ancestor.css('z-index'));
			
			// apply z-index to ancestor
			ancestor.css({
				'z-index': zindex
			});
		}
		if (ancestor == context) {
			throw $break;
		}
	});
}