var BoxyClass = Class.create( {

	initialize: function() {
		
		var overlay = Builder.node( 'div', {
		  id: 'overlay',
		  style: 'display: none'
		});
		
		var boxy = Builder.node( 'div', {
		  id: 'boxy',
		  style: 'display: none'
		});	
		
		var boxyContent = Builder.node( 'div', {
		  id: 'boxyContent'
		});		
			
		var boxyClose = Builder.node( 'a', {
		  id: 'boxyClose',
		  href: '#'
		});		
		boxy.appendChild( boxyClose );		
		boxy.appendChild( boxyContent );
				
		document.body.appendChild( overlay );
		document.body.appendChild( boxy );
		$( 'boxyClose' ).show();
		Event.observe( boxyClose, 'click', function( event ) {
			event.stop();
			Boxy.closeBoxy();
		});		
			
	},
	
	populateBoxy: function( content, width ) {
		
		$$( "div.sub-nav").each( function( element ) {
			element.style.display = "none";
		});
		width = width ? width : "300";
		position = window.pageYOffset;	
		$( 'boxy' ).setStyle( { width: width + 'px', marginLeft: ( ( width / 2 ) + 10 ) - ( ( ( width / 2 ) + 10 ) * 2  ) + 'px', marginTop: position + 'px' } );
		
		if( content ) {
			$( 'boxyContent' ).innerHTML = content;
		}
		
		Effect.Appear( 'overlay', {
			duration: 0.1,
			from: 0,
			to: 0.80
		} );
		Effect.Appear( 'boxy', {
			duration: 0.1,
			from: 0,
			to: 1,
		} );
		Effect.SlideUp( 'boxyClose', {
			duration: 0.1,
			delay: 0.2
		});

	},
	
	closeBoxy: function() {
		
		Effect.Fade( 'overlay', {
			duration: 0.1
		} );
		Effect.Fade( 'boxy', {
			duration: 0.1,
			afterFinish: function() {
				$( 'boxyContent' ).innerHTML = "";
			}
		} );
		
	}
	
	
});

// getPageScroll() by quirksmode.com
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
	  yScroll = self.pageYOffset;
	  xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
	  yScroll = document.documentElement.scrollTop;
	  xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
	  yScroll = document.body.scrollTop;
	  xScroll = document.body.scrollLeft;
	}
	return new Array(xScroll,yScroll)
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
	var windowHeight
	if (self.innerHeight) {	// all except Explorer
	  windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	  windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
	  windowHeight = document.body.clientHeight;
	}
	return windowHeight
}
