/*
	Zoom image function + flash loader fix
	Copyright (C) Atlant Telecom Web Laboratory, 2006
	Development by Vitaly Novik
*/

function Zoom(xlink, width, height, title, charset){
	
	width = Math.ceil(width);
	height = Math.ceil(height);

	var resizeSW = 0;
	
	if (!(width && height) || (!width || ! height)) { width = 200; height = 200; resizeSW = 1; }
	
	var b_op = (window.navigator.userAgent.indexOf("Opera") != -1) ;
	var b_mie = (!b_op && window.navigator.appName == 'Microsoft Internet Explorer');
	var b_moz = (!b_op && window.navigator.appName != 'Microsoft Internet Explorer');
	
	var loadScript = 'document.getElementById("loadarea").style.display="none";';
			loadScript += 'var iW =document.getElementById("img").offsetWidth; ';
			loadScript += 'var iH =document.getElementById("img").offsetHeight; ';
			loadScript += 'if(iW>=50 && iH>=50){ ';
			
			if (resizeSW) {

				loadScript += 'if (document.getElementById("img") && document.getElementById("image")) { ';
				
				if(b_op){
					loadScript += 'window.resizeTo(iW+window.outerWidth-window.innerWidth, iH+window.outerHeight-window.innerHeight); ';
				} else {
					if(b_moz) {
						loadScript += 'window.resizeTo(iW+window.outerWidth-window.innerWidth+100, iH+window.outerHeight-window.innerHeight+100); ';
						loadScript += 'window.resizeTo(iW+window.outerWidth-window.innerWidth, iH+window.outerHeight-window.innerHeight); ';
					} else {
						loadScript += 'window.resizeTo(iW+100, iH+100); ';
						loadScript += 'var oW =document.getElementById("image").offsetWidth; ';
						loadScript += 'var oH =document.getElementById("image").offsetHeight; ';
						loadScript += 'window.resizeTo(iW+100-oW+iW, iH+100-oH+iH); ';
					}
				}
				loadScript += ' } ';
			}
			
			loadScript += '} else { document.getElementById("image").style.display="none"; } ';
			
	var header = '<!DOCTYPE html PUBLIC ' + '"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
			'<' + 'html>' + '<' + 'head>' +
			'<' + 'meta http-equiv="Content-Type" content="text/html;charset=' +
			(charset?charset:'windows-1251') + '" />' +
			
			(title?'<' + 'title>' + title + '<' + '/title>':'<' + 'title>' + '<' + '/title>') +
			
			'<' + 'style type="text/css">' + '<!-- ' +
			'body,html { width:100%; height:100%; } ' +
			'body { background-color:#FFFFFF; padding:0px; margin:0px; border:0px; } ' +
			'body,td,th,div { font-family:tahoma; font-size:12px; } ' +
			'#image { width:100%; height:100%; display:table; } ' +
			'#loadarea { position:absolute; z-index:1010; width:' + width + 'px; height:' + height + 'px; -moz-opacity:0.85; filter:Alpha(opacity=85); opacity:0.85; background:#FFFFFF; } ' +
			'#loadareatab { width:' + width + 'px; height:' + height + 'px; } ' +
			'#lbar td { font-size:1px; } ' + 
			'#lbar td div { width:5px; height:5px; font-size:1px; border:1px #666666 solid; background-color:#FFFFFF;} ' +
			'#error { width:' + width + 'px; height:' + height + 'px; } ' +
			'#error td { vertical-align:middle; text-align:center; color:#990000; font-size:100px; font-weight:bold; } ' +
			' -->' + '<' + '/style>' +
			
			'<' + '/head>' + '<' + 'body ' + 
			/*'onblur="window.close();" ' +*/
			'onclick="window.close();" ' +
			'onkeydown="window.close();" ' +
			'onkeypress="window.close();" ' +
			'onkeyup="window.close();" ' +
			'onmousedown="window.close();" ' + 
			'onmouseup="window.close();" ' +
			'>';

	var footer = '<' + '/body>' + '<' + '/html>';
	
		var img = window.open('','','width=' + width + ', height=' + height + ', toolbar=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no');

		img.document.open();

			img.document.write(header +
			
								'<' + 'div id="loadarea">' +
								'<' + 'table id="loadareatab" border="0" cellspacing="0" cellpadding="0"><' +'tr>' +
								'<' + 'td style="vertical-align:middle; text-align:center;">' +
								'<' + 'table id="lbar" border="0" cellspacing="6" cellpadding="0" align="center">' +
								'<' + 'tr>' +
									'<' + 'td><' + 'div id="lb1"><' + '/div><' + '/td>'+
									'<' + 'td><' + 'div id="lb2"><' + '/div><' + '/td>'+
									'<' + 'td><' + 'div id="lb3"><' + '/div><' + '/td>'+
									'<' + 'td><' + 'div id="lb4"><' + '/div><' + '/td>'+
									'<' + 'td><' + 'div id="lb5"><' + '/div><' + '/td>'+
								'<' + '/tr><' + '/table>' +
								
								'<' + 'script type="text/javascript"> ' +
								'function doLoad(){' + loadScript + '} ' +
								'window.onload = doLoad; ' +
								
								'function ZoomCLB(oldnum, newnum) { '+
									'document.getElementById("lb" + oldnum).style.backgroundColor = "#FFFFFF"; '+
									'document.getElementById("lb" + newnum).style.backgroundColor = "#000000"; '+
									'if(newnum==5){ZoomCLBTO(1);} else {ZoomCLBTO(newnum+1);} '+
								'} '+
								'function ZoomCLBTO(num){ '+
									'var oldnum; '+
									'var newnum; '+
									'if(num == 1){oldnum = 5; newnum = num;} else {oldnum = num-1; newnum = num;} '+
									'var LB = window.setTimeout("ZoomCLB(" + oldnum + ", " + newnum + ")", 300); '+
								'} ' +

								'<' + '/script>' +
								
								'<' + '/td><' + '/tr><' + '/table><' + '/div>	' +
								'<' + 'div id="image" ' +
								'>' +
								'<img id="img" src="' + xlink + '" alt="" ' +
								'/>' +
								'<' + '/div>' +
									'<' + 'table id="error" cellpadding="0" cellspacing="0" border="0">' + '<' + 'tr>' + '<' + 'td>' +
								'&times;' +
								'<' + '/td>' + '<' + '/tr>' + '<' + '/table>' +
							footer);
								
		img.document.close();
		
		img.ZoomCLBTO(1);
		
		img.focus();

}

