$(document).ready(function() {


							   
        //инициалищация красивых select Cusel
      /*  var params = {
                changedEl: "#vipusk",
                visRows: 5,
                scrollArrows: true
        }
	
        //блок с дополнительными параметрами поиска
				
        cuSel(params);		*/
				
      /*  var cuselWidth = $('.cus').width();
        $('.vipusk').css('width', cuselWidth +'px').css('max-width','237px');
        $(window).bind("resize", function(){
                var cuselWidth = $('.cus').width();
                $('.vipusk').css('width', cuselWidth +'px').css('max-width','237px');
        })*/


        //cufon смена некрасивых заголовков на красивые
	
        Cufon.replace(['.logo'],{
                fontFamily: 'handbook'
        });
        Cufon.replace(['.myriad, .topic_table_title'],{
                hover:true
        }, {
                fontFamily: 'Myriad Pro'
        });
        $(window).bind("resize", function(){
                imgResise();
                galleryResise();
        })
	
        imgResise();
        galleryResise()

		$('.gallery_preview a:first').addClass('curr');
        $('.gallery_preview a').click(function(){
               // $('#gallery_pic img').hide()
                $('#gallery_pic img').attr('src',$(this).attr('rel')).fadeIn(400);	
				$('.gallery_preview a').removeClass('curr');
				$(this).addClass('curr');				
                return false;
        });
                                
                                
                                
        $('#giant_photo img').each( function(){
                var giantWidth = $('#giant_photo').width();
                $(this).css('max-width', giantWidth + 'px').css('min-width', giantWidth + 'px');
		
        })
        
        $('.menu_list a').click(function(){
                $.cookie('rel', $(this).attr('rel'), {path: '/'});
        });
        
        if ($('.menu_list a.curr').parent().hasClass('menu_body')){
                $('.menu_list a.curr').parent().prev().find('a').addClass('curr');
        }
        
        $('.topic_table_title a').click(function(){
                $.cookie('rel', -1, {path: '/'});
        })

//equalHeight($(".column3 .news_item"));
});//end ready


/*function equalHeight(column) {
    tallest = 0;
    column.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
        tallest = thisHeight;
        }
    });
   column.height(tallest);
}*/


function imgResise(){
	
        var pictureWidth = $('.column .news_item').width();
        $('.column .news_item img').each( function(){
                $(this).css('max-width', pictureWidth + 'px').css('min-width', pictureWidth + 'px')					   
        })
	
        var pictureWidth2 = $('.column2 .news_item').width();
        $('.column2 .news_item img').css('max-width', pictureWidth2 + 'px').css('min-width', pictureWidth2 + 'px')	
	
        var pictureWidth5 = $('.column5 .news_item').width();
        $('.column5 .news_item img').css('max-width', pictureWidth5 + 'px').css('min-width', pictureWidth5 + 'px')	
	
        $('#giant_photo img').each( function(){
                var giantWidth = $('#giant_photo').width();
                //alert(giantWidth);
                $(this).css('max-width', giantWidth + 'px').css('min-width', giantWidth + 'px');
		
        })
	
}

function galleryResise(){
        var pictureblock = $('.gallery_preview').width();
       
        //alert(pictureblock)
        //$('#gallery_pic').css('height', pictureblock*0.8 +'px')
        $('#gallery_pic img').each( function(){
                //$(this).css('max-width', pictureblock -20  + 'px').css('max-height', pictureblock*0.8 + 'px')
                $(this).css('max-width', pictureblock -20  + 'px').css('min-width', pictureblock -20  + 'px');
                $(this).parent('#gallery_pic').height(pictureblock -20+ 'px');
        })
        if(pictureblock > 560){
                $('.gallery_preview div').css('width', '16%')
        }
        if(pictureblock > 400 && pictureblock < 560){
                $('.gallery_preview div').css('width', '20%').css('padding','0');
                        
                        
                        
        }
        if(pictureblock < 400){
                $('.gallery_preview div').css('width', '25%')
        }
//else{$('.gallery_preview div').css('width', '25%')}
                
                
                
/*  var gallery_preview_left = $('.gallery_preview').offset.left;
                alert(gallery_preview_left);
              
                var div_one = $('.gallery_preview div:first-child').offset.left;
                
                alert(div_one)*/
}
$(function(){
        $.fn.scanForm = function(select){
                var test_int = new RegExp('[0-9]+');
                var arr = new Array();
                var error = false;
                $(this).find('input[type=text]').each(function(){
                        if ($(this).attr('name') != ''){
                                if ($(this).hasClass('T-int') && !test_int.test($(this).val()))
                                        error = true;
                                arr.push('"' + $(this).attr('name') + '":"' + $(this).val() + '"');
                        }
                });

                $(this).find('input[type=hidden]').each(function(){
                        arr.push('"' + $(this).attr('name') + '":"' + $(this).val() + '"');
                });

                $(this).find('input[type=radio]').each(function(){
                        if ($(this).attr('checked'))
                                arr.push('"' + $(this).attr('name') + '":"' + $(this).val() + '"');
                });
                $(this).find('select').each(function(){
            
                        if ($(this).attr('name') != '')
                                arr.push('"' + $(this).attr('name') + '":"' + $(this).val() + '"');
                });
                $(this).find('textarea').each(function(){
                        if ($(this).attr('name') != ''){
                                var text = $(this).val();
              
                                arr.push('"' + $(this).attr('name') + '":"' + text.replace(/(\n(\r)?)/g, "\\n") + '"');
                        }
                });
        
                if (error) return false;
                return eval ('({' + arr.join(',') + '})');
        };
});
