var pImages = new Array();
// Dragging
var oldX = 0;
var oldY = 0;
var dragging = 0;

function ChPic(nm,bigImg,bX,bY)
{
	// IE-s deda movtyan ra ramdeni chalichi unda :)
	var im  = document.getElementById('ProjPic');
	im.src = pImages[nm].src; 
	if (bigImg)
	{
		im.onclick = function(){ ShowPic(bigImg,bX,bY); return false;}
		im.style.cursor = 'pointer';
	}
	else
	{		
		im.onclick = function(){ return false; }
		im.style.cursor = 'default';	
	}
	//alert(im.onmouseup);
	return false;
}

function addImage(pt,nm)
{
	var temp = new Image();
	temp.src = pt;
	pImages[nm] = (temp);
}

/*function ShowPic(p_path, p_width, p_height){
	sDesrc = "width=" + p_width + ", height=" + p_height +
		", status=no, toolbar=no, menubar=no, scrollbars=yes";
	win=window.open('','Picture_Details', sDesrc);
	win.document.write("<html><style>body{padding:0px;margin:0px;}</style><body>");
	win.document.write("<img src='"+p_path+"' width='"+p_width+"' height='"+p_height+"'><br>");
	win.document.write("</body></html>");
	win.document.close();	
}
*/


function ShowPic(pt, w, h)
{
	var canvas = document.getElementById('canvas');
	canvas.style.width = document.body.offsetWidth;
	canvas.style.height = document.body.offsetHeight;
	canvas.style.display = 'block';
	var d=document.getElementById('imgDiv');
	var d2 = document.getElementById('bigImgDiv');
	
	d2.innerHTML = '';
	var im = new Image();
	im.src=pt;
	im.border="0";
	im.style.cursor = 'default';
	d2.appendChild(im);
	d.style.display = "block";
}

function CloseBig()
{
	var d=document.getElementById('imgDiv');
	var canvas = document.getElementById('canvas');

	canvas.style.display = 'none';
	d.style.display = 'none';
}

function DragStart(e){
	if (!e) e=window.event;
	oldX = e.clientX;
	oldY = e.clientY;
	dragging=1;
	document.onmouseup = function() { DragEnd(); }
}

function DragEnd(e)
{
	oldX = 0;
	oldY = 0;
	dragging = 0;
}

function doDrag(e)
{
	if (!dragging) return;
	if (!e) e=window.event;
	var d=document.getElementById('imgDiv');
	x = parseInt(d.style.left);
	y = parseInt(d.style.top);
	d.style.left = (x+(e.clientX-oldX))+'px';
	d.style.top  = (y+(e.clientY-oldY))+'px';
	oldX = e.clientX;
	oldY = e.clientY;
}
