var ProgressBegin = ProgressX = ProgressW = 0;
var ProgressEnd = 133;
var ProgressWidth = 30;
var Marign = 15;
var t_id = '';

function GetPosition(Width , Height, event) {
	var x = y = Marign;
	if (document.attachEvent != null) { // Internet Explorer & Opera
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		if ( Width > ( window.event.clientX - Marign ) ) { x = Width + Marign } else { x -= Width + Marign }
		if ( Height > window.event.clientY ) { y = document.documentElement.scrollTop + 5 } else { y -= Height }
		}
	if (!document.attachEvent && document.addEventListener) { // Gecko
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
		if ( Width > ( event.clientX - Marign ) ) { x = Width + Marign } else { x -= Width + Marign }
		if ( Height > event.clientY ) { y = window.scrollY + 5 } else { y -= Height }
		}
	return {x:x, y:y};
	}

function ProgressAnimate() {
	var Progress = document.getElementById('progress');
	ProgressBegin += 2;
	if (ProgressBegin < ProgressWidth) { ProgressW = ProgressBegin; }
	if (ProgressBegin >= ProgressWidth && ( ProgressBegin + ProgressWidth ) < ProgressEnd ) { ProgressX = ProgressBegin - ProgressWidth; }
	if (ProgressBegin > ProgressWidth && ( ProgressBegin + ProgressWidth ) > ProgressEnd ) { ProgressX = ProgressBegin - ProgressWidth; }
	if (ProgressBegin > ProgressWidth && ( ProgressBegin + ProgressWidth ) > ( ProgressEnd  + ProgressWidth ) ) { ProgressX = ProgressBegin - ProgressWidth; ProgressW = ProgressEnd - ProgressX; }
	if (ProgressBegin >= ( ProgressEnd + ProgressWidth ) ) { ProgressBegin = ProgressX = ProgressW = 0; ProgressWidth = 30; }
	Progress.style.left = ProgressX + 'px';
	Progress.style.width = ProgressW + 'px';
	}

function ProgressStop() {
	this.clearInterval ( t_id );
	ProgressBegin = ProgressX = ProgressW = 0;
	t_id = '';
	document.getElementById('loader_img').style.display = 'block';
	document.getElementById('loader').style.display = 'none';
	}

function HideScin(){	
	document.getElementById('preview').style.display = 'none';
	this.clearInterval ( t_id );
	ProgressBegin = ProgressX = ProgressW = 0;
	t_id = '';
	}

function ShowScin (ScinSmall , Width , Height, event ) {
	event = event || window.event;
	var Path = ''; var Border = 4;
	var Temp1 = ScinSmall.split('/');
	var Temp2 = Temp1[Temp1.length-1].split('.');
	for ( var i = 2; i < Temp1.length-2; i++ ) { Path += Temp1[i] + '/'; }
	var Name = 'http://' + Path + 'preview/' + Temp2[0] + '.' + Temp2[1];
	var Html = '<div style="padding: ' + Border + 'px;"><div id="loader" style="left: ' + parseInt ( (Width - 150) / 2 ) + 'px; top: ' + parseInt ( ( (Height - 25) / 2 ) - 10 ) + 'px;"><div align="center">Загружается изображение...</div><div id="loader_bg"><div id="progress"> </div></div></div>';
	Html += '<div id="loader_img" style="display: none"><img id="' + Temp1[0] + '" onload="javascript:ProgressStop();" alt="" border="0" src="' + Name + '" width="' + Width + '" height="' + Height + '"></div></div>';
	//alert(Name);
	document.getElementById('preview').style.width = Width + Border * 2 + 'px';
	document.getElementById('preview').style.height = Height +  Border * 2 + 'px';
	document.getElementById('preview').innerHTML = Html;
	CoordX = GetPosition(Width , Height, event).x;
	CoordY = GetPosition(Width , Height, event).y;
	document.getElementById('preview').style.left = CoordX + 'px';
	document.getElementById('preview').style.top = CoordY + 'px';
	document.getElementById('preview').style.display = 'block';
	t_id = setInterval ( ProgressAnimate , 20 );
	}
