/*
Based on code created by Christian Fecteau (http://portfolio.christianfecteau.com/)
http://creativecommons.org/licenses/by-nc-sa/2.0/
	
L4Y - Added support for height resizing.
*/
l4yimages_max_width = 600;
l4yimages_max_height = 450;
function l4ygo()
{
	var l4yimg_array = document.getElementsByTagName("IMG");
	for (var i = 0; i < l4yimg_array.length; i++){
		var l4yimg = l4yimg_array[i];
		if (String(l4yimg.getAttribute('doresize')) == '1'){
			if (l4ywait){
				l4yimages_thumnailclick = l4yimg.height;
				if(l4yimg.width && !isNaN(l4yimg.width)){
					if (l4yimg.width > Number(l4yimages_max_width) || l4yimg.height > Number(l4yimages_max_height)){
						l4yimg.setAttribute('doresize','0');
						l4yimg.onload = null;
						l4yimg.setAttribute('width',String(l4yimages_max_width));
						l4ymake_pop(l4yimg);
					}
				}
				if (l4yimg.height && !isNaN(l4yimg.height)){
					if (l4yimg.height > Number(l4yimages_max_height)){
						l4yimg.setAttribute('doresize','0');
						l4yimg.onload = null;
						l4yimg.setAttribute('height',String(l4yimages_max_height));
						l4ymake_pop(l4yimg);
					}
				}
			} else if (!l4ywait){
				l4yimg.setAttribute('doresize','0');
				var l4yclone = l4yimg.cloneNode(false);
				l4yimg.onload = null;
				l4yimg.removeAttribute('onload');
				var l4yparent = l4yimg.parentNode;
				var l4yind = l4ycount++;
				l4yclone.setAttribute('doresize',String(l4yind));
				l4ypreload[l4yind] = new Image();
				l4ypreload[l4yind].src = l4yimg.src;
				if (window.showModelessDialog){
					l4yclone.style.margin = '2px';
				}
				l4yclone.style.width = '28px';
				l4yparent.replaceChild(l4yclone,l4yimg);
			}
		}
	}
	if (!l4yover && document.getElementById('doresize')){
		l4yover = true;
		l4ygo();
	}else if (!l4yover){
		window.setTimeout('l4ygo()',2000);
	}
}
function l4yimg_loaded(l4yobj){
	if (!document.getElementsByTagName || !document.createElement) {
		return;
	}
	var l4yatt = String(l4yobj.getAttribute('doresize'));
	var l4yreal_width = false;
	var l4yreal_height = false;
	if ((l4yatt != '1') && (l4yatt != '0')){
		var l4yindex = Number(l4yatt);
		if (l4ypreload[l4yindex].width){
			l4yreal_width = l4ypreload[l4yindex].width;
		}
	}else{
		l4yobj.setAttribute('doresize','0');
		if (l4yobj.width){
			l4yreal_width = l4yobj.width;
		}
	}
	if ((l4yatt != '1') && (l4yatt != '0')){
		var l4yindex = Number(l4yatt);
		if (l4ypreload[l4yindex].height){
			l4yreal_height = l4ypreload[l4yindex].height;
		}
	}else{
		l4yobj.setAttribute('doresize','0');
		if (l4yobj.height){
			l4yreal_height = l4yobj.height;
		}
	}
	if (!l4yreal_width || isNaN(l4yreal_width) || (l4yreal_width <= 0) || !l4yreal_height || isNaN(l4yreal_height) || (l4yreal_height <= 0)){
		var l4yrand1 = String(l4ycount++);
		eval("l4yretry" + l4yrand1 + " = l4yobj;");
		eval("window.setTimeout('l4yimg_loaded(l4yretry" + l4yrand1 + ")',2000);");
		return;
	}
	if (l4yreal_height > Number(l4yimages_max_height)){
		if (window.showModelessDialog){
			l4yobj.style.margin = '2px';
		}
		l4ymake_pop(l4yobj);
	}
	if (l4yreal_width > Number(l4yimages_max_width)){
		if (window.showModelessDialog){
			l4yobj.style.margin = '2px';
		}
		l4ymake_pop(l4yobj);
	}else if (!l4ywait){
		l4yobj.style.width = String(l4yreal_width) + 'px';
		l4yobj.style.border = '0';
		if (window.showModelessDialog){
			l4yobj.style.margin = '0px';
		}
	}
	if (window.ActiveXObject){
		window.clearTimeout(l4ytimer1);
		l4ytimer1 = window.setTimeout('l4yrefresh_tables()',10000);
	}
}
function l4yrefresh_tables(){
	var l4ytables = document.getElementsByTagName("TABLE");
	for (var j = 0; j < l4ytables.length; j++){
		l4ytables[j].refresh();
	}
}
function l4ymake_pop(l4yref){
	l4yref.style.width = String(l4yimages_max_width) + 'px';
	l4yref.style.height = String(l4yimages_max_height) + 'px';
	if (!window.opera){
		l4yref.onclick = function(){
			if (!l4ypop.closed){
				l4ypop.close();
			}
			l4ypop = window.open('about:blank','showthumb',l4ypop_features);
			l4ypop.resizeTo(window.screen.availWidth,window.screen.availHeight);
			l4ypop.moveTo(0,0);
			l4ypop.focus();
			l4ypop.location.href = this.src;
		}
	}else{
		var l4yrand2 = String(l4ycount++);
		eval("l4ypop" + l4yrand2 + " = new Function(\"l4ypop = window.open('" + l4yref.src + "','showthumb','" + l4ypop_features + "'); if (l4ypop) {l4ypop.focus();}\")");
		eval("l4yref.onclick = l4ypop" + l4yrand2 + ";");
	}
	document.all ? l4yref.style.cursor = 'hand' : l4yref.style.cursor = 'pointer';
	l4yref.title = l4yimages_thumnailclick;
	if (window.showModelessDialog){
		l4yref.style.margin = '0px';
	}
}
if (document.getElementsByTagName && document.createElement){
	l4ypreload = new Array();
	if (window.GeckoActiveXObject || window.showModelessDialog){
		l4ywait = false;
	}else{
		l4ywait = true;
	}
	l4ypop_features = 'top=0,left=0,width=' + String(window.screen.width-80) + ',height=' + String(window.screen.height-190) + ',scrollbars=1,resizable=1';
	l4yover = false;
	l4ycount = 1;
	l4ytimer1 = null;
	if (!window.opera){
		l4ypop = new Object();
		l4ypop.closed = true;
		l4yold_onunload = window.onunload;
		window.onunload = function(){
			if (l4yold_onunload){
				l4yold_onunload();
				l4yold_onunload = null;
			}
			if (!l4ypop.closed){
				l4ypop.close();
			}
		}
	}
	window.setTimeout('l4ygo()',2000);
}