var ru = jQuery.noConflict();   
ru(document).ready(function(){ 
    if(ru(".resizable").length!=0) {
        ru('textarea.resizable:not(.processed)').TextAreaResizer();   // для textarea
    }
    var c = new ru.cookie(); // создаем куки    
    function setcooky() {
        return c.set({ expires: 300, path: '/'}); // отсылаем
    }
  ru(".p1").click(function () {            
            parents=ru(this).parent().parent().parent().parent().parent().parent().parent().parent(); // получаем id модуля               
            idone=parents.attr("id"); // получаем id нужного элемента
            color = ru(this).next().css("display"); // унаем свойство блока
            
            if(color=="block") {
                     ru(this).next().slideUp("slow");     // получаем элемент который нужно свернуть
                    //ru(this).css("border-bottom", "none")

                    ru(this).find(".show").css({"background":"url(http://"+location.host+"/templates/ageent/images/down.jpg)  no-repeat right"})
                    c.get(); // получаем куки
                    fildone=c.field; // получаем нужное поле
                    
                    if(fildone==undefined) { // если это первый раз то
                        c.field = idone+"-"; // устанавливаем первое значение
                        setcooky()
                    } else {
                        if(fildone.search(idone) == -1) { // если среди установленных значений нет тоого на которое нажали
                           c.field = fildone + idone+"-"; // то записываем его в куки
                           setcooky()
                        }        
                    }
            } else {
                    ru(this).next().slideDown("slow");     // показываем нужный элемент
                    ru(this).css("border-bottom", "2px solid #F6F6F6")
                    ru(this).find(".show").css({"background":"url(http://"+location.host+"/templates/ageent/images/up.jpg)  no-repeat right"})
                    c.get(); // получаем куки
                    fildone=c.field; // получаем нужное поле
                    c.field = fildone.replace(idone,"")
                    setcooky()
            }
            
        
   });
     ru(window).one("load", function(){
            // для основных шаблонов выставляем высоту
            centr=ru(".centr").height();
            if(centr!=null) {
                centr-=20;
                ru("#ja-content").css({"min-height" : centr+"px"});
            }
            // для доки по joomla  
            centr_two=ru("body").height();
            if(centr_two!=null) {
                centr_two-=115;
                ru("#ja-content").css({"min-height" : centr_two+"px"});
            }
            c.get();
            dima= new String();
            var agent;
            agent=c.field;
            if(agent!=undefined) {
                agent=agent.split("-");
                 for (i = 0; i<agent.length; i++) {
                    if(agent[i]!="") {
                        ru("#"+agent[i]).find(".p1").next().slideUp("slow");     // получаем элемент который нужно свернуть
                        ru("#"+agent[i]).find(".show").css({"background":"url(http://"+location.host+"/templates/ageent/images/down.jpg)  no-repeat right"})
                         dima+=agent[i]+"-";
                    }
                 }
                    c.field = dima; // устанавливаем первое значение
                 setcooky()
            }
     });

            ru(window).resize(function() {
                centr=ru(window).height();        
                    if(centr!=null) {
                        centr-=182;
                        ru("#ja-content").css({"min-height" : centr+"px"});
                    }
                centr_two=ru("body").height();
                if(centr_two!=null) {
                    centr_two-=115;
                    ru("#ja-content").css({"min-height" : centr_two+"px"});
                }
            });
            
            
/* Форма регистрации*/
     // имя пользователя
     ru("#josForm").find("#name").blur(function () {
         namemsg=ru(this).val();    
             if(namemsg!="") {
                 ru(this).css({"border":"none","background":"none","font-weight":"bold"});    
                ru("#namemsg").css({"color":"#333333" }) 
             } else {
                ru("#namemsg").css({"color":"red"}) 
             }         
     });

     // логин пользователя
     ru("#josForm").find("#username").blur(function () {
         usernamemsg=ru(this).val();    
             if(usernamemsg!="") {
                 ru(this).css({"border":"none","background":"none","font-weight":"bold"});    
                ru("#usernamemsg").css({"color":"#333333"}) 
             } else {
                ru("#usernamemsg").css({"color":"red"}) 
             }         
     });
     
     // e-mail адрес пользователя
    ru("#josForm").find("#email").blur(function () {
         emailmsg=ru(this).val();    
             if(isValidEmail(emailmsg)) {
                 ru(this).css({"border":"none","background":"none","font-weight":"bold"});    
                ru("#emailmsg").css({"color":"#333333"}) 
             } else {
                ru("#emailmsg").css({"color":"red"}) 
             }         
     });

     // пароль пользователя
    ru("#josForm").find("#password").blur(function () {
         pwmsg=ru(this).val();    
             if(pwmsg!="") {
                 ru(this).css({"border":"none","background":"none","font-weight":"bold"});    
                ru("#pwmsg").css({"color":"#333333"}) 
             } else {
                ru("#pwmsg").css({"color":"red"}) 
             }         
     });
     
     // подтверждение пользователя
     ru("#josForm").find("#password2").blur(function () {
         pw2msg=ru(this).val();
             if((pw2msg!="") && (pw2msg===pwmsg)) {
                 ru(this).css({"border":"none","background":"none","font-weight":"bold"});    
                ru("#pw2msg").css({"color":"#333333"}) 
             } else {
                ru("#pw2msg").css({"color":"red"}) 
             }         
     });
     
    ru("#josForm").find("input").focus(function () {
         ru(this).css({"border":"1px solid #CCCCCC","background":"#FFFFCC" });        
    });
    
    function isValidEmail (email, strict){
     if ( !strict ) email = email.replace(/^\s+|\s+ru/g, '');
     return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}ru/i).test(email);
    }
    
    // для сворачивания, разворачивания блоков
    setTimeout( function() {
        ru('.india').next().css('display', 'none').addClass("you").end().click(function() {
            ru(this).next().slideToggle('show');
          }); 
    }, 600);

    
    // фикс для pre в ie
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
     var ieversion=new Number(RegExp.$1)
     if (ieversion) {
           ru(".rj_insertcode").find("td:eq(0)").css({"width":"22px"})
        ie6_width=ru(window).width();
        if(ie6_width<1024) {
            ru(".allfix").css({"width":"210px"});
        }
     }
    }
    /* Фикс для комментов */
    if(ru("#maincolumn").length!=0) {
        ru("body").append('<style type="text/css">#jc{ position:relative; margin-top:-21px;}.ie #jc{ position:relative; margin-top:-36px;}</style>')
    }

      ru("select[name='traslang']").change(function () {
         ru("form[name='thumbnails_one']").submit();
      });
      
      // для панели языков
        ru(".cont_two").hover(
              function () {
                 ru(".cont_three").fadeIn("slow");
              }
        );
        ru(".cont_three").hover(
              function () {
              },
              function () {
                 ru(".cont_three").fadeOut("slow");
              }
        );
        
        var text="";
        ru("#nav_inner:not(a)").click(function(lol) {
            ru("a").click(function() {   
               text = ru(this).text();   
            }); 
            if(text=="") {
               ru(".cont_one").click();    
            }
        });
        
        if(ru(window).width()>1270) {
            ru(".cont_two").css({"left":"1120px"});
            ru(".cont_three").css({"left":"765px"});
        }
        
        ru.ajax({
           type: "GET",
           url: "http://www.ageent.ru/modules/mod_vvisit_counter/dima.php?option=vvisit_counter",
           success: function(msg){
              ru("#vvisit_counter").html(msg).slideDown();
           }
         });
         
         ru("#hovred a[class!=curlanguages]").mouseover( function() {
            ru(this).animate({color: "#e60000"}, {queue:false, duration:250 });
         }).mouseout( function() {
            ru(this).animate({color: "#ffffff"}, { queue:false, duration:350});
         });
         
        ru('"#translate_popup a[id!=curlanguagesona]"').live('mouseover', function() {
            ru(this).animate({color: "#e60000"}, {queue:false, duration:250 });
        });      
        
        ru('"#translate_popup a[id!=curlanguagesona]"').live('mouseout', function() {
            ru(this).animate({color: "#006699"}, { queue:false, duration:350});
        });
});