var Globals = {
	
	CreateOverlay : function ( overlayId ) {
		if ( $( overlayId ) == null ) {
			
			div = new Element ( 'div', {
					'id' : overlayId
				}
			);
			
			$('doc_body').insert(div).down();
		}
		
		
		if(typeof window.innerHeight == 'undefined') {
			if ( $( "overlayframe" ) == null ) {
				iframe = new Element ( 'iframe', {
						'id' : "overlayframe"
					}
				);
			
				$('doc_body').insert(iframe).down();
			}
		}
		
		
	},

	ShowOverlay : function() {
		var overlayId = 'overlay';
		
		this.CreateOverlay( overlayId );
		
		$(overlayId).style.display = 'block';
		
	},
	
	HideOverlay : function() {
		var overlayId = 'overlay';
		if ( $( overlayId ) != null ) {
			$(overlayId).style.display = 'none';
		}
		
		if(typeof window.innerHeight == 'undefined') {
			document.documentElement.style.overflow = "visible";
			$("overlayframe").style.display = "none";
		}
	},
	
	CreateHiddenDiv : function () {
		id = "divhidden"
		if  ( $(id) == null ) {
			div = new Element ( 'div' );
			div.id =id;
			
			$('doc_body').insert(div).down();
		}
		
		return id;
	},
	
	CreateOverlayBox : function ( boxId ) {
		this.ShowOverlay();
		
		if  ( $(boxId) == null ) {
			div = new Element ( 'div' );
			div.className = "overlaybox";
			div.id = boxId+'-box';
			
			divBody = new Element ( 'div' );
			divBody.id = boxId;
			divBody.className = "body";
			
			div.insert( divBody ).down();
			
			/*drag = new Draggable( div ,{
				'handle': 'move',
				'starteffect': false,
				'endeffect': false
			});*/
			
			document.body.insert(div).down();
		}
		
		return div;
	},
	
	PosOverlayBox : function ( boxId ) {
		//$(boxId+'-box').style.left = (Element.getDimensions( document.body ).width/2 - Element.getDimensions( boxId+'-box' ).width/2)+'px';
		
		//$(boxId+'-box').style.top = (Element.getDimensions( document.body ).height/2 - Element.getDimensions( boxId+'-box' ).height/2-100)+'px';
		if ( $(boxId+'-box') ) {
			if(typeof window.innerHeight != 'undefined') {
				$(boxId+'-box').style.top = 
	                 Math.round(document.viewport.getScrollOffsets().top + 
	                 ((window.innerHeight - $(boxId+'-box').getHeight()))/2)+'px';
				$(boxId+'-box').style.left = 
	                 Math.round(document.viewport.getScrollOffsets().left + 
	                 ((window.innerWidth - $(boxId+'-box').getWidth()))/2)+'px';
				
				$("overlay").style.position = 'fixed';
	       } else {
	    	   $("overlay").style.top = document.viewport.getScrollOffsets().top;
	    	   $("overlayframe").style.display = "block";
	    	   $("overlayframe").style.top = document.viewport.getScrollOffsets().top;
	    	   $(boxId+'-box').style.top = 
	                 Math.round(document.viewport.getScrollOffsets().top + 
	                 ((window.document.documentElement.clientHeight - $(boxId+'-box').getHeight()))/2)+'px';
	            $(boxId+'-box').style.left = 
	                 Math.round(document.viewport.getScrollOffsets().left + 
	                 ((window.document.documentElement.clientWidth - $(boxId+'-box').getWidth()))/2)+'px';
	            
	            document.documentElement.style.overflow = "hidden";
		    	   
	       }
		}
	},
	
	HideOverlayBox : function ( boxId ) {
		
		this.HideOverlay();
		
		Event.stopObserving( document, 'scroll' );

		$(boxId+'-box').style.display = "none";
		
		if(typeof window.innerHeight == 'undefined') {
			document.documentElement.style.overflow = "auto";
			$("overlayframe").style.display = "none";
		}
	},
	
	ShowOverlayBox : function ( boxId ) {
		Event.observe(document, 'scroll', function() {
			Globals.PosOverlayBox( boxId );
		});

		
		$(boxId+'-box').style.display = "block";
	},
	
	MoveElement : function ( itemTop, itemDown, direction ) {
		if ( direction == "top" ) {
	 		height = (0 - $(itemTop).getHeight());
			if ( $(itemTop).positionedOffset().top == height ) {
				return Globals.MoveElement( itemTop, itemDown, 'down' );
			}else {
				$(itemTop).style.top = ($(itemTop).positionedOffset().top-1)+"px";
			}
			setTimeout( "Globals.MoveElement('"+itemTop+"','"+itemDown+"','"+direction+"')", 0 );
		}else {
			height = $(itemDown).getHeight();
		
			if ( $(itemDown).positionedOffset().top == 0 ) {
				return true;
			}else {
				$(itemDown).style.top = ($(itemDown).positionedOffset().top+1)+"px";
				
				
			}
			setTimeout( "Globals.MoveElement('"+itemTop+"','"+itemDown+"','"+direction+"')", 0 );
		}
	},
	
	OpenWindow : function ( href, width, height ) {
		NewWindow = window.open(href, "Zweitfenster", "width="+width+",height="+height+",scrollbars=yes");
		NewWindow.focus();
	}
}
