/* image-shrink-restore.js
 * Shinks all Images to prevent horinzontal scrolling on the website ... :-)
*/ 
var ws = 0		// ws ... Window size, we use just width of browser window
function sai() {
	ws = window.innerWidth ? window.innerWidth : document.body && document.body.offsetWidth ? document.body.offsetWidth : screen.width;
	if (document.images.length) {
		var i = document.images;
		for (var x = 0; x < i.length; x++) {
			if (eval(i[x].width + i[x].width * 0.15) > ws) {
				if (typeof i[x].ow == 'undefined') {
					i[x].ow = i[x].width;
					i[x].oh = i[x].height;
				}
				i[x].width = i[x].ow / (i[x].ow / (ws / 2));
				if (i[x].height == i[x].oh) {
					i[x].height = i[x].height / (i[x].ow / (ws / 2));
				}
				if (i[x].parentNode.nodeName != 'A') {
					i[x].onclick = ri;
					i[x].title = i[x].src;
					i[x].className = 'resized';
				}
			}
		}
	}
};

/* Restore image (element), when size of browser window has changed (larger) ...
*/
function ri(e) {
	var o = window.event ? window.event.srcElement : e.target;
	o.width = o.ow;
	if (o.height != o.oh) {
		o.height = o.oh;
	}
	o.onclick = si;
};
/* Otherweise shrink image (element), when window width is toooooo small ... 
*/
function si(e) {
	var o = window.event ? window.event.srcElement : e.target;
	o.width = o.width / (o.width / (ws / 2));
	if (o.height == o.oh) {
		o.height = o.height / (o.ow / (ws / 2));
	}
	o.onclick = ri;
};
