/**
 * Window.block/unblock
 *
 * @author Boz
 * @classDescription Extends the native window object with block and unblock functions.
 **/

var Window = { 
    block: function(msg, color, imgpath){
		var body = $E("body");
		var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		if(IE6){
			window.select = $ES("select",body);	
			for(var i=0; i<window.select.length; i++){
				window.select[i].style.visibility="hidden";
			}
		}
		
		/*
		 * Changed this so that modal can only be created once 
		 * This protects us when the modal is called more than once
		 *   -JL
		 */
		var curModal = $("modal");
		if(curModal == null){
			var modalMSG = new Element('div',{'id':'modalmsg'});
			/*
			 * winCooKoo
			 * gets width and height of window - this drove us nuts - hence the name
			 * -JL
			 */
			var winCooKoo = body.getCoordinates();
			winCooKoo.height = window.getScrollHeight();
			var modal = new Element('div', {
			'styles': {
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				'width': winCooKoo.width,
				'height': winCooKoo.height,
				'opacity': 0.8,
				'background': (color)? color : '#fff',
				'z-index': '1337',
				'text-align':'center'
			},
			'id':'modal'
			});
	
			if(typeof(msg) == 'string'){
				modalMSG.innerHTML = msg? msg : '';	
			}
			else{
				msg.injectInside(modalMSG);
			}		
			modal.setStyle('padding-top',winCooKoo.height/2.5 + "px");
			modal.injectInside(body);	
			modalMSG.injectInside(body);
		}
	},
	unblock: function(){
        if($("modal")){
            $("modal").remove();
        }

        if($("modalmsg")){
            $("modalmsg").remove();
        }
        
        if(window.select != null){
			for(var i=0; i<window.select.length; i++){
				window.select[i].style.visibility="visible";
			}		
		}
	}
};