
/*
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( this.parent().height() - this.height() ) / 2 + "px");
	this.addClass(this.height() + "_" + this.parent().height());
    //this.css("left", ( jQuery(this).parents('comm-foto-block').width() - this.outerWidth() ) / 2+jQuery(this).parents('comm-foto-block').scrollLeft() + "px");
    return this;
}*/

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	//var mh = ($(this).parent().height()-$(this).height()) / 2;
	//$(this).css('top', mh);
	var mw = ($(this).parent().width()-$(this).width()) / 2;
	$(this).css('left', mw);
	$(this).parent().find('a').css('padding-left', mw);
	
	});
};
})(jQuery);


function form_live(e)
{
    
    e.preventDefault();
    var formserialized = jQuery(this).serializeArray();
    var formdata = {};
    jQuery.each(formserialized, 
        function (i,n) 
        {
            formdata[n.name] = n.value;
        } 
    );
    var target = jQuery(this).attr("target");
    var action = jQuery(this).attr("action");
    jQuery("#"+target).html("обработка...");
    jQuery("#"+target).load(action, formdata);
}


jQuery(function( $ ){

    $(document).ready(
        function()
        {
            $("form.live").bind("submit", form_live);
        }
    );

	
	$(".img_showbig_item").hide();
	
	$(window).load(function() { 
			
		
			$('.comm-fotos-block').each(function () {
						
				var inline = Math.floor($(this).width()/207);
				var i = 0;
				var j = 0;
				var count = 0;
				var tallest = 0;
				
				
				$(this).find('.comm-foto-block').each(function () {
					var imgnum = $(this).parent().find('.comm-foto-block').length;
					var currline = 'comm-foto'+j;
					$(this).addClass(currline);
					$(this).addClass('comm-foto-row' + count);
					
					var thisHeight = $(this).children('.img_showbig_item').attr("height");
					if(thisHeight > tallest) {
						tallest = thisHeight;
					}
					
					
					
					
					i++;
					count++;
					if ((i%inline == 0) || (i == imgnum)) {
						var tallestpx = tallest + 'px';
						
						if ($(this).parents('.rules').length == 0)
							$(this).parent().find('.comm-foto'+j).css("min-height" , tallest + "px")/*.css({"height": tallest})*/;
						
						j++;
						count = 0;
						tallest = 0;
					}
					//if ($.browser.webkit) {$('.comm-foto-block').css("min-height", "200px !important")}
					
					
					
				});
			
				//$(this).width();
				$(this).find('.img_showbig_item').vAlign().show();	
			});
		
	});
	

});

