<br />
<b>Deprecated</b>:  Function eregi() is deprecated in <b>/home/u62106/php_libs/sCMS/lib/HTTP/HTTP.php</b> on line <b>64</b><br />
﻿/**
 * sCMS is a SEO-friendly Content Management System for small projects.
 * sCMS organized as a compact core with supporting module extensibility.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @author		Andrey Khrolenok <limych at users.sourceforge.net>
 * @copyright	Copyright &copy; 2009 by Andrey Khrolenok
 * @license		http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version		$Id: jquery.flyup.js 129 2008-08-13 22:33:31Z limych $
 * @package		sCMS
 */

Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
};

(function($){
	// fucking IE hack for table cells padding
//	$('.content table td').wrapInner("<div class='td'></div>");
//	$('.content table th').wrapInner("<div class='td'></div>");

	// Функция оптимального размещения ячеек таблицы с галлереей на странице
	function optimizeGallery(){
		$('.wiki-gallery').each(function(){
			var table = $(this);
			var max_width = table.parent().width();
			var rows = table.find('tbody:first > tr');
			var cells = rows.find('td');

			if(cells.get(0)._width == undefined){
				// Считаем минимальные ширины ячеек
				var wid = this.style.width;
				this.style.width = 'auto';
				cells.appendTo(rows.get(0)).each(function(){
					this._width = $(this).width();
				});
				this.style.width = wid;
			}

			// Вычисляем, сколько ячеек ставить в строку
loop:
			for(var cells_cnt = cells.length; cells_cnt > 1; cells_cnt--){
				var cell_size = new Array(cells_cnt);
				for(var i = 0; i < cells.length; i++)
					cell_size[i % cells_cnt] = (isNaN(cell_size[i % cells_cnt]) ? cells.get(i)._width : Math.max(cell_size[i % cells_cnt], cells.get(i)._width));
				if(cell_size.sum() > max_width)	continue loop;
				break;
			}

			// Расставляем ячейки по строкам
			for(var i = Math.ceil(cells.length / cells_cnt); i >= 1; i--){
				cells.slice(0, cells_cnt).appendTo(rows.get(0));

				if(rows.length > 1){
					rows = rows.slice(1);
				}else{
					rows = rows.clone().empty().insertAfter(rows);
				}
				cells = cells.slice(cells_cnt);
			}
			rows.slice(1).remove();
		});
	}

	$(function(){
		$('.wiki-image-thumb').flyup({
			loadingText	: 'Загрузка изображения...'
		});
		optimizeGallery();
		$(window).resize(optimizeGallery);
	});
})(jQuery);
