/* index.html */

function inputBlur(elm){
    var val = elm.val();
    if(val == ''){
        var html = $('<input type="text" name="password" id="password" value="пароль" />');
        elm.replaceWith(html);
    }    
}

function inputFocus(elm){
    var val = elm.val();
    if(val == 'пароль'){
        var pass = $('<input type="password" name="password" id="password" value="" />');
        elm.replaceWith(pass);
        pass.focus();
    }   
}

var  wimg = 123;
function hideGalleryLinks(){
    $('.move_left, .move_right').hide();
    $('.photo_scroll img').each(function(){
        wimg = wimg + $(this).width();
        if($('.photo_scroll').width() < wimg){
            $('.move_left, .move_right').show();
            return false;
        }
    });
}

$(document).ready(function(){
                    
                    $('#search_text_fild').focus(function(){
                        if($(this).attr('value') == 'Поиск'){$(this).attr('value','');}
                    });
                    
                    $('#search_text_fild').blur(function(){
                        if($(this).attr('value') == ''){$(this).attr('value', 'Поиск');}
                    });
                    
                    $('#fsbtn').click(function(){
                        $('#search_form').submit();
                    });
                    
                    onblur=""
    
                    $(".plan_div").dialog({
                        autoOpen: false,
                        buttons: { 
                            "Закрыть": function(){
                                $(this).dialog("close"); 
                            }
                        }
                    });
    
                    $('#flash_plan').click(function(){
                        var params = "menubar=no, location=no, resizable=no, scrollbars=no, status=no, width=950, height=655";
                        window.open("/images/main2.html", "Yandex", params);
                    });
                    
                    $('#flash_plan_w').click(function(){
                        var params = "menubar=no, location=no, resizable=no, scrollbars=no, status=no, width=950, height=655";
                        window.open("/images/main_w.html", "Yandex", params);
                    });
    
                    hideGalleryLinks();
                    
                    $('.move_left').click(function(){
                        container = $('.photo_scroll #vlightbox');
                        margin = parseInt(container.css("margin-left"));
                        if(margin>=0){
                            return false;
                        }
                        pos = 160;
                        container.stop().animate({
                                    marginLeft: '+='+pos+'px'
                        }, 1000, function() {
                            width = container.width();
                            margin = parseInt(container.css("margin-left"));
                            if(margin>0){
                                container.animate({
                                    marginLeft: '0px'
                                }, 1000);    
                            }
                        });
                        
                        return false;
                    });
                    
                    $('.move_right').click(function(){
                        container = $('.photo_scroll #vlightbox');
                        width = container.width();
                        margin = parseInt(container.css("margin-left"));
                        stop = (width-600)*-1;
                        if(margin<0 && margin<=stop){
                            return false;
                        }
                        if(width<600 && margin == 0){
                            return false;    
                        }
                        pos = 160;
                        container.stop().animate({
                                    marginLeft: '-='+pos+'px'
                        }, 1000, function() {
                            width = container.width();
                            margin = parseInt(container.css("margin-left"));
                            stop = (width-600)*-1;
                            if(margin<0 && margin<stop){
                                if(width>600){
                                    margval = stop;
                                }else{
                                    margval = 0;    
                                }
                                container.animate({
                                    marginLeft: margval+'px'
                                }, 1000);    
                            }
                        });
                        return false;
                    });
    
                    $('.login_link').live('click', function(){
                        offset = $(this).offset();
                        $('#login_form_dialog').css('left', offset.left);
                        $('#login_form_dialog').css('top', offset.top);
                        $("#login_form_dialog").show();
                        overlay = $('<div class="overlay_my"></div>');
                        $('body').append(overlay);
                        overlay.fadeTo('slow', 0.5);
                        return false;    
                    });
                    
                    $('#close_login_dialog_link').click(function(){
                        $("#login_form_dialog").hide();
                        $('.overlay_my').remove();
                        return false;
                    });
                    
                    $('#login_form_dialog #password').live('focus', function(){
                        inputFocus($(this));        
                    });
                    
                    $('#login_form_dialog #password').live('blur', function(){
                        inputBlur($(this));           
                    });
                    
                    $('#login_form_dialog #login').live('focus', function(){
                        var val = $(this).val();
                        if(val == 'логин'){
                            $(this).val('');    
                        }            
                    });
                    
                    $('#login_form_dialog #login').live('blur', function(){
                        var val = $(this).val();
                        if(val == ''){
                            $(this).val('логин');    
                        }           
                    });
                    
                    
                    $('#reklama_block_content .rb_content').css('display', 'none');
                    $('#reklama_block_content .rb_content:last').css('display', 'block');
                    
                    $('.reklama_block_menu td a').live('click', function(){
                        var rel = $(this).attr('rel');
                        $('.reklama_block_menu .rbm_selected').removeClass('rbm_selected');
                        $(this).parent().addClass('rbm_selected');
                        $('#reklama_block_content .rb_content').css('display', 'none');
                        $('#reklama_block_content #'+rel).css('display', 'block');
                        return false;
                    });
                    

/* e.o. index.html */ 

/* form.phtml comments form */
    /*
    $("#comments_form_dialog").dialog({
        autoOpen: false,
        width: 480,
        buttons: { 
            "Закрыть": function(){
                $(this).dialog("close"); 
            }
        }
    });
    $('#add_comment_link').live('click', function(){
        $('#comments_form_dialog').dialog("option", "title", 'Добавить Комментарий');
        $('#comments_form_dialog').dialog("open");
        return false;    
    });
    
    
    $('.answer_link').live('click', function(){
        $('#comments_form').find('#answer_to').val($(this).attr('rel'));
        $('#comments_form_dialog').dialog("open");
        $('#comments_form_dialog').dialog("option", "title", 'Ответить '+$(this).text());
        return false;    
    });
    
    */ 
    $('.comments_text').each(function(elm){
        new Redactor($(this), {});
    });
        
    
    $('#comments_dialog_link').live('click', function(){
        $('#comments_form_dialog').slideToggle('fast');
        return false;
    });
    
 /* form.phtml comments form */ 
 
 
 /* reserve.html */
    $('#reserve_form').submit(function(){
          $('#reserve_status').html('<img src="/images/ajax/loading.gif" alt="" border="0">');
          var options = {
              target: "#reserve_status",
              url: "/classes/residence/ajaxActions.php5",
              success: function() {
                    
              }
          };
          $('#reserve_form').ajaxSubmit(options);
          return false;
    });
    
 /* reserve.html */   
    
    
    
    /* clock_link action */
    
    
    
    if(is_admin){ // сетится в индексе в хедере
        btns = {
            "Закрыть": function(){
                $(this).dialog("close"); 
            },
            "Сохранить": function(){
               var ptext_memo = FCKeditorAPI.GetInstance('ptext_memo').GetXHTML();  
               $.ajax({
                    type:'POST',
                    url: 'ajax/ptext',
                    dataType: 'json',
                    data: {
                        'method':'editPartText',
                        'params':{
                            'symbol':'clock',
                            'ptext_memo':ptext_memo
                        }
                    },
                    success: function(data) {
                        alert('Данные успешно обновлены');
                        $('#clock_dialog').dialog('close');
                    }
                }); 
            }     
        }    
    }else{
        btns = {
            "Закрыть": function(){
                $(this).dialog("close"); 
            }
        }
        
    }
    
    if(is_admin){
        var width_d = '1100px';
    }else{
        var width_d = '970px';
    }
    $('#clock_dialog').dialog({
        autoOpen: false,
        buttons: btns,
        width: width_d,
        modal: true
    });
     
     
     
     
     
           
    
    $('#clock_link, #clock_img').click(function(){
        
        $.ajax({
            type:'POST',
            url: '/ajax/ptext',
            dataType: 'json',
            data: {
                'method':'getPartText',
                'params':{
                    'symbol':'clock'
                }
            },
            success: function(data) {               
                $('#clock_dialog_content').html(data.text);        
                $('#clock_dialog_content').append(data.editform);        
                $('#clock_dialog').dialog('open');
                
                $('.clock_table tbody tr').hover(function(){
                    $(this).toggleClass('hover');
                });
                $('.clock_table tbody tr:even').css('background-color','#e5e5e5');
                
            }
        });
        return false;
    });
    
    /* EO clock_link action */
    
    
}); 
 
    
    

