$(document).ready(function(){

	$("#otziv a").fancybox();
	$('.left_cont a').fancybox();

	$.validity.setup({outputMode:"summary"});
    
	$('#feedback_form').live('submit',function(){

		$.validity.start();
        
		$("#fb_name").require("Укажите Имя;")
		$("#fb_surn").require("Укажите Фамилию;")
		$("#fb_org").require("Укажите Организацию;")
		$("#fb_post").require("Укажите Должность;")
	        $("#fb_mail").require("Укажите E-mail;").match("email", "Введите корректный E-mail;");
		$("#fb_mes").require("Введите текст Сообщения;")
		$("#fb_capt").require("Введите код с картинки;")
        
		var result = $.validity.end(); 

		if (!result.valid) 
		{ 
			$.fancybox($("#feedb_error").html());
			return false;
		} 
		
		var error = '0';
		$.ajax({
			type	: "POST",
			cache	: false,
			async	: false,
			url	: '/captcha.php',
			data	: 'su_captcha='+$('#fb_capt').val()+'&su_captcha_code='+$('#fb_cpt_code').val(),
			success : function(data)
			{
				if(data == 'error')
				{
					error = '1';
					$('.validity-summary-container ul').html('<li>Код картинки не совпадает с введенным;</li>');
					$(".validity-summary-container").show();				
					$.fancybox($("#feedb_error").html());
					return false;
				}
				$.validity.clear();
			}
		});

		if(error == '1')
		{
			return false;
		}

	});
    
	//Фикс высоты
	function fixHeight(){
		//Каталог
		$("#floats").css('height', 'auto');
		
		dWidth = $("#floats").width();
		elemWidth = 240;
		visible = Math.floor(dWidth / elemWidth) - 1;
		$("#floats div").each(function(e){
			$(this).show();
			if(e > visible){
				$(this).hide();
			}
		});
		
		//Новости
		$("#news").css('height', 'auto');
		
		dWidth = $("#news").width() - 260;
		elemWidth = 240;
		visible = Math.floor(dWidth / elemWidth) - 1;
		$("#news div.newsElem").each(function(e){
			$(this).show();
			if(e > visible){
				$(this).hide();
			}
		});
		$(".novosti_chitaite_takje").css('height', 'auto');
		
		dWidth = $(".novosti_chitaite_takje").width() - 170;
		elemWidth = 240;
		visible = Math.floor(dWidth / elemWidth) - 1;
		$(".novosti_chitaite_takje div.newsElem").each(function(e){
			$(this).show();
			if(e > visible){
				$(this).hide();
			}
		});
		//Галерея
		$("#gallery").css('height', 'auto');
		
		dWidth = $("#gallery").width() - 260;
		elemWidth = 161;
		visible = Math.floor(dWidth / elemWidth) - 1;
		$("#gallery div.galleryElem").each(function(e){
			$(this).show();
			if(e > visible){
				$(this).hide();
			}
		});
		
		
	}
	
	fixHeight();
	$(window).resize(function(){
		fixHeight();
	});
		
	if(document.getElementById('main_page_gradient'))
	{
		$('#content h1, #content h2, #heading span').gradientText({
        	colors: ['#d60000', '#1b69ca']
	    });
	}
	
	
	$("#topmask-up").after('<div id="topmaskBig"></div>');
	html = '';
	$("#topmask img").each(function(){
		html += '<div><img src="' + $(this).attr('src') + '" alt=""></a></div>';
	});
	$("#topmaskBig").html(html);
	
	$("#rightmask-up").after('<div id="rightmaskBig"></div>');
	html = '';
	$("#rightmask img").each(function(){
		html += '<div><img src="' + $(this).attr('src') + '" alt=""></a></div>';
	});
	$("#rightmaskBig").html(html);
	
	$("#topmaskBig div").mouseover(function(){
		if($(this).index() != 7 && $(this).index() != 11 && $(this).index() != 15){
			$(this).addClass('hover');
			$("#topmaskBig, #rightmaskBig").css('z-index', '10');
		}
	});
	$("#topmaskBig div").mouseleave(function(){
		$(this).removeClass('hover');
		$("#topmaskBig, #rightmaskBig").css('z-index', '1');
	});
	
	$("#rightmaskBig div").mouseover(function(){
		if($(this).index() != 0 && $(this).index() != 1 && $(this).index() != 3 && $(this).index() != 9){
			$(this).addClass('hover');
			$("#topmaskBig, #rightmaskBig").css('z-index', '10');
		}
	});
	$("#rightmaskBig div").mouseleave(function(){
		$(this).removeClass('hover');
		$("#topmaskBig, #rightmaskBig").css('z-index', '1');
	});

	$("a[rel=fancybox]").fancybox();
});

