// ISO - image_soft_open

function showImage (A) {
	src = A.href;
	bigEl = document.createElement('div');
	bigEl.id = 'image_back';
	bigEl.style.zIndex = 9998;
	bigEl.style.position = 'absolute';
	bigEl.style.display = 'none';
	bigEl.style.background = 'black';
	bigEl.style.width = '100%' 
	bigEl.style.height = (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
	bigEl.style.top = '0px';
	bigEl.style.left = '0px';
	document.body.appendChild (bigEl);
	
	theLoading = document.createElement('div');
	theLoading.id = 'loading';
	theLoading.style.zIndex = 9999;
	theLoading.style.position = 'absolute';
	theLoading.style.width = 100+'px';
	theLoading.style.height = 50+'px';
	theLoading.style.background = '#EEE';
	theLoading.style.border = '1px solid #CCC';
	theLoading.style.top = document.body.scrollTop+((document.body.clientHeight - 50) / 2)+'px';	
	theLoading.style.left = ((document.body.offsetWidth - 50) / 2)+'px';
	theLoading.innerHTML = '<div style="text-align:center; cursor: pointer"><img src="well/pics/big/loading.gif" alt="LOADing"><br>ÇÀÃÐÓÇÊÀ</div>';
	theLoading.onclick = function() { closeImage(); }
	document.body.appendChild(theLoading);	
	
	var imgPreload = new Image();
	imgPreload.onload = function() {
		document.body.removeChild(theLoading);
		El = document.createElement('div');
		El.id = 'image_window';
		El.style.zIndex = 9999;
		El.style.position = 'absolute';
		El.style.background = '#EEE';
		El.style.border = '1px solid #CCC';
		El.style.width = imgPreload.width+10+'px';
		El.style.top = document.body.scrollTop+((document.body.clientHeight - imgPreload.height) / 2)+'px';	
		El.style.left = ((document.body.offsetWidth - imgPreload.width-10) / 2)+'px';
		El.innerHTML = ''+
			"<table width=100%>"+
			"	<tr><td style='text-align:center'><a href='javascript:void(0)'><img id='popupImage' src='"+src+"' alt='' style='border: 1px solid #CCC; display:none'></a>"+
			"	<tr><td style='text-align:center'><a href='javascript:void(0)'>ÇÀÊÐÛÒÜ</a>";		
			"</table>";
		document.body.appendChild (El);
		errorOK = El.getElementsByTagName('A')[0];
		errorOK.onclick = function() {fadeOpacity.backQ('image_back'); fadeOpacity.backQ('image_window'); El.parentNode.removeChild(El); bigEl.parentNode.removeChild(bigEl);}
		errorOK = El.getElementsByTagName('A')[1];
		errorOK.onclick = function() {fadeOpacity.backQ('image_back'); fadeOpacity.backQ('image_window'); El.parentNode.removeChild(El); bigEl.parentNode.removeChild(bigEl);}
		img = El.getElementsByTagName('IMG')[0];

		setElementOpacity(El, 0);
		if (!fadeOpacity.aRules['imgRule']) fadeOpacity.addRule('imgRule', 0, 1, 30); 	
		fadeOpacity('image_window', 'imgRule');
		img.style.display = 'inline';
	}
	imgPreload.src = A.href;
	
	setElementOpacity(bigEl, 0);	
	if (!fadeOpacity.aRules['backRule']) fadeOpacity.addRule('backRule', 0, 0.5, 30);
	fadeOpacity('image_back', 'backRule');
	bigEl.style.display = 'inline';
}

function closeImage() {
	bigEl = document.getElementById('image_back');
	bigEl.parentNode.removeChild(bigEl);
	theLoading = document.getElementById('loading');
	theLoading.parentNode.removeChild(theLoading);	
}

function initISO() {
	if (!document.getElementsByTagName) { return; }
	var anchors = document.getElementsByTagName('a');

	for (i=0,len=anchors.length; i<len; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == 'ISO')) {
			anchor.onclick = function() { showImage(this); return false; }
		}
	}
	anchor = null;
}

addLoadEvent(initISO);
