function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

var timer = null;
var IMG = null;
var NewWindow = null;
function ViewImage(Isrc,title) {
	IMG = new Image;
	IMG.src = Isrc;
	if (typeof(title)=="undefined" || title=="") title="Gallery";
	if (NewWindow) { NewWindow.close(); }
	if (NewWindow==null || NewWindow.closed) {
		settings=
		 "left="+50+","
		 +"top="+50+","
		 +"width="+640+","
		 +"height="+480+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=no,"
		 +"resizable=yes"
		 NewWindow = window.open("",'Gallery',settings);
	}
	NewWindow.document.open();
	//NewWindow.document.clear();
	NewWindow.document.write(
         "<html><head><title>"+ title +"</title>"
        +"</head>\n"
        +"<body onclick=\"window.close();\" style=\"text-align:left;margin:15px;\">\n"
        +"<img src=\"" + IMG.src + "\" border=\"0\" alt=\""+title+"\" />\n"
        +"</body>\n"
        +"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
	timer = setInterval("resize()",250);
}

function resize() {
    if(!IMG.complete){ return; }
    clearInterval(timer);
	resizeWindowTo(NewWindow,(IMG.width+40),(IMG.height+100));
	IMG = null;
}

function resizeWindowTo(WindowObject,w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			WindowObject.outerWidth=w;
			WindowObject.outerHeight=h;
		}
		else WindowObject.resizeTo(w,h);
	}
}

function ProceedShowImage()
{
    var ImagesAnchors = document.getElementsByTagName('A');
    var Images = null;
    for (var i = 0 ; i < ImagesAnchors.length ; i++)
    {
        if (ImagesAnchors[i].className.indexOf('ShowImage') != -1)
        {
            ImagesAnchors[i].onclick = function() {
                ViewImage(this.href,"Gallery");
                return false;
            };
        }
    }
}


//onload
addEvent(window,'load',ProceedShowImage);



var PopupWin = null;
function OpenPopup(url,w,h) {
	if (PopupWin) { PopupWin.close(); }
	if (PopupWin==null || PopupWin.closed) {
		settings=
		 "left="+(screen.width-w)/2+","
		 +"top="+(screen.width-h)/2+","
		 +"width="+w+","
		 +"height="+h+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=no,"
		 +"resizable=yes"
		 PopupWin = window.open(url,'PopupWin',settings);
	}
	PopupWin.focus();
}