function writeAlbum(album, albumCount, align, root)
{
	document.write('<table cellpading="0" cellspacing="0" border="0" width="100%">');
  document.write('  <tr>');
  document.write('    <td align="center">');

	for (i = 0; i < albumCount; i++)
	{
		showPopupImage(root + album[i] + '-thmb.jpg', root + album[i] + '.jpg', 140, 105, align)
		
		if ((i+1)%3 == 0)
		{
			document.write('    </td>');
			document.write('  </tr>');
			document.write('  <tr>');
			document.write('    <td align="center">');
		}
	}
  document.write('    </td>');
  document.write('  </tr>');
  document.write('</table>');
}

function writeProductAlbum(album, albumCount, imagesPerLine, albumName, albumId, albumHeight, size, albumName2, showLabels)
{
	if (size == null)
	{
		size = 'normal';
	}
	
	// 'normal' sizes
	var hspace = 10;
	var vspace = 10;
	var width  = 140;
	var height = 105;
	var cellwidth = 170;
	
	if (size == 'small')
	{
		// 'small' sizes
		hspace = 10;
		vspace = 5;
		width  = 120;
		height = 90;
	  cellwidth = 170;
	}
	
	var name = albumName;
	
	if (albumName2 != null)
	{
		name = name + '&nbsp;&amp;&nbsp;' + albumName2;
	}
	
	document.write('<table cellpading="0" cellspacing="0" border="0">');
  document.write('  <tr>');
  document.write('    <td class="tab-nowidth" nowrap="nowrap">&nbsp;'+ name + '&nbsp;</td>');
  document.write('  </tr>');
  document.write('</table>');
	document.write('<div class="album" id="' + albumId + '">');
	document.write('<table cellpading="0" cellspacing="0" border="0" width="100%">');

  for (j = 0; j < Math.ceil(albumCount/imagesPerLine); j++)
	{
    document.write('  <tr>');
    document.write('    <td align="center">');
		document.write('      <table cellpading="0" cellspacing="0" border="0">');
		document.write('        <tr>');
	
		for (i = 0; i < imagesPerLine; i++)
		{
			var idx = j*imagesPerLine + i;
			var line = "";
		  
			document.write('    <td align="center" width="' + cellwidth + '">');
			
			if (idx < albumCount)
			{
				line = '<a href="' + album[idx].page + '"';
				
				if (album[idx].target != null)
				{
					line = line + ' target = "' + album[idx].target + '"';
				}
				
				line = line + '>';
				
				line = line + '<img align="center" border="1" hspace="' + hspace + '" src="' + album[idx].image + '" vspace="' + vspace + '" class="clickable-out" width="' + width + '" height="' + height + '" onMouseOut="this.className=\'clickable-out\'" onMouseOver="this.className=\'clickable-over\'"/>';
			
				if ((album[idx].target != null))
				{
					line = line + '</a>';
				}
			}
			else
			{
				line = "&nbsp;";
			}
			
			document.write(line);
			
			document.write('    </td>');
		}

		document.write('  </tr>');

		var showNames = true;
		
		if (showLabels == 'false')
		{
			showNames = false;
		}

    if (showNames == true)
		{
			document.write('  <tr>');
			
			for (i = 0; i < imagesPerLine; i++)
			{
				var idx = j*imagesPerLine + i;
	
				if (idx < albumCount)
				{
					line = '<a href="' + album[idx].page + '"';
					
					if (album[idx].target != null)
					{
						line = line + ' target = "' + album[idx].target + '"';
					}
					
					line = line + ' class="product-name">';
					
					line = line + album[idx].name;
				
					if ((album[idx].target != null))
					{
						line = line + '</a>';
					}
				}
				else
				{
					line = "&nbsp;";
				}
				
				document.write('<td align="center" class="product-name">' + line + '</td>');
			}
			
			document.write('  </tr>');
		}

    document.write('</table>');
	}

  document.write('    </td>');
  document.write('  </tr>');
  document.write('</table>');
	document.write('</div>');
	
	eval(albumId + '.style.height=' + albumHeight + ';');
}

function showInlineImage(image, width, height, align)
{
  document.write('<img align="' + align + '" border="1" hspace="10" src="' + image + '" vspace="10" class="clickable-out" width="' + width + '" height="' + height + '"/>');
}

function showPopupImage(image_thmb, image, width, height, align)
{
  document.write('<a href="javascript:openImage(\''+image+'\')"><img align="' + align + '" border="1" hspace="10" src="' + image_thmb + '" vspace="10" class="clickable-out" width="' + width + '" height="' + height + '" onMouseOut="this.className=\'clickable-out\'" onMouseOver="this.className=\'clickable-over\'"/></a>');
}

var DEFAULT_WIDTH  = 800;
var DEFAULT_HEIGHT = 800;
			
function openImage(img, width, height, winname) 
{
	if (width == null)
		width = DEFAULT_WIDTH;
	  		
  	if (height == null)
  		height = DEFAULT_HEIGHT;

    if (winname == null)
  		winname = 'imageWin';
			  		
	openwin = this.open(img, winname, 'width=' + width + ',height=' + height + 
                            ',status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,scroll=auto');
	openwin.focus();
}

function Product(pName, pImage, pPage, pTarget)
{
	this.image  = pImage;
	this.page   = pPage;
	this.name   = pName;
	this.target = pTarget;
}

function ArticleInfo(aName, aModel, aWeight, aDim, aModelName)
{
	this.name     = aName;
	this.model    = aModel;
	this.features = new Array();
	this.weight   = aWeight;
	this.dim      = aDim;
	this.modelName = aModelName;
}

function showArticles(articles)
{
	document.write('<table width="100%" border="1" bordercolor="#FFFFFF">');
	var descClassAlt       = 'class="description-alt"';
	var descClassAltCenter = 'class="description-alt-center"';
	var alt = true;
	var cls;
	var clsCenter;
	
	for (i in articles)
	{
		if (alt)
		{
		  cls       = descClassAlt;
			clsCenter = descClassAltCenter;
		}
		else
		{
		  cls       = '';
			clsCenter = '';
		}
		
		document.write(' <tr>');
		document.write('   <td>');
		document.write(' 	   <table width="100%">');
		document.write('		   <tr>');
		document.write('			   <td width="170" ' + clsCenter + '><script>showPopupImage("../../../images/products/' + articles[i].model + '/' + articles[i].model + '-0-thmb.jpg", "../../../images/products/' + articles[i].model + '/' + articles[i].model + '-0.jpg", 140, 105, "center");</script></td>');
		document.write('				 <td ' + cls + '>');

    if (articles[i].modelName == null)
		{
		  document.write('					 <h1 class="smalltop"><a name="' + articles[i].model + '">' + articles[i].name + ', модел #' + articles[i].model + '</a></h1>');
		}
		else
		{
		  document.write('					 <h1 class="smalltop"><a name="' + articles[i].model + '">' + articles[i].name + ', модел ' + articles[i].modelName + '</a></h1>');
		}

    document.write('			 		 <ul class="feature-nopt">');
		for (j in articles[i].features)
		{
		  document.write('			  	 <li>' + articles[i].features[j] + '</li>');
		}
		document.write('					 </ul>');
		document.write('					 <p class="normal">');
		document.write('					   Тегло на уреда: ' + articles[i].weight + ' кг<br/>');
		document.write('             Размери: ' + articles[i].dim);
		document.write('			 		 </p>');
		document.write('				 </td>');
		document.write('			 </tr>');
		document.write('		 </table>');
		document.write('	 </td>');
		document.write(' </tr>');
		
		alt = !alt;
	}
	document.write('</table>');
}
