// JavaScript Document
var cmsName='bitpanel';
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
    	scrOfY = window.pageYOffset;
    	scrOfX = window.pageXOffset;
	} 
	else 
		if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
  		}
		else
			if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}		
			
	return [ scrOfX, scrOfY ];
}


//gets the amount of pixels shown on the visitor's browser
function getBodyDimensions() {
	
	//get the screen resolution
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	
	//get the body dimensions
	var bodyWidth = 0, bodyHeight = 0;
	if( typeof( document.body.offsetHeight ) == 'number' ) {
		//Non-IE
		bodyWidth = document.body.offsetWidth;
		bodyHeight = document.body.offsetHeight;
  	} 
	else{
		//IE in 'standards compliant mode'
		bodyWidth = window.innerWidth;
		bodyHeight = window.innerHeight;
	}	
 	 
	//alert(frameWidth+' >>> '+bodyWidth+' >>> '+Math.max(frameWidth,bodyWidth));
	//get the maximum between the resolution and body
	return[Math.max(frameWidth,bodyWidth),Math.max(frameHeight,bodyHeight+20)];
	
	
}


//draws the backgroud layer and the specified image
function drawFrames(imgSrc,path){
	
	if(typeof(path) == 'undefined')
		path='';

	//img menu table
	var tbl=document.createElement('table');
	tbl.id='enlg-img-table';
	tbl.style.display='none';
	tbl.style.border='1px solid #000000';
	
	var tr=tbl.insertRow(0);
	var td=tr.insertCell(0);
	td.align='left';
	td.innerHTML='<img src="'+path+cmsName+'/images/enlarge_image/back.gif" style="display: none" /><img src="'+path+cmsName+'/images/enlarge_image/forward.gif" style="display: none" />';
	var td=tr.insertCell(1);
	td.style.textAlign='right';
	td.innerHTML='<img src="'+path+cmsName+'/images/enlarge_image/close.gif" style="cursor: pointer" onClick="javascript: deleteFrame()" />';
	
	//loading
	var lImgRef=new Image();
	lImgRef.src=cmsName+'/images/enlarge_image/loading_animation.gif';
	lImgRef.id='application-loading-image';
	
	//enlarged
	var eImgRef=new Image();
	eImgRef.src=imgSrc;
	eImgRef.id='application-enlarged-image';
	eImgRef.style.display='none';
	
	//the loading image
	var imgHeight=32;
	var imgWidth=32;
	
	//frames
	var scr=getScrollXY();
	var bDim=getBodyDimensions();
	
	//drawing teh background
	drawAbsoluteDiv('bg-div',0,0,bDim[0],bDim[1],300,'#cccccc',5);
	var divRef=drawAbsoluteDiv('enlg-img-div',scr[1]+Math.round(screen.height/3)-Math.round(imgHeight/2),scr[0]+Math.round(screen.width/2)-Math.round(imgWidth/2),imgWidth,imgHeight,350,'#005b88',10);
	
	//adding the images
	divRef.appendChild(tbl);
	divRef.appendChild(lImgRef);
	divRef.appendChild(eImgRef);
	
	if(eImgRef.complete)
		showEnlargedImage();
	else	
		eImgRef.onload=showEnlargedImage;
}


//draws the background
function drawAbsoluteDiv(id,top,left,width,height,zIndex,bgColor,transparency){
	var divRef=document.createElement('div');
	divRef.id=id;
	divRef.style.height=height+'px';
	divRef.style.width=width+'px';
	divRef.style.position='absolute';
	divRef.style.left=left+'px';
	divRef.style.top=top+'px';
	divRef.style.backgroundColor=bgColor;
	divRef.style.zIndex=zIndex;
	divRef.style.opacity = transparency/10;
	divRef.style.filter = 'alpha(opacity=' + transparency*10 + ')';
	document.body.appendChild(divRef);
	return divRef;
}


//
function showEnlargedImage(){
	document.getElementById('application-loading-image').style.display='none';
	var menuHeight=27;
	var scr=getScrollXY();
	//frame
	var imgRef=document.getElementById('application-enlarged-image');
	var divRef=document.getElementById('enlg-img-div');
	//get the body dimensions
	var bDim=getBodyDimensions();
	
	//testing if the image fits in the screen
	var top=scr[1]+Math.round(screen.height/3)-Math.round(imgRef.height/2);
	var overflowTop=0;
	
	//if the image is taller than the screen
	if(top<10){
		overflowTop=Math.abs(top);
		top=10;
	}
	
	//if the image+menu is longer than the screen
	if(bDim[1]+10<imgRef.height+top+menuHeight)
		document.getElementById('bg-div').style.height=top+menuHeight+imgRef.height+10+'px';
		
	divRef.style.top=top+'px';
	divRef.style.left=scr[0]+Math.round(screen.width/2)-Math.round(imgRef.width/2)+'px';
	divRef.style.width=imgRef.width+'px';
	divRef.style.height=imgRef.height+menuHeight+'px';
	
	/////adding menu
	var tbl=document.getElementById('enlg-img-table');
	tbl.style.width=imgRef.width+'px';
	//tbl.style.border='1px solid #000000';
	tbl.rows[0].cells[0].style.width=Math.round(imgRef.width/2)+'px';
	tbl.rows[0].cells[1].style.width='50%';
	tbl.style.display='block';
	////

	imgRef.style.display='block';
	
}


//
function deleteFrame(){
	document.body.removeChild(document.getElementById('bg-div'));
	document.body.removeChild(document.getElementById('enlg-img-div'));
}