(function() {
	
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	var zIndex = 500;
	var currentIndex = 0;
    var layerDefaultStyle = {
        width : "100%",
        height : "100%",
        borderStyle : "none",
        display : "none",
        position : IE6 ? 'absolute' : 'fixed',
        left : 0,
        overflow : 'hidden',
        filter : 'alpha(opacity=25)',
        '-moz-opacity' : .5,
        opacity : .5,
        backgroundColor : 'black'
    };
    
	var layers = [document.createElement ('DIV')/*@cc_on, document.createElement ('IFRAME')@*/];

	LSF.each (layers, function (layer, i) {
        var layerStyle = layer.style;
        for (var prop in layerDefaultStyle) {
            layerStyle[prop] = layerDefaultStyle[prop];
        }
        layer.className = 'lsf_layer_fog';
	    layer.id = 'lsf_layer_' + i;
	});
    
    var isInitialized = false;
    
    function init() {
    	if (!isInitialized) {
    		/*@cc_on 
    		document.body.insertBefore (layers[1], document.body.firstChild);
    		@*/
    		document.body.insertBefore (layers[0], document.body.firstChild);
    		isInitialized = true;
    	}
    }
    
	LSF.UI.LayerManager = {

		//return the zIndex 
		requestLayer : function() {
			init();
			var needsShow = currentIndex == 0;
			currentIndex++;
			zIndex += 3;
			LSF.each (layers, function (layer, i) {
				layer.style.zIndex = zIndex - 2 + i;
				if (needsShow) {
					layer.style.display = 'block';
				}
			});
			return zIndex;
		},
		
		disposeLayer : function() {
			init();
			zIndex -= 3;
			currentIndex --;
			LSF.each (layers, function (layer, i) {
				if (currentIndex == 0) {
					layer.style.display = 'none';
					layer.style.zIndex = 0;
				} else {
					layer.style.zIndex = zIndex - 2 + i;
				}
			});
			return zIndex;
		}
		
		
	}
	
})();
