function httpreq() {
	try { return new XMLHttpRequest(); } catch(e) { }
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { }
	try { return ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { }
	return false;
}
function moreimg(proj,resp) {
	if (document.getElementById) {
		this.proj=proj;
		this.resp=resp;
		var obj = this;
		this.anchor = document.getElementById('moreimg');
		if (this.anchor) {
			this.container = this.anchor.parentNode;
			this.container.style.width="451px";
			this.container.style.display="block";
			var img = this.container.parentNode.getElementsByTagName('img');
			this.anchor.style.width = img[0].offsetWidth;
		}
		var popup = function() {
			obj.popup(this);
			return false;
		}
		if (this.anchor) {
			this.anchor.onclick=popup;
		}
		this.popupele = null;
	}
}
moreimg.prototype={
initpopup:function(ele) {
	this.popupshadow = document.createElement('div');
	this.popupshadow.className = 'popshad';
	for (x = 1; x <= 3; x ++) {
		div = document.createElement('div');
		div.className = 's'+x;
		if (x == 2) {
			this.popupshadowspace = div;
		}
		this.popupshadow.appendChild(div);
	}
	document.body.appendChild(this.popupshadow);

	this.popupele = document.createElement('div');
	this.popupele.className='moreimg';
	this.popupelecont = document.createElement('div');
	this.popupele.appendChild(this.popupelecont);
	document.body.appendChild(this.popupele);

	var obj = this;
	setTimeout(function() {
		obj.popupheight = obj.popupele.offsetHeight;
		obj.popupwidth = obj.popupele.offsetWidth;
	}, 50);
	setTimeout(function() {
		obj.loadimages();
	}, 200);
},loadimages:function() {
	var obj = this;
	var over = function() {
		this.className = 'over';
	}
	var out = function() {
		this.className = '';
	}
	var click = function() {
		viewimg(this.imageid);
	}
	obj.popupele.style.background="buttonface";
	obj.popupele.style.height="auto";
	for (x = 0; x < this.resp.length; x++) {
		div = document.createElement('div');
		div.imageid = this.resp[x];
		div.onmouseover = over;
		div.onmouseout = out;
		div.onclick = click;
		img = document.createElement('img');
		img.src='past_projects.nb?nb%5Bop%5D=image&nb%5Bsize%5D=3&nb%5Bid%5D='+this.resp[x];
		img.width = 120;
		img.height = 90;
		div.appendChild(img);
		obj.popupelecont.appendChild(div);
	}
	setTimeout(function() {
		if (obj.popupele.offsetHeight > 300) {
			obj.popupele.style.height="300px";
		}
		var top = 2;
		if (navigator.userAgent.indexOf("Firefox/") != -1) {
			top = 0
		}
		var head = obj.anchor;
		while (head) {
			top += head.offsetTop;
			head = head.offsetParent;
		}

		var totalheight = window.scrollY != undefined?window.scrollY + window.innerHeight:totalheight = document.body.parentNode.clientHeight + document.body.parentNode.scrollTop;

		obj.popupheight = obj.popupele.offsetHeight;

		if (top + 16 + obj.popupheight > totalheight) {
			obj.popupele.style.top = (top + 2 - obj.popupheight) + 'px';
			obj.popupshadow.style.top = (top - 9 - obj.popupheight) + 'px';
		} else {
			obj.popupele.style.top = (top + 18) + 'px';
			obj.popupshadow.style.top = (top + 7) + 'px';
		}
		obj.popupele.style.visibility="visible";
		obj.popupshadow.style.visibility="visible";
		obj.popupshadowspace.style.height = (obj.popupheight - 44) + 'px';
	}, 20);
},popup:function(ele) {
	if (this.popupele == null) {
		this.initpopup();
	}
	var top = 2;
	var head = ele;
	var left = head.offsetWidth - 160;
	while (head) {
		top += head.offsetTop;
		left += head.offsetLeft;
		head = head.offsetParent;
	}

	if (navigator.userAgent.indexOf("Firefox/") != -1) {
		left -= 2;
		top -= 2;
	}

	var obj = this;

	setTimeout(function() {

		var totalheight = window.scrollY != undefined?window.scrollY + window.innerHeight:totalheight = document.body.parentNode.clientHeight + document.body.parentNode.scrollTop;

		if (top + 16 + obj.popupheight > totalheight) {
			obj.popupele.style.top = (top + 2 - obj.popupheight) + 'px';
			obj.popupshadow.style.top = (top - 9 - obj.popupheight) + 'px';
		} else {
			obj.popupele.style.top = (top + 18) + 'px';
			obj.popupshadow.style.top = (top + 7) + 'px';
		}

		obj.popupele.style.left = (left) + 'px';
		obj.popupshadow.style.left=(left - 11) + 'px';
		
		obj.popupele.style.display="block";
		obj.popupshadowspace.style.height = (obj.popupheight - 44) + 'px';
		obj.popupshadow.style.display="block";

		function hidepopup() {
			obj.hidepopup();
		}
		setTimeout(function() {
			obj.oldbodyfunction = document.body.onclick;
			document.body.onclick=hidepopup;
		}, 10);
	}, 60);
},hidepopup:function() {
	this.popupele.style.display="none";
	this.popupshadow.style.display="none";
	document.body.onclick=this.oldbodyfunction;
}}
function viewimg(img) {
	window.open('past_projects.nb?project%5Bop%5D=images&project%5Bimgid%5D='+img, '', 'width=850,height=734,scrollbars=no');
	return false;
}
function initgallery(){
	if (document.getElementById){
		this.output=document.getElementById('output');
		var navbar=document.getElementById('scrollee');
		var x,a=navbar.getElementsByTagName('a');
		var obj=this;
		this.current=false;
		this.output.style.background="white url(/perfects/style/images/loading.gif) 50% 50% no-repeat";
		for (x=0;x<a.length;x++){
			a[x].img = false;
			a[x].onclick=function(){
				return obj.load(this);
			}
			if(a[x].className=='c'){
				this.current=a[x];
			}
		}
		this.scrollee = document.getElementById('scrollee');
		this.scroller = document.getElementById('imagelisting');
		if (this.scroller.offsetWidth < this.scrollee.offsetWidth) {
			function down() {
				this.className = 'scroller down active';
			}
			function up() {
				this.className = 'scroller active';
			}
			function scroll() {
				if (this.id == 'left') {
					obj.scrollee.pos -= 780;
					if (obj.scrollee.pos < 0) {
						obj.scrollee.pos = 0;
					}
				} else if (this.id == 'right') {
					obj.scrollee.pos += 780;
					if (obj.scrollee.pos > obj.scrollee.max) {
						obj.scrollee.pos = obj.scrollee.max;
					}
				}
				obj.move();
			}
			this.left = document.getElementById('left');
			this.right = document.getElementById('right');
			this.left.className = 'scroller active';
			this.right.className = 'scroller active';
			this.left.onmousedown = down;
			this.right.onmousedown = down;
			this.left.onmouseup = up;
			this.right.onmouseup = up;
			this.left.onmouseout = up;
			this.right.onmouseout = up;
			this.scrollee.style.left = '0px';
			this.scrollee.pos = 0;
			this.scrollee.cur = 0;
			this.scrollee.max = this.scrollee.offsetWidth - this.scroller.offsetWidth;
			this.interval = null;
			this.left.onclick = scroll;
			this.right.onclick = scroll;
		}
	}
}

initgallery.prototype={
load:function(a) {
	a.blur();
	if(a==this.current) {
		return false;
	}
	if (this.current) {
		this.current.className='';
	}
	a.className='c';
	this.current=a;
	if(this.output.childNodes.length) {
		this.output.removeChild(this.output.childNodes[0]);
	}

	if(a.img == false) {
		var i=a.getAttribute('href');
		i='past_projects.nb?nb%5Bop%5D=image&nb%5Bsize%5D=5&nb%5Bid%5D='+i.replace(/.*=([0-9]+)$/,'$1');
		a.img=new Image();
		var obj=this;
		if (typeof(a.img.complete) != 'undefined') {
			a.img.onload=function() {
				obj.show(a);
			}
			a.img.src=i;
		} else {
			a.img.src=i;
			this.output.appendChild(a.img);
		}
	} else {
		if (typeof(a.img.complete) == 'undefined') {
			this.output.appendChild(a.img);
		} else if(a.img.complete) {
			this.output.appendChild(a.img);
		}
	}
	return false;
},show:function(a) {
	if(this.current==a){
		this.output.appendChild(a.img);
	}
},move:function() {
	if (this.scrollee.pos != this.scrollee.cur) {
		if (this.interval == null) {
			var obj = this;
			this.interval = setInterval(function() {
				var delta = Math.ceil((obj.scrollee.pos - obj.scrollee.cur) / 2);
				obj.scrollee.cur += delta;
				obj.scrollee.style.left = (0 - obj.scrollee.cur) + 'px';
				if (Math.abs(delta) <= 0) {
					clearInterval(obj.interval);
					obj.interval = null;
				}
			}, 40);
		}
	}
}
}
