﻿function LabelsClean(){
	$('input.form-input').each(function(i){
		var	inputLabel=$(this).val();
		$(this).focus(function(){if ($(this).val() == inputLabel) {$(this).val('')}});
		$(this).blur(function(){if ($(this).val() == '') {$(this).val(inputLabel)}})
	});
};
function menuJustify(el){
	var	liW=0,
			len=el.find('ul:first > li').length;
	blockWidth=el.find('ul:first').width();
	el.find('ul:first > li').each(function(i){liW+=$(this).width()});
	blockMargin=(blockWidth-liW)/(el.find('ul:first > li').length-1);
	blockMargin=Math.floor(blockMargin)+'px';
	el.find('ul:first > li').css('margin-right','0px');
	el.find('ul:first > li').each(function(i){
		if (i<len-1) {$(this).css('margin-right',blockMargin)}
	});
};
function BuildPage() {
	
	var	blockHeight=0,
			blockWidth=0,
			blockMargin=0,
			blockPadding=0,
			j=0,
			len=0;
	LabelsClean();
	
	//menuJustify($('#top-menu'));
	$(".contents img[align*='left']").css('margin-left','0px');
	$(".contents img[align*='right']").css('margin-right','0px');
	$('.anonce-block').each(function(i){
		j=0;
		len=$(this).find('.item').length-1;
		$(this).find('.image:even').addClass('even');
		$(this).find('.item').each(function(k){
			if (j==3 && k<len) {
				$(this).after('<div class="clear">&nbsp;</div>');
				j=-1
			};
			j+=1
		})
	});
			
	$('a.button-block').each(function(i){
		$(this).append('<span class="left"></span>');
		$(this).append('<span class="right"></span>');
	});
	
	$('.scroll-block').each(function(i){
		if ($(this).find('.scroll-1').length>0) {blockHeight=$(this).find('.item:first').height()};
		if ($(this).find('.scroll-2').length>0) {blockHeight=$(this).find('.subitem:first').height()};
		$(this).find('.text').each(function(k){
			blockPadding=(blockHeight-$(this).height())/2;
			if (blockPadding>0) {$(this).css('padding-top',blockPadding+'px')}
		});
		$(this).find('.scrollable:first').scrollable({circular: true})
	});
		
	if ($('#login-block')) {
		
		$('#login-block a[rel]').overlay({
			effect: 'apple',
			expose: '#4f4f4f',
			closeOnClick: false
		});
	};
	blockHeight=$('#footer > .contents:first').height();
	$('#footer').height(blockHeight);
	$('#center').css('padding-bottom',blockHeight+'px');
	$('#footer').hide(0);
	$('#footer').show(0)
};
//Запуск функций построения страницы
$(document).ready(function(){
	BuildPage();
});

