(function(){
	try{window.addEventListener('load',arguments[0],false);}
	catch(e){window.attachEvent('onload',arguments[0]);}
})(function(){
	var thumbs = document.getElementById('thumbs').getElementsByTagName('a');
 for(var i=0; i<thumbs.length; i++){
		thumbs[i].onmouseover = function(){
			var itemImage = document.getElementById('itemImage');
			if(this.href.match(/\.html$/)){
				var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
						try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
						catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
				})();
				req.onreadystatechange = function(){ 
					if (req.readyState != 4 ) return ;
					if (req.status == 200 || req.status==0) {
						var resText = req.responseText;
						if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
							var esc = escape( resText );
							if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
								resText = decodeURIComponent( esc );
							}
						}
						
						if(resText.match(/<body.*>/)){
							var htmlBodyStart = resText.indexOf("<body")+(resText.match(/<body.*>/)+"").length;
							var htmlBodyEnd   = resText.indexOf("</body>");
							resText = resText.slice(htmlBodyStart,htmlBodyEnd);
						}
						document.getElementById('itemImage').innerHTML = resText;
						metaphase_iePng();
					}
					else{
						document.getElementById('itemImage').innerHTML = "<p style='background:#fff;'>loading...</p>";
					}
				}
				req.open('GET', this.href, true); 
				req.send(null);
			}
			else if(this.href.match(/\.jpg$/)){
				itemImage.getElementsByTagName('img')[0].setAttribute('src',this.href);
			}
			return false;
		}

		thumbs[i].onclick = function(){
			var itemImage = document.getElementById('itemImage');
			if(this.href.match(/\.html$/)){
				var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
						try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
						catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
				})();
				req.onreadystatechange = function(){ 
					if (req.readyState != 4 ) return ;
					if (req.status == 200 || req.status==0) {
						var resText = req.responseText;
						if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
							var esc = escape( resText );
							if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
								resText = decodeURIComponent( esc );
							}
						}
						
						if(resText.match(/<body.*>/)){
							var htmlBodyStart = resText.indexOf("<body")+(resText.match(/<body.*>/)+"").length;
							var htmlBodyEnd   = resText.indexOf("</body>");
							resText = resText.slice(htmlBodyStart,htmlBodyEnd);
						}
						document.getElementById('itemImage').innerHTML = resText;
						metaphase_iePng();
					}
					else{
						document.getElementById('itemImage').innerHTML = "<p style='background:#fff;'>loading...</p>";
					}
				}
				req.open('GET', this.href, true); 
				req.send(null);
			}
			else if(this.href.match(/\.jpg$/)){
				itemImage.getElementsByTagName('img')[0].setAttribute('src',this.href);
			}
			return false;
		}
	}
});
