var popup = {
	popupWin: null,
	popupLinks: {},
	popupThumbs: {},
	init: function() {
		var aTags = document.getElementsByTagName('A');
		for (var i=0;i < aTags.length;i++) {
		
			if((' '+aTags[i].className+' ').indexOf(' imagePopup ') != -1){
// 					alert(aTags[i].href);
				if(aTags[i].href.indexOf('NoImage') != -1) {
					aTags[i].parentNode.appendChild(aTags[i].childNodes[0]);
					aTags[i].parentNode.removeChild(aTags[i]);
				} else {
				aTags[i].firstChild.bigImgSrc=aTags[i].href;
				aTags[i].target="";
				aTags[i].href="";
				aTags[i].firstChild.bigImg = document.createElement('img');
				aTags[i].firstChild.bigImg.src = aTags[i].firstChild.bigImgSrc;
				if(document.getElementById('prodHeader') != null) aTags[i].firstChild.prodName = document.getElementById('prodHeader').textContent;
				aTags[i].popupWin=null;
				popup.popupLinks[popup.popupLinks.length] = aTags[i];
				popup.popupThumbs[popup.popupThumbs.length] = aTags[i].firstChild;
				addEvent(aTags[i],'click',popup.doPopup,false);
				}
			}
		}
//		var imageWrapper = document.getElementById('imageThumb');
//		var imageLink = imageWrapper.firstChild;
//		var imageThumb = imageLink.firstChild;
//		imageThumb.bigImgSrc=imageLink.href;
//		imageLink.target="";
//		imageLink.href="";
//		imageThumb.prodName = document.getElementById('productsHeader').innerHTML;
//		imageThumb.bigImg = document.createElement('img');
//		imageThumb.bigImg.src=imageThumb.bigImgSrc;
		//imageThumb.bigImgHeight = bigImg.height;
		//imageThumb.bigImgWidth = bigImg.width;
//		addEvent(imageLink,'click',popup.doPopup,false);
	},
	focusPopups: function() {
		for(var i=0;i<popup.popupLinks.length;i++){
			
			popup.popupLinks[i].popupWin.focus();
			
		}
	},
	doPopup: function(ev) {
		var e = window.event ? window.event : ev;
		var t = e.target ? e.target : e.srcElement;
		while(t.tagName != 'A' && t.tagName != 'DIV') {
			t = t.parentNode;
		} 
		//popup.focusPopups();
		t.popupWin = window.open(null,null,'directories=no,location=no,menubar=no,status=no,scrollbars=no,toolbar=no,top=100,left=100,width='+t.firstChild.bigImg.width+',height='+t.firstChild.bigImg.height);
		
		if(t.popupWin.document.getElementById('popImg')) {
			t.popupWin.close(); 
			t.popupWin =window.open(null,null,'directories=no,location=no,menubar=no,status=no,scrollbars=no,toolbar=no,top=100,left=100,width='+t.firstChild.bigImg.width+',height='+t.firstChild.bigImg.height);
		}
		t.popupWin.document.open();
		t.popupWin.document.write('<html><head><TITLE>'+t.firstChild.prodName+'</TITLE><style>html, body { padding: 0px; margin:0px; }</style></style></head><body><img id="popImg" src="'+t.firstChild.bigImg.src+'" /></body></html>');
		t.popupWin.document.close();
		//popup.focusPopups();
		
		if(ev && ev.stopPropagation && ev.preventDefault) {
			e.stopPropagation();
			e.preventDefault();
		}
		if(window.event) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return false;
		}
	}
}
function popupInit() {
	if(!aH) var aH = new ajaxObject();
	//addCatAjax.init();
	popup.init();
};
addEvent(window,'load',popupInit, false); 