function FlashLoad(fname, flocation, fwidth, fheight, fbgcolor, falign, fwmode, fvars, fversion) {
	
	fversion = '' + fversion;
	
	if (fversion) {
		fversionarr = fversion.split(',');
		if(fversionarr.length < 4){
			for (i = fversionarr.length; i < 4; i++ ){
				fversion = fversion + ',0';
			}
		}
	} else {
		fversion = '8,0,0,0';
	}

	document.write		('<object ' +
										'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
										'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + fversion + '" ' +
										'width="' + fwidth + '" ' +
										'height="' + fheight + '" ' +
										(fname?('id="' + fname + '" '):'') +
										(falign?('align="' + falign + '" '):'align="middle"') +
										'>' +
										
										'<param name="allowScriptAccess" value="always" />' +
										'<param name="scale" value="noscale" />' +
										
										'<param name="movie" value="' + flocation + '" />' +
										
										'<param name="quality" value="high" />' +
										
										(fbgcolor?'<param name="bgcolor" value="' + fbgcolor + '" />':'') +
										
										'<param name="wmode" value="' + (fwmode?fwmode:'opaque') + '" />' +
										
										(fvars?'<param name="FlashVars" value="' + fvars + '" />':'') +
										
										'<embed src="' + flocation + '" quality="high" ' +
										'wmode="' + (fwmode?fwmode:'opaque') + '" ' +
										(fbgcolor?'bgcolor="' + fbgcolor + '" ':'') +
										'width="' + fwidth + '" ' +
										'height="' + fheight + '" ' +
										(fname?('name="' + fname + '" '):'') +
										(falign?('align="' + falign + '" '):'align="middle" ') +
										'allowScriptAccess="always" ' +
										'scale="noscale" ' +
										(fvars?'FlashVars="' + fvars + '" ':'') +
										'type="application/x-shockwave-flash" ' +
										'pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
										
										'</' + 'object>');

}

function zooom(id) {
	var h = document.getElementById(id).innerHTML;
	document.getElementById(id).innerHTML = h ? '' : '<a href="javascript:zooom(' + "'" + id + "'" + ')"><img src="' + id + '" border="0" /></a>';
}


function Zoom2(xlink, width, height){
	if (width && height) {
		var img = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=' + height + ',width=' + width);
		if (navigator.userAgent.indexOf("Opera") == -1) {
			img.document.writeln('<html><body bgcolor="#D6D3CE" style="padding: 0px; margin: 0px; border: 0px;"><div id="text" style="width: 100%; height: 100%; text-align: center; padding-top: 40px; font-family: tahoma; font-size: 12px;">Загрузка изображения...</div><div id="image" style="display: none;"><img src="' + xlink + '" alt="" onload="document.getElementById(\'text\').style.display = \'none\'; document.getElementById(\'image\').style.display = \'block\';" /></div></body></html>');
		} else {
			img.document.writeln('<html><body bgcolor="#D6D3CE" style="padding: 0px; margin: 0px; border: 0px;"><div id="image" style="display: block;"><img src="' + xlink + '" alt="" onload="window.resizeTo(this.width+6, this.height+63)" /></div></body></html>');
		}
	} else {
		var img = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=100,width=200');
		if (navigator.userAgent.indexOf("Opera") == -1) {
			img.document.writeln('<html><body bgcolor="#D6D3CE" style="padding: 0px; margin: 0px; border: 0px;"><div id="text" style="width: 100%; height: 100%; text-align: center; padding-top: 40px; font-family: tahoma; font-size: 12px;">Загрузка изображения...</div><div id="image" style="display: none;"><img src="' + xlink + '" alt="" onload="document.getElementById(\'text\').style.display = \'none\'; document.getElementById(\'image\').style.display = \'block\'; window.resizeTo(this.width+6, this.height+63)" /></div></body></html>');
		} else {
			img.document.writeln('<html><body bgcolor="#D6D3CE" style="padding: 0px; margin: 0px; border: 0px;"><div id="image" style="display: block;"><img src="' + xlink + '" alt="" onload="window.resizeTo(this.width+6, this.height+63)" /></div></body></html>');
		}
	}
}
