/*
* global variable
*/
var topPos;
var leftPos;
var topPosBlend;
var topPosPopup;
var fadeInterval;
var i=0;
var fade=1;
var id2;
var id3;

/*
onscroll and onresize events
*/
window.onresize = function()
{
	if(document.getElementById('blend').style.display=='block' && document.getElementById('popup').style.display=='block'){
		fade=0;
		showPopup();
	}
}

window.onscroll = function()
{
	if(document.getElementById('blend').style.display=='block' && document.getElementById('popup').style.display=='block'){
		fade=0;
		showPopup();
	}
}

/*
showPopup+fadeIn
*/
function fadeIn(){
	if(i!=10)
	{
		document.getElementById('blend').style.opacity='0.'+i;
		document.getElementById('popup').style.opacity='0.'+i;
	}
	else
	{
		document.getElementById('blend').style.opacity=i;
		document.getElementById('popup').style.opacity=i;		
	}
	document.getElementById('blend').style.filter='alpha(opacity='+(i*10)+')';
	document.getElementById('popup').style.filter='alpha(opacity='+(i*10)+')';
	i++;	
	if(i==10){
		window.clearInterval(fadeInterval);	
		i=0;
		getCountImage();
	}	
	//window.scrollTo(0,0);
}

function showPopup(wid2,wid3)
{			

	id3=wid3;
	id2=wid2;	
	imageNr=wid2;
	countImageUrl = countImageUrl2+'id2='+id3+'&id3='+id2+'&';
	loadImageUrl  = loadImageUrl2+'id2='+id3+'&id3='+id2+'&';	
	
	if(fade==1)
	{	
		document.getElementById('popup').style.opacity='0';
		document.getElementById('blend').style.opacity='0';
		document.getElementById('blend').style.filter='alpha(opacity=0)';
		document.getElementById('popup').style.filter='alpha(opacity=0)';	
		document.getElementById('blend').style.display='block';
		document.getElementById('popup').style.display='block';	
	}
	
	topPos = (document.getElementById('blend').offsetHeight-document.getElementById('popup').offsetHeight)/2;	
	leftPos = (document.getElementById('blend').offsetWidth-document.getElementById('popup').offsetWidth)/2;		
	
	topPosPopup = document.documentElement.scrollTop+topPos;
	topPosBlend = document.documentElement.scrollTop;
	
	
	document.getElementById('popup').style.top = topPosPopup+'px';
	document.getElementById('popup').style.left = leftPos+'px';	
	
	document.getElementById('blend').style.top = topPosBlend+'px';			
	if(fade==1)
	{
		fadeInterval = window.setInterval("fadeIn()", 10);
	}
	fade=1;
}

/*
closePopup+fadeOut
*/
function fadeOut(){
	if(i!=10)
	{
		document.getElementById('blend').style.opacity='0.'+i;
		document.getElementById('popup').style.opacity='0.'+i;
	}
	else
	{
		document.getElementById('blend').style.opacity=i;
		document.getElementById('popup').style.opacity=i;		
	}	
	
	document.getElementById('blend').style.filter='alpha(opacity='+(i*10)+')';
	document.getElementById('popup').style.filter='alpha(opacity='+(i*10)+')';
	i--;	
	if(i==0){
		window.clearInterval(fadeInterval);	
		i=0;
		document.getElementById('blend').style.display='none';
		document.getElementById('popup').style.display='none';			
	}		
}

function closePopup()
{
	i=10;
	fadeInterval = window.setInterval("fadeOut()", 10);	
}
