var left = 0; //Starting Location - left
var top = 0; //Starting Location - top
var Imageinterval = 50; //Move 10px every initialization
var LinkImage = "";
var ImageWidth = "";
var ImageHeight = "";
var OldHeightDoc = 0;

function ShowImage(NewLink)
{
	LinkImage = NewLink;
	
	image2 = new Image();
	image2.src = LinkImage;    
	ImageWidth = image2.width;
	ImageHeight = image2.height;  
	 
	var VideoWindow = document.getElementById('PreviewImage');
        
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', "ShowImageNew");
	newdiv.setAttribute('style', "Z-INDEX: 103; POSITION: fixed; BACKGROUND-COLOR: #000000;width: 0px; height: 0px;filter: alpha(opacity=45);-moz-opacity: .45; opacity:0.45; top: -5px");
	newdiv.setAttribute('onclick', "removeImage() ;");
	newdiv.innerHTML = '';
	VideoWindow.appendChild(newdiv);
 
	var newdiv2 = document.createElement('div');
	newdiv2.setAttribute('id', "ShowImageNew2");
	newdiv2.setAttribute('style', "Z-INDEX: 104;POSITION: absolute; BACKGROUND-COLOR: white;width: 10px; height:10px;border: 0px solid black ;");
	newdiv2.innerHTML = '';
	VideoWindow.appendChild(newdiv2);
	
        //alert(document.getElementById("AllDocument").clientHeight);
        
        newdiv.style.width =  screen.availWidth + "px" ;//"100%"; //document.getElementById("AllDocument").style.width;
	newdiv.style.height = screen.availHeight + "px"; //"120%"; //document.getElementById("AllDocument").style.height;
        
        //alert(Skata.style.pixelHeight);
        
        //var tempheight = document.getElementById("AllDocument").offsetHeight;

//	alert(tempheight);	
//	newdiv.style.height = "110%";
        
        //newdiv.style.width = document.getElementById('AllDocument').offsetWidth + 'px';
	//newdiv.style.height = document.getElementById('AllDocument').offsetHeight + 'px';
	
	left = (screen.width/2);

        var GetScrollTop = (window.pageYOffset)?(window.pageYOffset):(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop;

	top = GetScrollTop + 100;
		
	newdiv2.style.left = left + 'px';
	newdiv2.style.top = top + 'px';

	//OldHeightDoc =	document.getElementById("AllDocument").offsetHeight;
      
	//var countheight = ImageHeight + 200 + GetScrollTop;
	         
	//if (countheight >  OldHeightDoc)
	//{
	//	document.getElementById("AllDocument").style.height = countheight +'px';
	//}
	
		
	window.setTimeout('OpenWindowImageHeight()',500);
}

function OpenWindowImageHeight()
{
	var ObjectHeight = 0;
	ObjectHeight = document.getElementById('ShowImageNew2').offsetHeight;
	ObjectHeight = ObjectHeight + Imageinterval;
		
	document.getElementById("ShowImageNew2").style.height = ObjectHeight+'px';
	
	if (ObjectHeight < (image2.height + 20))  
	{
		window.setTimeout('OpenWindowImageHeight()',10);
		return;
	}
	
	document.getElementById('ShowImageNew2').style.height = (image2.height + 20) + 'px';
	window.setTimeout('OpenWindowImageWidth()',10);
}

function OpenWindowImageWidth()
{
	var ObjectWidth = 0;

	left = left - Imageinterval; 
	
	document.getElementById('ShowImageNew2').style.left  = left +'px';
	
	ObjectWidth = document.getElementById('ShowImageNew2').offsetWidth;
	ObjectWidth = ObjectWidth   + (2 * Imageinterval);
		
	document.getElementById('ShowImageNew2').style.width = ObjectWidth + 'px';
	
	if (ObjectWidth < (image2.width + 20))  
	{
		window.setTimeout('OpenWindowImageWidth()',10);
		return;
	}
	
	document.getElementById('ShowImageNew2').style.width  =  (image2.width + 20) + 'px';
        
	window.setTimeout('CreateImage()', 10);
}

function CreateImage()
{
	var newdiv2 = document.getElementById('ShowImageNew2');
		
	var sHTML="<div id='imagespace' style='BACKGROUND-COLOR: #FFFFFF; PADDING-LEFT: 10px; PADDING-TOP: 10px;'>";
	sHTML= sHTML + "<div style='width:" + image2.width + "px;" + " height: " + image2.height + "px;"  +" background-image: url(Images/loading.gif); background-repeat: no-repeat; background-position:center;'>";
	sHTML= sHTML + "<IMG src='" + LinkImage + "' onerror='javascript: ErrorPic(this)'>";
	sHTML= sHTML + "</div>";
	sHTML= sHTML + "</div>";						
	newdiv2.innerHTML  = sHTML; 
}

function removeImage() 
{
//	GetThis.parentNode.removeChild(GetThis);
//	document.getElementById('imagespace').parentNode.removeChild('imagespace');
	$("imagespace").remove();
	left = parseInt(document.getElementById('ShowImageNew2').style.left);
	
	window.setTimeout('CloseWindowImageWidth()',10);
}


function CloseWindowImageWidth()
{
	var ObjectWidth = 0;

	left = left + Imageinterval; 
		
	document.getElementById('ShowImageNew2').style.left  = left +'px';
	
	ObjectWidth = document.getElementById('ShowImageNew2').offsetWidth;
	ObjectWidth = ObjectWidth   - (2 * Imageinterval);
	
	if (ObjectWidth < 0) ObjectWidth = 10;
	
	document.getElementById('ShowImageNew2').style.width = ObjectWidth + 'px';
	
	if (ObjectWidth > 10)  {
		window.setTimeout('CloseWindowImageWidth()',10);
		return;
	}
	
	document.getElementById('ShowImageNew2').style.width = 10 + 'px';
	
	top = parseInt(document.getElementById('ShowImageNew2').style.top);

	window.setTimeout('CloseWindowImageHeight()',10);
}

function CloseWindowImageHeight()
{
	var ObjectHeight = 0;
	ObjectHeight = document.getElementById('ShowImageNew2').offsetHeight;
	ObjectHeight = ObjectHeight   - (2 * Imageinterval);
	
	if (ObjectHeight < 0) ObjectHeight = 10;
		
	document.getElementById('ShowImageNew2').style.height = ObjectHeight + 'px';
	
	if (ObjectHeight > 10)  {
		window.setTimeout('CloseWindowImageHeight()',10);
		return;
	}
	
 	document.getElementById("ShowImageNew2").style.height =  0 + 'px';
	document.getElementById("ShowImageNew2").style.width = 0 + 'px';
	
	var VideoWindow = document.getElementById('PreviewImage');
	var newdiv = document.getElementById('ShowImageNew');
	var newdiv2 = document.getElementById('ShowImageNew2');
	VideoWindow.removeChild(newdiv2);
	VideoWindow.removeChild(newdiv);
	
	document.getElementById("AllDocument").style.height = '100%';
}
