// JavaScript Document
var allImgs, mBody, imgFrame, bMask,isIE, mHeight, mTop, mTotal;
var allDestine=new Array();
var allTitle=new Array();
var preLoad=new Array();
var opacity=70;
function getObjs(){
	mBody=document.getElementsByTagName('body').item(0);
	allImgs=document.getElementsByTagName('img');
	isIE=(navigator.appVersion.indexOf("MSIE")!=-1);
		
	for(x=0;x<allImgs.length;x++){
		allDestine[x]=allImgs[x].getAttribute('rel');
		allTitle[x]=allImgs[x].getAttribute('alt');
		preLoad[x]=new Image();
		preLoad[x].src=allDestine[x];
		allImgs[x].onclick=new Function ('showPic('+x+')');
	}
}

function showPic(target){
	/*if(isIE){
		mHeight=document.body.clientHeight;
		mTotal=document.body.scrollHeight;
		mTop=document.body.scrollTop;
		
		}else{
			mHeight=document.documentElement.clientHeight;
			mTotal=document.documentElement.scrollHeight;
			mTop=document.documentElement.scrollTop;
			}*/
		mHeight=document.documentElement.clientHeight;
			mTotal=document.documentElement.scrollHeight;
			mTop=document.documentElement.scrollTop;
	bMask=document.createElement('div');
	bMask.setAttribute('id','allMask');
	bMask.style.width=mBody.offsetWidth+"px";
	bMask.style.height=mTotal+"px";
	bMask.style.backgroundColor="#000";
	bMask.style.MozOpacity=opacity/100;//for FireFox;
	bMask.style.KhtmlOpacity=opacity/100;//for previous version Safari;
	bMask.style.opacity=opacity/100;//for browser which support opacity style;
	bMask.style.filter = "alpha(opacity=" + opacity + ")";// for IE
	mBody.appendChild(bMask);
	bMask.onclick=function(){closeImg();}
	
	imgFrame=document.createElement('div');
	imgFrame.setAttribute('id','imgFrame');
	imgFrame.style.width=(20+preLoad[target].width)+"px";
	imgFrame.style.left=Math.floor((mBody.offsetWidth-(20+preLoad[target].width))/2)+"px";
	imgFrame.style.top=Math.floor(((mHeight-(50+preLoad[target].height))/2)+mTop)+"px";
	
	mBody.appendChild(imgFrame);
	imgFrame.onclick=function(){closeImg();}
	
	bigImg=document.createElement('img');
	bigImg.src=allDestine[target];
	bigImg.onclick=function(){closeImg();}
	imgFrame.appendChild(bigImg);
	
	bigTitle=document.createElement('div');
	bigTitle.setAttribute('id','bigTitle');
	bigTitle.style.right=0+"px";
	bigTitle.style.bottom=0+"px";
	bigTitle.onclick=function(){closeImg();}
	imgFrame.appendChild(bigTitle);
	
	function closeImg(){
		mBody.removeChild(bMask);
		mBody.removeChild(imgFrame);
	}
	
}

window.onload=function(){
getObjs();

}
