
//dv = document.getElementById('test');

function showLoad(id)
{

	dv = document.getElementById(id);
	//alert(dv.style.opacity);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)<1)
	{
		dv.style.opacity=parseFloat(dv.style.opacity)+0.05 ;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		//alert(dv.style.filter);
		setTimeout('showLoad("'+id+'");',1);
	}

}
function stopLoad(id,sLink)
{

	dv = document.getElementById(id);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)>0)
	{
		//alert(dv.style.opacity);
		dv.style.opacity=parseFloat(dv.style.opacity)-0.1;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		setTimeout('stopLoad("'+id+'","'+sLink+'");',1);
	}
	else {
		location.replace(sLink);
	}

}
function startFade(id)
{

	//dv=obj;
	//alert('yoo');
	//document.getElementById(textId).style.color='white';
	dv = document.getElementById(id);
	if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoad("'+id+'");',1);

}
function endFade(id,sLink)
{
	//document.getElementById(textId).style.color='#999';
	//dv=obj;
	//alert('yoo');
	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoad("'+id+'","'+sLink+'");',1);

}










function showLoadImage(id,sLimit)
{

	dv = document.getElementById(id);
	//alert(dv.style.opacity);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)<parseFloat(sLimit))
	{
		dv.style.opacity=parseFloat(dv.style.opacity)+0.1;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		//alert(dv.style.filter);
		setTimeout('showLoadImage("'+id+'","'+sLimit+'");',1);
	}

}
function stopLoadImage(id)
{

	dv = document.getElementById(id);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)>0)
	{
		//alert(dv.style.opacity);
		dv.style.opacity=parseFloat(dv.style.opacity)-0.2;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		setTimeout('stopLoadImage("'+id+'");',1);
	}
	else {
		//alert('ddd');
		document.getElementById(id).style.zIndex='-5';
	}

}
//увеличивает из превюхив большое изображение
function fnEnlarge(path,width,height)
{

	document.getElementById('img_big').innerHTML='<img onclick="endFadeImage();" style=\'cursor:pointer;\' src="images/'+path+'">';
	document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
	document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

}


function startImage(sLink,width,height,good_key)
{
	//alert(width);
	//document.getElementById('imgBlock').style.backgroundColor="none";
	//	document.getElementById('imgBlock').style.textAlign="center";
	out='<div id="img_big"><img onclick="endFadeImage();" style="cursor:pointer;" src="'+sLink+'"></div><div style="width:500px; text-align:center;">';
	if(good_key!='')
	{
		JsHttpRequest.query(
		'load_info.php', // backend
		{
			// pass a text value
			'action': 'get_image_by_key',
			'good_key': good_key
		},
		// Function is called when an answer arrives.
		function(result, errors) {
			if (errors && errors!=='') {
				//document.getElementById('test').appendChild(document.createTextNode(errors));
				//alert(errors);
			}
			// Write errors to the debug div.
			// document.getElementById("debug").innerHTML = errors;
			// Write the answer.
			if (result) {
				//alert(result.length);
				for(i=0;i<result.length;i++)
				{
					res=result[i];

					out+='<img onclick="fnEnlarge(\''+res['path']+'\',\''+res['width']+'\',\''+res['height']+'\',\''+res['image_key']+'\');" style="cursor:pointer;" height=100 src="thumbnails/'+res['path']+'">';

					//alert(out);
				}



				out+='</div>';
				//alert(document.getElementById('imgBlock').innerHTML);
				document.getElementById('imgBlock').innerHTML=out;
				
				//??????? ??????
				document.body.style.overflow='hidden';
				//alert(document.getElementById('imgBack').style.zIndex);
				//??????? ?????? ??????
				document.getElementById('imgBack').style.zIndex='7';
				document.getElementById('imgBlock').style.zIndex='8';
				document.getElementById('imgBlock').style.height=parseInt(800+5)+"px";

				//alert(width);
				//?????????????
				document.getElementById('imgBlock').style.marginLeft='-'+(parseFloat(width)/2)+'px';
				//alert(height);
				document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

				id='imgBack';
				dv = document.getElementById(id);
				//if(parseFloat(dv.style.opacity)==0)
				setTimeout('showLoadImage("'+id+'","0.5");',1);


				id='imgBlock';
				dv = document.getElementById(id);
				//	if(parseFloat(dv.style.opacity)==0)
				setTimeout('showLoadImage("'+id+'","1");',1);

			}
		},
		true  // do not disable caching
		);
	}
	else
	{
		out+='</div>';
		//alert(document.getElementById('imgBlock').innerHTML);
		document.getElementById('imgBlock').innerHTML=out;

		//??????? ??????
		document.body.style.overflow='hidden';
		//alert(document.getElementById('imgBack').style.zIndex);
		//??????? ?????? ??????
		document.getElementById('imgBack').style.zIndex='7';
		document.getElementById('imgBlock').style.zIndex='8';
			document.getElementById('imgBlock').style.height=parseInt(height)+"px";
			//alert(	document.getElementById('imgBlock').style.height);

		//alert(width);
		
		//?????????????
		document.getElementById('imgBlock').style.marginLeft='-'+(parseFloat(width)/2)+'px';
				//alert(height);
				document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height/3))+'px';
				//alert(document.getElementById('imgBlock').style.marginTop);

		id='imgBack';
		dv = document.getElementById(id);
		//if(parseFloat(dv.style.opacity)==0)
		setTimeout('showLoadImage("'+id+'","0.5");',1);


		id='imgBlock';
		dv = document.getElementById(id);
		//	if(parseFloat(dv.style.opacity)==0)
		setTimeout('showLoadImage("'+id+'","1");',1);
	}

}
function endFadeImage()
{
	id='imgBlock';

	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoadImage("'+id+'");',1);

	id='imgBack';

	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoadImage("'+id+'");',1);

	document.body.style.overflow='auto';
}

