/*
 * BMUI.Page library
 * Collection of methods that provide functionality for or data about the current page
 * @author Dan Neame <dneame@britishmuseum.co.uk>
 */

// define namespace
if( typeof( BMUI ) == 'undefined' ) BMUI = {};
if( typeof( BMUI.Page ) == 'undefined' ) BMUI.Page = {};

var Page = function(){

	// local vars
	this.secure = ( document.location.protocol == "https:" );
	this.urlParts = document.location.toString().split( '/' );
	this.webroot_absolute = ( ( this.secure ) ? 'https://' : 'http://' ) + this.urlParts[ 2 ];
	// if webroot does not contain 'britishmuseum' then set it to nonsecure live
	if( this.webroot_absolute.indexOf( 'britishmuseum' ) < 0 ) this.webroot_absolute = 'http://www.britishmuseumshoponline.org';

	/*
	 * BMUI.Page.getScroll
	 * Method to return window scroll position in any browser (beware! old doctypes in IE7 may require IE6 method instead. Function is NOT coded to handle this.)
	 */
	this.getScroll = function(){
		var x = 0, y = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			// Netscape
			x = window.pageXOffset;
			y = window.pageYOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			// DOM
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			// IE6 standards compliant mode
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
		return [ x , y ];
	} // end getScroll
	
	this.clear_after = function( expression ){
		$( expression ).after( '<br style="display:block;clear:both;height:1px;margin:0;padding:0" />' );
	}

}
BMUI.Page = new Page();