function filtr()
{
    var god = document.getElementById("god");
    var god_value = "";
    if(god)
    {
        for(var i= 0; i <= god.length; i++)
        {
            if(god[i].selected)
            {
                god_value = god[i].value;
                break;
            }
        }
    }

    var company=document.getElementById("company").value;
    if(company!='') company="?n_f_temp_id=4&n_f_13="+company;
    var mes = document.getElementById("mes");
    var mes_value = "0";
    if(mes)
    {
        for(var i= 0; i <= mes.length; i++)
        {
            if(mes[i].selected)
            {
                mes_value = mes[i].value;
                break;
            }
        }
    }

	if(god_value!=''){
		god_value="y"+god_value+"/";
	}
	else{
		if(mes_value!="") god_value="y"+new Date().getFullYear()+"/";
	}
	
	if(company!='')
	{
   		 if(mes_value == 0)
		    {
		        window.location.href = "/news/"+god_value+company;
		    }
		    else
		    {
		        window.location.href = "/news/"+god_value+mes_value+"/"+company;
		    }
		}
	else
	{
		 if(mes_value == 0)
		    {
		        window.location.href = "/news/"+god_value;
		    }
		    else
		    {
		        window.location.href = "/news/"+god_value+mes_value+"/";
		    }
	}



}

function filtr_doc(){
if(document.forma.n_f_13.value=="")
	{
		parent.location="?n_f_temp_id=4";
	}
	else
	{
		parent.location="?n_f_temp_id=4&n_f_13="+document.forma.n_f_13.value;
	}
}

function filtr_otziv()
{
	var company=document.forma.im_f_2.value;
	if(company=='')
	{
		parent.location="/clients_comments/";
	}
	else
	{
		parent.location="/clients_comments/?im_f_temp_id=1&im_f_2="+company;
	}
	
}
function perehod(){
var stepen="";
var zakazchik="";
var ispolnitel="";
var data="";

if(document.forma.p_f_1_49.value !="")
    zakazchik= (stepen != '' ? '&' : '')+"p_f_1_49="+document.forma.p_f_1_49.value;

var els = document.getElementById("p_f_1_45");
if(els)
{  
    for(var i = 0; i < els.length; i++)
    {
        if(els[i].selected && els[i].value !="")
        {
            ispolnitel = ispolnitel+'&p_f_1_45[]='+els[i].value;
        }
    }
}    

if(document.forma.p_f_1_47.value !="")
    data = (stepen != ''  || zakazchik != '' || ispolnitel !="" ? '&' : '')+"p_f_1_47_lo=01.01."+document.forma.p_f_1_47.value+"&p_f_1_47_hi=01.01."+(document.forma.p_f_1_47.value*1+1);
if(document.forma.stepen.value !="" )
{
    stepen=document.forma.stepen.value+"/?";
}
else
{
    stepen="?";
}

if(document.forma.stepen.value=="" && document.forma.p_f_1_49.value=="" && document.forma.p_f_1_45.value=="" && document.forma.p_f_1_47.value=="") stepen="";
if(document.forma.stepen.value!="" && document.forma.p_f_1_49.value=="" && document.forma.p_f_1_45.value=="" && document.forma.p_f_1_47.value=="") {stepen=document.forma.stepen.value+"/";}
if (zakazchik=="") ispolnitel = ispolnitel.substr(1);
parent.location="/objects/"+stepen+zakazchik+ispolnitel+data;
}

