$(window).load(function() 
{
    $('#QapTcha').QapTcha({disabledSubmit:true});
    
    var $matchcontacts = [];
    $matchcontacts[0] = 'tell';
    $matchcontacts[1] = 'mail';
    $matchcontacts[2] = 'vk';
    $matchcontacts[3] = 'fb';
    $matchcontacts[4] = 'tw';
    $matchcontacts[5] = 'skype';
    $matchcontacts[6] = 'isq';
    
    function signup_help_clear(){
        $('#signup-help span').removeClass('active');
        $('.wrap').css({'z-index':'auto','position':'inherit'});
        $('.modal').css({'z-index':'100500'});
        $('.alert-help').hide();      
    }
    
    $('#signup-help span').click(function(){
    if($(this).hasClass('active')){
        $(this).removeClass('active');
        signup_help_clear();
    }else{
        $(this).addClass('active');
        $('#email').focus();
        $('.wrap').css({'z-index':'-1','position':'relative'});
        $('.modal').css({'z-index':'auto'}); 
        $('.begin-signup-form ').css({'z-index':'100500','position':'relative'});
        $('.alert-help').show(); 
    }
    });

    $('.dropdown').click(function(){
    if($(this).hasClass('open')){
        $(this).removeClass('open');
        $(this).find('.dropdown-toggle').removeClass('active')        
    }else{
        $(this).addClass('open');
        $(this).find('.dropdown-toggle').addClass('active')
    }
    });

    $('div.icon.match').live('click', function(event){
        if($(this).hasClass('active'))
        $(this).removeClass('active');
        else
        $(this).addClass('active');
    });        

     if($('.switch-btn.gender').hasClass('girl-active') === false){
        $('.switch-btn.gender').find('.switch-active').animate({left: '50'});
        $('#isearch').html('мужской');
        $('#male').show().addClass('active');
        $('#famale').hide().removeClass('active');
        $('.switch-btn.gender').removeClass('girl-active');        
     }
    
    $('.switch-btn.gender').click(function() {
     if($('.switch-btn.gender').hasClass('girl-active')){
        $(this).find('.switch-active').animate({left: '50'});
        $('#isearch').html('мужской');
        $('#male').show().addClass('active');
        $('#famale').hide().removeClass('active');
        $('.switch-btn.gender').removeClass('girl-active');
     }
     else{
        $(this).find('.switch-active').animate({left: '0'});
        $('#isearch').html('женский');
        $('#male').hide().removeClass('active');
        $('#famale').show().addClass('active');
        $('.switch-btn.gender').addClass('girl-active');
    }
    });
    
    
    $( "#slider" ).slider({
			range: true,
			min: 16,
			max: 80,
			values: [ $("#filter-age-min").html(), $("#filter-age-max").html() ],
			slide: function( event, ui ) {
				$("#filter-age-min").html(ui.values[ 0 ]);
                $("#filter-age-max").html(ui.values[ 1 ]);
			},
            stop: function(event, ui) {
                minage = parseInt(ui.values[0]);
                maxage = parseInt(ui.values[1]);
                
                slider_age_ajax(minage,maxage);  
                users_age_filter(minage,maxage); 
            }
    });
    
    
    $("#filter-age-min").html($( "#slider" ).slider( "values", 0 ));
	$("#filter-age-max").html($( "#slider" ).slider( "values", 1 ));
	
    users_age_filter($("#filter-age-min").html(),$("#filter-age-max").html()); 
    	
    $('.check-btn.gender a').click(function(){
    if($(this).hasClass('active') === false){
        gender = $(this).attr('data-container');
        
        if($('.check-btn.gender a.m').hasClass('active') || $('.check-btn.gender a.f').hasClass('active')){
            gender = 'MF';    
        }
        
        search_gender_ajax(gender);
    }else{
        if($(this).next().hasClass('active')){
            gender = $(this).next().attr('data-container');
            search_gender_ajax(gender);   
        }
        
        if($(this).prev().hasClass('active')){
            gender = $(this).prev().attr('data-container');
            search_gender_ajax(gender);   
        }         
    }     
    });
    
    if($('.check-btn.gender a.m').hasClass('active') === false){
        $content = $('.M');
        $content.removeClass('active').hide();
    }
    
    if($('.check-btn.gender a.f').hasClass('active') === false){
        $content = $('.F');
        $content.removeClass('active').hide();
    }
        
    $('.inp').focus(function(){
        $defval = $(this).attr('title');
        $val = $(this).val();
        if($val==$defval)
        $(this).val('');    
    });
    
    
    $('.inp').blur(function(){
        $defval = $(this).attr('title');
        $val = $(this).val();
        if($val=='')
        $(this).val($defval);    
    });
    

    $('.bottom-bar').hover(function(){
        $('.search-age').fadeIn();
        $('.search-text').fadeIn();
    },function(){
        $('.search-age').fadeOut();
        $('.search-text').fadeOut();    
    });

    $('.signin-form-show').click(function(){
        $('.modal-close').click();
        $('.signup-form').click();
        return false;
    });
    
    $('.modal-close').click(function(){
        signup_help_clear()
        $('.modal').fadeOut();  
        $('.overlay').fadeOut();
        
        if($(this).hasClass('date-form')==true){
            $('.begin-date-form').hide();
            $('.user-profile img').attr('src','0');
            $(this).removeClass('date-form');
            $('.contact .icon').removeClass('active');
        }
        
        if($(this).hasClass('gallery-form')==true){
            $('.begin-gallery-form').hide();
            $('.user-image img').attr('src','0');
            $(this).removeClass('gallery-form');
            $('.contact .icon').removeClass('active');
        }
        
        if($(this).hasClass('signup-form')==true){
            $('.begin-signup-form').hide();
            $('.modal-close').removeClass('signup-form');
        }
        
        if($(this).hasClass('feedback-form')==true){
            $('.begin-feedback-form').hide();
            $('.modal-close').removeClass('feedback-form');
        }

        if($(this).hasClass('abaut-form')==true){
            $('.begin-abaut-form').hide();
            $('.modal-close').removeClass('abaut-form');
        } 
        
        if($(this).hasClass('promo-form')==true){
            $('.begin-promo-form').hide();
            $('.modal-close').removeClass('promo-form');
        }         

        if($(this).hasClass('image-caption-form')==true){
            $('.begin-image-caption-form').hide();
            $('.modal-close').removeClass('image-caption-form');
        }

        if($(this).hasClass('social-auth-form')==true){
            $('.begin-social-auth-form').hide();
            $('.modal-close').removeClass('social-auth-form');
        }
        
        if($(this).hasClass('contact-form')==true){
            $('.begin-contact-form').hide();
            $('.modal-close').removeClass('contact-form');
            $('.contact .icon').removeClass('active');
        }

        return false;    
    });


    $('.show-modal').live('click', function(event){
        $('.modal').fadeIn();  
        $('.overlay').fadeIn();
        
        if($(this).hasClass('date-form')==true){
            $('.user-profile').hide();
            $('.image-loader').show();
            
            $title = $('.users-prev li.active:first').attr('data-user-name')+', '+$('.users-prev li.active:first').attr('data-user-age');
            $userID = $('.users-prev li.active:first').attr('data-user-id');
            $image = $('.users-prev li.active:first').attr('data-user-image');
        
            for($i=0;$i<=$matchcontacts.length;$i++){
            if($('.users-prev li.active:first').attr('data-contact-'+$matchcontacts[$i])==='2')
            $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
            if($('.users-prev li.active:first').attr('data-contact-'+$matchcontacts[$i])==='1')  
            $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
            if($('.users-prev li.active:first').attr('data-contact-'+$matchcontacts[$i])==='0')  
            $('.contact .'+$matchcontacts[$i]).hide();
            }   
        
            $('.user-profile img').attr('src',$image);
            $('.user-profile a').attr('href','/user/'+$userID);
            $('.user-profile').attr('data-user-id',$userID);
            $('.user-profile').attr('data-image-index',0);
            $('.add-interesting').attr('data-user-name',$('.users-prev li.active:first').attr('data-user-name'));
            $('.add-interesting').attr('data-user-id',$userID);
            $('.begin-date-form').show();
            $('.modal-close').addClass('date-form');
            imagedynamicresize($('.user-profile'));
        }
        
        if($(this).hasClass('signup-form')==true){
            $title = $(this).attr('data-title');
            $('.begin-signup-form').show();
            $('.modal-close').addClass('signup-form');
        }
        
        if($(this).hasClass('social-auth-form')==true){
            $title = $(this).attr('data-title');
            $('.begin-social-auth-form').show();
            $('.modal-close').addClass('social-auth-form');
        }
        
        if($(this).hasClass('feedback-form')==true){
            $title = $(this).attr('data-title');
            $('.begin-feedback-form').show();
            $('.modal-close').addClass('feedback-form');

        }
        
        if($(this).hasClass('abaut-form')==true){
            $title = $(this).attr('data-title');
            $('.begin-abaut-form').show();
            $('.modal-close').addClass('abaut-form');

        }
        
        if($(this).hasClass('promo-form')==true){
            $title = $(this).attr('data-title');
            $('.begin-promo-form').show();
            $('.modal-close').addClass('promo-form');

        }
        
        if($(this).hasClass('image-caption-form')==true){
            $title = $(this).attr('data-title');
            $imageID = $(this).attr('data-image-id');
            
            $('.begin-image-caption-form').show();
            $('.modal-close').addClass('image-caption-form');
            $('#image-caption-send').attr('data-image-id',$imageID);
        }
        
        if($(this).hasClass('user-form')==true){
            $('.user-profile').hide();
            $('.image-loader').show();
            $('.modal-close').addClass('date-form');
            $thisID = parseInt($(this).attr('data-user-id'));
            $image = $(this).attr('data-user-image');
            $index = $(this).index('.user-form.active');
           
            $title = $(this).attr('data-user-name');

            if($(this).attr('data-user-age') !=='')  
            $title += ', возраст: '+$(this).attr('data-user-age'); 
            
            if($(this).attr('data-user-city') !=='')  
            $title += ', город: '+$(this).attr('data-user-city'); 
             
            if($(this).attr('data-user-height') !=='')  
            $title += ', рост: '+$(this).attr('data-user-height'); 
             
            if($(this).attr('data-user-weight') !=='')  
            $title += ', вес: '+$(this).attr('data-user-weight');
            
            if($(this).attr('data-user-zodiac') !=='')  
            $title += '<div class="icon-inline icon-zodiac '+$(this).attr('data-user-zodiac')+'" title="'+$(this).attr('data-user-zodiac-name')+'"></div>';    
        
            for($i=0;$i<=$matchcontacts.length;$i++){
            if($(this).attr('data-contact-'+$matchcontacts[$i])==='2')
            $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
            if($(this).attr('data-contact-'+$matchcontacts[$i])==='1')  
            $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
            if($(this).attr('data-contact-'+$matchcontacts[$i])==='0')  
            $('.contact .'+$matchcontacts[$i]).hide();
            }
        
            $('.user-profile img').attr('src',$image);
            $('.user-profile a').attr('href','/user/'+$thisID);
            $('.user-profile').attr('data-user-id',$thisID);
            $('.user-profile').attr('data-image-index',$index);
            $('.user-profile').attr('data-user-name',$(this).attr('data-user-name'));
            $('.add-interesting').attr('data-user-name',$(this).attr('data-user-name'));
            $('.add-interesting').attr('data-user-id',$thisID);
            $('.begin-date-form').show();
            imagedynamicresize($('.user-profile'));
        }
        
        if($(this).hasClass('user-gallery')==true){
            $('.user-image').hide();
            $('.image-loader').show();
        
            $('.modal-close').addClass('gallery-form');
            $title = $(this).attr('data-title');
            $image = $(this).attr('data-image');  
            $index = $(this).index('.user-gallery');

            for($i=0;$i<=$matchcontacts.length;$i++){
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='2')
            $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='1')  
            $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='0')  
            $('.contact .'+$matchcontacts[$i]).hide();
        }

            $('.user-image img').attr('src',$image);
            $('.user-image').attr('data-image-index',$index);
            $('.begin-gallery-form').show();
            imagedynamicresize($('.user-image'));
        }
        
        if($(this).hasClass('contact-form')==true){
            $('.user-image').hide();
            $('.image-loader').show();
        
            $title = $('.user-info').attr('data-title');
            $image = $(this).attr('data-image');  
        
            for($i=0;$i<=$matchcontacts.length;$i++){
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='2')
            $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='1')  
            $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
            if($('.user-info').attr('data-contact-'+$matchcontacts[$i])==='0')  
            $('.contact .'+$matchcontacts[$i]).hide();
            }
            
            $('.user-profile img').attr('src',$image);
            $('.begin-contact-form').show();
            $('.modal-close').addClass('contact-form');
            imagedynamicresize($('.begin-contact-form .user-profile'));
        }
        
        $('.modal .modal-header h3').html($title);
    });
    
    
    $('.begin-date-form .next').click(function(){
        $('.user-profile').hide();
        $('.image-loader').show();
        $index = parseInt($('.begin-date-form .user-profile').attr('data-image-index')) + 1;
        $userID = parseInt($('.users-prev li.active:eq('+$index+')').attr('data-user-id'));
        
        if($index >= parseInt($('.users-prev li.active').size())){
            $userID = parseInt($('.users-prev li.active:first').attr('data-user-id'));
            $index = parseInt($('.users-prev li.active:first').index('.users-prev li.active'));
        }
        
        $user_info = $('.users-prev li.active:eq('+$index+')');
        $title = $user_info.attr('data-user-name');

        if($user_info.attr('data-user-age') !=='')  
        $title += ', возраст: '+$user_info.attr('data-user-age'); 
           
        if($user_info.attr('data-user-city') !=='')  
        $title += ', город: '+$user_info.attr('data-user-city'); 
             
        if($user_info.attr('data-user-height') !=='')  
        $title += ', рост: '+$user_info.attr('data-user-height'); 
             
        if($user_info.attr('data-user-weight') !=='')  
        $title += ', вес: '+$user_info.attr('data-user-weight');
        
        if($user_info.attr('data-user-zodiac') !=='')  
        $title += '<div class="icon-inline icon-zodiac '+$user_info.attr('data-user-zodiac')+'" title="'+$user_info.attr('data-user-zodiac-name')+'"></div>'; 

        $image = $('.users-prev li.active:eq('+$index+')').attr('data-user-image');
        
        for($i=0;$i<=$matchcontacts.length;$i++){
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='2')
        $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='1')  
        $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='0')  
        $('.contact .'+$matchcontacts[$i]).hide();
        }        
        
        $('.user-profile img').attr('src',$image);
        $('.user-profile a').attr('href','/user/'+$userID);
        $('.user-profile').attr('data-user-id',$userID);
        $('.user-profile').attr('data-image-index',$index);
        $('.user-profile').attr('data-user-name',$('.users-prev li.active:eq('+$index+')').attr('data-user-name'));
        $('.add-interesting').attr('data-user-name',$('.users-prev li.active:eq('+$index+')').attr('data-user-name'));
        $('.add-interesting').attr('data-user-id',$userID);
        $('.modal .modal-header h3').html($title);
    });
    
    
    $('.begin-date-form .prev').click(function(){
        $('.user-profile').hide();
        $('.image-loader').show();
        $index = parseInt($('.begin-date-form .user-profile').attr('data-image-index')) - 1;
        $userID = parseInt($('.users-prev li.active:eq('+$index+')').attr('data-user-id'));
    
        if($index < 0){
            $userID = parseInt($('.users-prev li.active:last').attr('data-user-id'));
            $index = parseInt($('.users-prev li.active:last').index('.users-prev li.active'));
        }
        
        $user_info = $('.users-prev li.active:eq('+$index+')');
        $title = $user_info.attr('data-user-name');

        if($user_info.attr('data-user-age') !=='')  
        $title += ', возраст: '+$user_info.attr('data-user-age'); 
           
        if($user_info.attr('data-user-city') !=='')  
        $title += ', город: '+$user_info.attr('data-user-city'); 
             
        if($user_info.attr('data-user-height') !=='')  
        $title += ', рост: '+$user_info.attr('data-user-height'); 
             
        if($user_info.attr('data-user-weight') !=='')  
        $title += ', вес: '+$user_info.attr('data-user-weight');  
        
        if($user_info.attr('data-user-zodiac') !=='')  
        $title += '<div class="icon-inline icon-zodiac '+$user_info.attr('data-user-zodiac')+'" title="'+$user_info.attr('data-user-zodiac-name')+'"></div>'; 
        
        $image = $('.users-prev li.active:eq('+$index+')').attr('data-user-image');
        
        for($i=0;$i<=$matchcontacts.length;$i++){
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='2')
        $('.contact .'+$matchcontacts[$i]).show().addClass('match');
        
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='1')  
        $('.contact .'+$matchcontacts[$i]).show().addClass('notmatch');
        
        if($('.users-prev li.active:eq('+$index+')').attr('data-contact-'+$matchcontacts[$i])==='0')  
        $('.contact .'+$matchcontacts[$i]).hide();
        }    
         
        $('.user-profile img').attr('src',$image);
        $('.user-profile a').attr('href','/user/'+$userID);
        $('.user-profile').attr('data-user-id',$userID);
        $('.user-profile').attr('data-image-index',$index);
        $('.user-profile').attr('data-user-name',$('.users-prev li.active:eq('+$index+')').attr('data-user-name'));
        $('.add-interesting').attr('data-user-name',$('.users-prev li.active:eq('+$index+')').attr('data-user-name'));
        $('.add-interesting').attr('data-user-id',$userID);
        $('.modal .modal-header h3').html($title);

    });
    
    
    $('.user-profile').hover(function(){
        $('.user-profile a p').fadeIn();
        $('.user-profile .contact').fadeIn();
        $('.user-profile .user-action').fadeIn();
        $('.user-profile .alert-inline').fadeIn();
        $('.user-profile .complain').fadeIn();
        
    },function(){
        $('.user-profile a p').fadeOut();
        $('.user-profile .contact').fadeOut();
        $('.user-profile .user-action').fadeOut();
        $('.user-profile .alert-inline').fadeOut();
        $('.user-profile .complain').fadeOut();
    });
    
    $('.user-image').hover(function(){
        $('.user-image .contact').fadeIn();
        $('.user-image .user-action').fadeIn();
        $('.user-image .alert-inline').fadeIn();
        
    },function(){
        $('.user-image .contact').fadeOut();
        $('.user-image .user-action').fadeOut();
        $('.user-image .alert-inline').fadeOut();
    });
    
    
    $('.begin-gallery-form .next').click(function(){
        $('.user-image').hide();
        $('.image-loader').show();
        $index = parseInt($('.user-image').attr('data-image-index')) + 1;

        if($index >= parseInt($('.user-gallery').size())){
            $index = parseInt($('.user-gallery:first').index('.user-gallery'));
        }

        $title = $('.user-gallery:eq('+$index+')').attr('data-title'); 
        $image = $('.user-gallery:eq('+$index+')').attr('data-image'); 

        $('.user-image img').attr('src',$image);
        $('.user-image').attr('data-image-index',$index);
        $('.modal .modal-header h3').html($title);
    });
    
    
    $('.begin-gallery-form .prev').click(function(){
        $('.user-image').hide();
        $('.image-loader').show();
        $index = parseInt($('.user-image').attr('data-image-index')) - 1;
                
        if($index < 0){
            $index = parseInt($('.user-gallery:last').index('.user-gallery'));
        }
        
        $title = $('.user-gallery:eq('+$index+')').attr('data-title'); 
        $image = $('.user-gallery:eq('+$index+')').attr('data-image'); 

        $('.user-image img').attr('src',$image);
        $('.user-image').attr('data-image-index',$index);
        $('.modal .modal-header h3').html($title);
    });
    
    
    function imagedynamicresize(img){
        window_width = parseInt($('body').width()); 
        window_height = parseInt($('body').height()); 
        max_height = (window_height/100)*80;


        img.find('img').attr("src", img.find('img').attr("src")).load(function() {
           
        img.removeAttr("width").
        removeAttr("height").
        removeAttr("style");
            
        width = parseInt(this.width); 
        height = parseInt(this.height);

        ratio = max_height/height;

        if(height >= max_height){
            resize_height = max_height;
            resize_width = width * ratio;
            img.height(resize_height);   
            img.width(resize_width);

        }else{
            img.height(height);   
            img.width(width);           
        }
        
        $('.image-loader').hide();
        img.show();        
        
        });


    }
    
    function users_age_filter(minage,maxage){
        if(minage !==null || maxage !==null){
                $('.users-prev li').removeClass('active').hide();
                for($i = minage;$i<=maxage;$i++){
                    $('.users-prev li.user-age-'+$i).addClass('active').show();
                }        
        }
        
    }  
    
    $('#authorization').keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('#authorization-send').click();
            return false;
        } else {
            return true;
        }
    });
    
    //->помощник
    
    $('#helper').toggle(function(){
        $('body').css({'cursor' : 'help'});
        $('.btn, a').css({'cursor' : 'help'});
        $(this).addClass('active');
        $('.helper').addClass('popup-helper');    
        },function(){
        $('body').css({'cursor' : 'auto'});
        $('.btn, a').css({'cursor' : 'pointer'});
        $(this).removeClass('active');
        $('.helper').removeClass('popup-helper');   
    });
    
    $('body').click(function(){
    if($('#helper').hasClass('active')){
        $('#helper').click();
    }
    });
    

    $('.popup-helper').live({
        mouseenter:
           function()
           {
    $(this).popover('show');
           },
        mouseleave:
           function()
           {
    $(this).popover('hide');
           }
       }
    );
    //<-помощник
    
    $('.radio-btn a').click(function(){
        $('.radio-btn a').removeClass('active'); 
        $('.radio-btn-contents').hide();
        $content = $('.'+$(this).attr('data-container'));
        $(this).addClass('active'); 
        $content.show();
    });
    
    $('.check-btn a').click(function(){
    if($(this).hasClass('active')){
        $(this).removeClass('active');
        $content = $('.'+$(this).attr('data-container'));
        $content.removeClass('active').hide();    
    }else{
        $(this).addClass('active');
        $content = $('.'+$(this).attr('data-container'));
        $content.addClass('active').show();
    }
    });
    
    //->ajax запросы
   function slider_age_ajax(minage,maxage){
        $.post("/ajax/profile-change/",{
            search_age : 'true',
            maxage : maxage,
            minage : minage
            
          } ,function(data)
          {
              if(data==1){
                show_alert('profile-update-true');  
              }	
              if(data==0){   

              }            				
          },"json");
    }
    
    function search_gender_ajax(gender){
        $.post("/ajax/profile-change/",{
            search_gender : 'true',
            gender : gender
            
          } ,function(data)
          {
              if(data==1){
                show_alert('profile-update-true');  
              }	
              if(data==0){   

              }            				
          },"json");
    }
    
   $('.add-interesting').click(function(){
        $userID = $(this).attr('data-user-id');
        $username = $(this).attr('data-user-name');
        
        $size = $('.contact .icon.match.active').size();
        var $contacts = [];
        
        for($i=0;$i<=$size;$i++){
            $contacts[$i] = $('.contact .icon.match.active:eq('+$i+')').attr('data-contact');
        }

        if($contacts[0] !== undefined){
        
        $.post("/ajax/interesting-add/",{
            add_interesting : 'true',
            user_to : $userID,
            username : $username,
            contacts : $contacts
            
          } ,function(data)
          {
              if(data==1){
                $('.modal-close').click();
                show_alert('begin-contact-form-true',$username);  
              }	
              if(data==0){
                $('.modal-close').click();
                show_alert('begin-contact-form-double-error',$username); 
              }            				
          },"json");
        }
        else{
            show_alert('begin-contact-form-error'); 
        }
    });
    
    $('.remove-interesting').click(function(){
        $userID = $(this).attr('data-user-id');
        $username = $(this).attr('data-user-name');
        
        $.post("/ajax/interesting-remove/",{
            remove_interesting : 'true',
            user_to : $userID,
            username : $username,
            
          } ,function(data)
          {
              if(data==1){
                $('.modal-close').click();
                show_alert('begin-contact-form-remove-true',$username);  
              }	
              if(data==0){
                $('.modal-close').click();
              }            				
          },"json");
    });    
    
    $('#authorization-send').click(function(){
        $login = $('#email').val();
        $password = $('#password').val();
        
        if($login !=='' && $login !=='Эл. почта'){
        
        $('#authorization .btn-response').show(); 
        $.post("/ajax/authorization/",{
            authorization : 'true',
            login : $login,
            password : $password
            
          } ,function(data)
          {
              if(data.ok==1){
                $('#authorization .btn-response').hide();
                document.location.href = "/profile/";
              }	
              if(data.error==1){
                $('#authorization .btn-response').hide()
                show_alert('authorization-password-error');
              }            				
              if(data.error==2){
                $('#authorization .btn-response').hide()
                show_alert('wrong-auth-mail');
              }
              if(data.error==3){
                $('#authorization .btn-response').hide()
                show_alert('authorization-password-error');
              }
          },"json");
        }else{
            show_alert('authorization-email-error');
        }
    });


    $('#feedback-send').click(function(){
        $name = $('#name').val();
        $text = $('#text').val();
        
        if($name !=='' && $name !=='Представьтесь'){
        
        $('#feedback .btn-response').show(); 
        $.post("/ajax/feedback-add/",{
            add_feedback : 'true',
            name : $name,
            text : $text
            
          } ,function(data)
          {
              if(data.ok==1){
                $('#feedback .btn-response').hide();
                show_alert('feedback-true');
              }	
              if(data=='0'){
                $('#feedback .btn-response').hide()
                show_alert('feedback-error');
              }            				
          },"json");
        }else{
            show_alert('feedback-error');
        }
    });
    
    $('#image-caption-send').click(function(){
        $imageid = $(this).attr('data-image-id');
        $text = $('#image_caption').val();
        
        if($text !==''){
        
        $('#feedback-form .btn-response').show(); 
        $.post("/ajax/image-caption-add/",{
            add_image_caption : 'true',
            imageid : $imageid,
            text : $text
            
          } ,function(data)
          {
              if(data.ok==1){
                $('#feedback-form .btn-response').hide();
                show_alert('image-caption-send-true');
                $('.modal-close').click();
              }	
              if(data=='0'){
                $('#feedback-form .btn-response').hide()
                show_alert('image-caption-send-error');
                $('.modal-close').click();
              }            				
          },"json");
        }else{
            show_alert('all-error');
        }
    });
    
    $('.complain').click(function(){
        $user = $('.user-profile').attr('data-user-id');
        $name = $('.user-profile').attr('data-user-name');
        
        $.post("/ajax/feedback-add/",{
            add_complain : 'true',
            user : $user,
            name : $name
            
          } ,function(data)
          {
              if(data.ok==1){
                show_alert('complain-true');
              }	
              if(data=='0'){
                show_alert('all-error');
              }            				
          },"json");
    });


    
    //<-ajax запросы
});
    function show_alert(alert, name){
        switch (alert) {
        
        case  'profile-update-true' :
            template = '<div class="alert profile-update-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Информация о профиле успешно обновлена</p></div></div>';  
            break;
        
        case 'profile-image-upload-true' :
            template = '<div class="alert profile-image-upload-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Фотографии успешно загружены</p></div></div>';  
            break;
        
        case 'image-caption-send-true' :
            template = '<div class="alert image-caption-send-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Комментарий обновлен</p></div></div>';  
            break;
        
        case 'begin-contact-form-true' :
            template = '<div class="alert begin-contact-form-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Вы успешно отправили запрос <span id="alert-username"></span></p></div></div>';  
            break;
        
        case 'begin-contact-form-remove-true' :
            template = '<div class="alert danger begin-contact-form-remove-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Вы удалили пользователя из списка <span id="alert-username"></span></p></div></div>';  
            break;
        
        case 'complain-true' :
            template = '<div class="alert complain-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Спасибо! Ваша жалоба принята</p></div></div>';  
            break;
        
        case 'feedback-error' :
            template = '<div class="alert danger feedback-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Заполните правильно все поля!</p></div></div>';  
            break;
        
        case 'feedback-true' :
            template = '<div class="alert feedback-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Спасибо! Ваше сообщение успешно отправлено.</p></div></div>';  
            break;
        
        case 'all-error' :
            template = '<div class="alert danger all-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Ошибка запроса!</p></div></div>';  
            break;
        
        case 'begin-contact-form-double-error' :
            template = '<div class="alert danger begin-contact-form-double-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Вы уже отправили запрос пользователю <span id="alert-username"></span></p></div></div>';  
            break;
        
        case 'authorization-email-error' :
            template = '<div class="alert danger authorization-email-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Введите эл. почту</p></div></div>';  
            break;
        
        case 'authorization-password-error' :
            template = '<div class="alert danger authorization-password-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Неправильный пароль</p></div></div>';  
            break;
        
        case 'begin-contact-form-error' :
            template = '<div class="alert danger begin-contact-form-error"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Вы не выбрали контакты</p></div></div>';  
            break;
            
        case 'wrong-city-true' :
            template = '<div class="alert danger wrong-city-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Неправильный город</p></div></div>';  
            break;
            
        case 'wrong-auth-mail' :
            template = '<div class="alert danger wrong-city-true"><div class="alert-header"><a href="#" class="alert-close">×</a></div><div class="alert-content"><p>Введите корректный адрес почты</p></div></div>';  
            break;
        }
        
        $('.system-alerts').append(template).fadeIn(200).delay(3000).fadeOut(200, function() {$('.'+alert).remove();});

        if(name)
        $('#alert-username').html(name);
    }
    
    $('.alert-close').live('click', function(event){
        index = $(this).index('.alert .alert-close');
        $('.alert:eq('+index+')').hide();
        return false;
    }); 
