inpage = ({
debug: function (s) {
	if (!window.debug) return;
	inpage.debug = confirm(s) ? inpage.debug : function () {};
},
url: ({
split: function (s) {
	var prot = /^([a-z0-9A-Z]+):/.exec(s);
	if (prot) {
		prot = prot[1].toLowerCase();
		if (prot != 'http' && prot != 'https') {return s;}
	} else {
		if (s.charAt(0) != '/') {
			s = location.pathname.replace(/[^\/]*(\?.*)?(#.*)?$/, '')+s;
		}
		s = location.protocol+'//'+location.host+s;
	}
	var a = /^(https?:)\/\/([^\/]*?)(:\d+)?(\/.*?|$)(\?.*?)?(#.*)?$/.exec(s);
	for (var i = 0; i <= 6; i++) {
		if (!a[i] || ((typeof a[i]) == 'undefined')) a[i] = '';
	}
	var o = ({});
	o.protocol = a[1]; // location.protocol
	o.hostname = a[2]; // location.hostname
	o.host = o.hostname+a[3]; // location.host
	o.path = a[4]; // location.pathname
	o.qs = a[5]; // location.search
	o.hash = a[6]; // location.hash
	return o;
},
islocal: function (url) {
	if (typeof url == 'string') url = inpage.url.split(url);
	if (typeof url == 'string') return false;
	if (url.protocol != location.protocol) return false;
	if (url.host != location.host) return false;
	return true;
},
isbinary: function (url) {
	if (typeof url == 'string') url = inpage.url.split(url);
	if (typeof url == 'string') return false;
	if (url.path.match(/\.(ai|bmp|dwt|exe|gif|i(mg|so)|jp(eg|g)|m(id|p3)|p(df|ng|sd)|r(ar|ss)|t(ar|xt)|zip)$/)) return true;
	return false;
},
getpath: function (url) {
	if (typeof url == 'string') url = inpage.url.split(url);
	if (typeof url == 'string') {
		if (!url.length) return '/';
		return url;
	}
	return url.path;
},
toString: function (url) {
	if (typeof url == 'string') return url;
	return url.protocol+'//'+url.host+url.path+url.qs+url.hash;
},
localPart: function (url) {
	if (typeof url == 'string') {
		url = inpage.url.split(url);
	}
	if (typeof url == 'string') {
		url = url.replace(/^[\w\d]+:(\/\/[^\/]*)?/, '');
		return url;
	}
	return url.path+url.qs+url.hash;
}
}), // end inpage.url
init: function (ids) {
	if (location.hash && /^#?[^;=&]+=[^;=&]*([&;]|$)/.exec(location.hash)) {
		return;
	}
	var containers = [];
	if (!ids) containers.push(document.body);
	else containers = tmg.cleanarray(ids);
	inpage._initcontainers = [];
	for (var x = 0; x < containers.length; x++) {
		var container = containers[x];
		if (typeof container == 'string') container = document.getElementById(container);
		if (!container) continue;
		inpage._initcontainers.push(container);
	}
	inpage.reinit();
},
rsaukinit: function () {
	return inpage.init(['content', 'top']);
},
reinit: function () {
	if (location.hash && /^#?[^;=&]+=[^;=&]*([&;]|$)/.exec(location.hash)) {
		return;
	}
	for (var x = 0; x < inpage._initcontainers.length; x++) {
		var container = inpage._initcontainers[x];
		if (!container) continue;
		var links = tmg.getChildTags(container, 'a');
		for (var i = 0; i < links.length; i++) {
			var link = links[i];
			inpage.registerevents_link(link);
		}
	}
	inpage.starthashpolling();
},
registerevents_link: function (link) {
	if (!link.inpageregistered) {
		link.inpageregistered = true;
		tmg.addEventSimple(link, 'click', inpage.linkclick);
	}
},
linkclick: function (e) {
	if (!e) e = window.event;
	var link = this;
	if (!link || !link.nodeType) link = tmg.eventTarget(e); // in IE6, `this' is some wicked object
	if (!link || !link.nodeType == 1 || !link.href || link.tagName.toLowerCase() != 'a') link = tmg.getAncestor(link, 'a');
	if (!link || !link.href || link.href.match(/\.(jpe?g|gif|png)(\?.*)?(#.*?)?$/i)) return true;

	return inpage.linkclick_ex(link, e);
	// returning a boolean might not make sense to you, developer
	// but trust me
	// if you know ie7, this will make sense
},
linkclick_ex: function (link, e) {
	if (tmg.metaKey(e)) return true;
	if (inpage.click(link.href)) {
		tmg.catchEvent(e);
		return false;
	}
	return true;
},
follow: function (href, fromhistory) {
	if (!inpage.click(href, fromhistory ? true : false)) location.href = href;
},
click: function (href, fromhistory) {
	if (document.getElementById('ga_control')) {return false;}
	var url = inpage.url;
	href = url.split(href);
	if (!url.islocal(href) || url.isbinary(href))
		return false;

	// not sure how to handle this
	if (href.hash)
		return false;

	// if the page following stems from a change in location.hash, don't set location.hash, as that would reset browser history
	if (!fromhistory) {
		var set = href.path+href.qs;
		if (inpage.base && set.substring(0, inpage.base.length) == inpage.base)
			set = set.substring(inpage.base.length, set.length);
		location.hash = '#'+set;
	}

	href.hash = '';
	var geturl = url.toString(href);
	inpage._curpage = geturl;

	if (href.qs) geturl += '&';
	else geturl += '?';
	geturl += 'localload';

	tmg._loaded = false;
	tmg.xhrgetj(geturl, inpage.cb);

	return true;
},
cb: function (xhr) {
	if (xhr.responseText && xhr.responseText.match(/^ *</))
		return inpage.errorhandle();

	var data = tmg.xhrjson(xhr);
	if (!data)
		return inpage.errorhandle();

	var datas = ['menu', 'content'];
	var handled = 0;
	for (var i = 0; i < datas.length; i++) {
		var datastring = datas[i];
		if (data[datastring]) {
			var container = document.getElementById(datastring);
			if (!container) {
				container = document.createElement('div');
				container.id = datastring;
				container = document.body.appendChild(container);
			}
			if (!handled)
				window.scrollTo(0,0);
			container.innerHTML = data[datastring];
			handled++;
		}
	}

	if (data.scripts) {
		for (var i = 0; i < data.scripts.length; i++) {
			var scr = data.scripts[i];
			handled++;
			if (scr[0] == 'style') tmg.loadStyle(scr[1]);
			else if (scr[0] == 'script') tmg.loadScript(scr[1]);
			else handled--;
		}
	}

	if (data.logindata) {
		var changed = false;
		for (var i in data.logindata) {
			if (!window[i] || window[i] != data.logindata[i]) changed = true;
			window[i] = data.logindata[i];
		}
		if (changed) {
			if (data.logindata.loggedin) onloggedin();
			else loggedout();
		}
	}

	if (data.title) {
		tmg.setTitle(data.title);
	}

	if (data.gallery) {
		inpage.setGallery(data.gallery);
		handled++;
	}

	if (window.pageTracker) {
		if (data.utmvar) {
			window.pageTracker._setVar(data.utmvar);
			handled++;
		}

		if (data.customurl) {
			window.pageTracker._trackPageview(data.customurl);
			handled++;
		} else {
			window.pageTracker._trackPageview(inpage.url.localPart(inpage._curpage));
		}
	}

	// if the json data had members and none have been handled, this is an error condition
	if (data.length && !handled)
		inpage.errorhandle();

	// rav-auktion: register menu events
	if (data['menu'] && typeof menuregister == 'function')
		menuregister();

	if (inpage.fireevent)
		inpage.fireevent('load', {});

	inpage.reinit();
	tmg._tmgloaded(); // call new onload handlers
},
getGalleryElement: function () {
	if (inpage.galleryElement)
		return inpage.galleryElement;
	var o = document.getElementById('gallery');
	if (o && o.tagName && o.tagName.toLowerCase() == 'link')
		return inpage.galleryElement = o;
	var head = document.head;
	if (!head) {
		var heads = tmg.getElementsByTagName(document.documentElement, 'head');
		if (heads.length) {
			head = heads[0];
		} else {
			head = document.body;
		}
	}
	o = document.createElement('link');
	if (!document.getElementById('gallery'))
		o.id = 'gallery';
	o.type = 'application/rss+xml';
	o.rel = 'alternate';
	o.title = '';
	o = head.appendChild(o);
	return inpage.galleryElement = o;
},
setGallery: function (url) {
	var gall = inpage.getGalleryElement();
	gall.href = url;
	if (gall.href)
		(new Image).src = gall.href;
},
errorhandle: function () {
	location.replace(inpage.getcurrentpage());
},
getcurrentpage: function () { // _curpage property getter
	if (!inpage._curpage) inpage._curpage = location.href;
	return inpage._curpage;
},
currentpageis: function (s) {
	var curpage = inpage.url.toString(inpage.url.split(inpage.getcurrentpage()));
	s = inpage.url.toString(inpage.url.split(s));
	return curpage === s;
},
hashpoll: function () { // execute this function when life no longer has meaning for you
	var cur, hash, hash2, cururl, hashurl, hash2url, curpath, hashpath, hash2path, newurl;
	cur = inpage.getcurrentpage();
	hash = location.hash;
	hash2 = hash2url = hash2path = '';
	if (hash.substring(0,1) == '#')
		hash = hash.substring(1,hash.length);
	if (hash.charAt(0) !== '/') {
		if (!inpage.base)
			return;
		else if (hash.length)
			hash = inpage.base+hash;
		else {
			hash = location.pathname+location.search;
			hash2 = inpage.base;
		}
	}
	if (!hash2) {hash2 = hash;}
	cururl = inpage.url.split(cur);
	hashurl = inpage.url.split(hash);
	hash2url = inpage.url.split(hash2);
	curpath = inpage.url.getpath(cururl);
	hashpath = inpage.url.getpath(hashurl);
	hash2path = inpage.url.getpath(hash2url);
	inpage.debug('cur: '+cur+'\nhash: '+hash+'\nhash2: '+hash2+'\ncururl: '+cururl+' ('+inpage.url.toString(cururl)+')\nhashurl: '+hashurl+' ('+inpage.url.toString(hashurl)+')\ncurpath: '+curpath+'\nhashpath: '+hashpath);
	if (curpath != hashpath && curpath != hash2path) {
		// the hash differs from the url
		if (window.console && window.console.log) {
			window.console.log(curpath,hashpath,hash2path);
		}
		newurl = inpage.url.toString((curpath == hashpath) ? hash2url : hashurl);
		inpage.debug('Switching to '+newurl);
		inpage.follow(newurl, true);
		inpage.stophashpolling();
	}
},
starthashpolling: function () {
	inpage.stophashpolling();
	inpage._hashpollinterval = setInterval(inpage.hashpoll, 750);
},
stophashpolling: function () {
	if (inpage._hashpollinterval) {
		clearInterval(inpage._hashpollinterval);
		delete inpage._hashpollinterval;
	}
},
events: false
}); // end inpage
if (typeof ev == 'object') {
	ev.register(inpage);
	inpage.events = true;
}
// The following statement should go in the html in every page
if (window.inpagebase) {
	inpage.base = window.inpagebase;
	window.inpagebase = null;
}
if (location.hash && location.hash.substring(0,2) == "#/")
	location.replace(location.hash.substring(1,location.hash.length));
else if (location.hash && inpage.base && !(/^#?[^;=&]+=[^;=&]*([&;]|$)/.exec(location.hash)))
	location.replace(inpage.base+location.hash.substring(1,location.hash.length));

