
PGOnload = function() { PGReloaded.init(); if (PGPrimary != null) { PGPrimary.node.onclick(PGPrimary.node); } }

if (typeof PGOnload == 'function') {
	if ('undefined' != typeof jQuery) jQuery(document).ready(function(){PGOnload();});
	else if( typeof window.onload != 'function' ) window.onload = PGOnload;
	else {oldonld = window.onload;window.onload = function(){if(oldonld){oldonld();};PGOnload();}};
}

PGReloaded = {
	I: function(a) {
		return document.getElementById(a);
	},

	settings: function() {
		var t = this, s = PGSettings;
	},

	init: function() {
		var t = this, L, T, ext, i, m, setid, inset, shfile, shMenuPre, k, img;
		PGLinks = {}, PGSets = {}, PGPrimary = null;
		if ('object' != typeof PGSettings) PGSettings = {};

		for (i = 0; i < document.links.length; i++) {
			L = document.links[i];
			ext = (L.href.indexOf('?') == -1) ? L.href.slice(-4).toLowerCase() : L.href.substring(0, L.href.indexOf('?')).slice(-4).toLowerCase();
			if (ext != '.jpg' && ext != '.png' && ext != '.gif' && ext != 'jpeg') continue;
			if (L.className.toLowerCase().indexOf('projectgalleries') == -1) continue;

			if (L.getAttribute('rel').toLowerCase().indexOf('set_') != -1) {
				setid = L.getAttribute('rel').substring(4);
			}
			else {
				setid = 0, inset = -1;
			}

			if (setid) {
				if (!PGSets[setid]) PGSets[setid] = [];
				{
					inset = PGSets[setid].push(i);
				}
			}

			var alttext = "";
			for (j = 0; j < L.childNodes.length; j++) {
				if (L.childNodes[j].nodeType == L.ELEMENT_NODE) {
					alttext = L.childNodes[j].getAttribute("alt");
				}
			}

			var idx = L.href.lastIndexOf('/');
			shfile = L.href.slice(idx + 1);
			T = (L.title && L.title != shfile) ? L.title : '';

			PGLinks[i] = {
				link: L.href,
				thumb: L.getAttribute('fullthumb'),
				num: inset,
				set: setid,
				title: T,
				node: L,
				alttext: alttext,
				caption: L.getAttribute("title")
			};
			L.onclick = new Function('PGReloaded.make("' + i + '");return false;');

			if (PGPrimary == null) {
				PGPrimary = PGLinks[i];
			}
		}

		t.settings();
	},

	make: function(ln, fs) {
		var t = this, prev, next, prevlink = '', nextlink = '', previmg, nextimg, D, S, W, fsarg = -1, imgNum, NavBar;

		if (!t.Top) {
			if (typeof window.pageYOffset != 'undefined') t.Top = window.pageYOffset;
			else t.Top = (document.documentElement.scrollTop > 0) ? document.documentElement.scrollTop : document.body.scrollTop;
		}

		var a = document.getElementById('PGFullSizeImageHref');
		var img = document.getElementById('PGFullSizeImage');
		var cap = document.getElementById('PGFullSizeImageCaption');

		img.setAttribute('src', PGLinks[ln].thumb);
		img.setAttribute('alt', PGLinks[ln].alttext);
		a.setAttribute('href', PGLinks[ln].link);
		a.setAttribute('title', PGLinks[ln].caption);

		cap.innerHTML = PGLinks[ln].caption;

		//a.onclick = new Function('shutterReloaded.make("' + ln + '");return false;');
	}
};

