﻿/* http://plugins.jquery.com/project/Cookie */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('n.5=v(a,b,c){4(7 b!=\'w\'){c=c||{};4(b===o){b=\'\';c.3=-1}2 d=\'\';4(c.3&&(7 c.3==\'p\'||c.3.q)){2 e;4(7 c.3==\'p\'){e=x y();e.z(e.A()+(c.3*B*r*r*C))}s{e=c.3}d=\'; 3=\'+e.q()}2 f=c.8?\'; 8=\'+(c.8):\'\';2 g=c.9?\'; 9=\'+(c.9):\'\';2 h=c.t?\'; t\':\'\';6.5=[a,\'=\',D(b),d,f,g,h].E(\'\')}s{2 j=o;4(6.5&&6.5!=\'\'){2 k=6.5.F(\';\');G(2 i=0;i<k.m;i++){2 l=n.H(k[i]);4(l.u(0,a.m+1)==(a+\'=\')){j=I(l.u(a.m+1));J}}}K j}};',47,47,'||var|expires|if|cookie|document|typeof|path|domain|||||||||||||length|jQuery|null|number|toUTCString|60|else|secure|substring|function|undefined|new|Date|setTime|getTime|24|1000|encodeURIComponent|join|split|for|trim|decodeURIComponent|break|return'.split('|'),0,{}))

var vtype=0;
$(function(){

  if (location.href.indexOf('/link/') > 0)
  {
    var o=location.href.indexOf('#');
    if (o>0)   $('#name'+location.href.substr(o+1,100)).parent().addClass('linkAmchor');


  }

  $('#li').append("<a href='http://www.liveinternet.ru/click;hpsy' target=_blank id='LIRU'><img src='//counter.yadro.ru/hit;hpsy?t45.1;r" + escape(document.referrer) + ((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)) + ";u" + escape(document.URL) + ";" + Math.random() + "' border=0 width=31 height=31 alt='' title='LiveInternet'><\/a>");




  $('span.external').each(function(){
        var url= $(this).attr('title');
        if (url.indexOf('/'))
        if (url.indexOf('ttp://') < 0) url="http://"+url;
        $(this).wrap('<a rel="nofollw" href="'+url+'"></a>')
    });

   $('.citero li')
   .hover(function(){
      $('.hover').removeClass('hover');
      $(this).addClass('hover');
      return true;
   })
   .bind('mouseover',function(e){
     var s='',l,url,a,e=$(e.target);
     if (!e.hasClass('social'))  return true;

     $(e).attr('target','_blank');
     t=$(e).parent().parent().find('.ctext a');
     url='http://cpsy.ru/cit'+$(e).attr('rel')+'.htm';
     a=t.attr('rel');
     t=t.html();

     if (e.hasClass('tw'))
     {

        s=t + ' '+ a;
        l=url.length;
        if (s.length > 135-l) s=t;
        if (s.length > 135-l) s=t.substr(0,135-l)+'...';
        s=s+' '+url;
        s='http://twitter.com/home?status='+s;
     }
     if (e.hasClass('lj'))
     {
       s="http://www.livejournal.com/update.bml?event=<a+href%3D"+url+">"+t+' /'+a+"/<%2Fa>&subject="+a+" Цитаты+";
     }
     if (e.hasClass('fb'))
     {
        s="http://www.facebook.com/sharer/sharer.php?u="+url+"&t="+t+' /'+a+'/';
     }
     $(e).removeClass('social');
     if (s!=='')  e.attr('href',s);

   });





      $("#ajaxLoad").load("/tmp/json.htm",
       function(){
          // голосовалка

          if (Math.random()<0.5) vtype=1;

          if ($.cookie('vote1') == 1) vtype=0; else
          if ($.cookie('vote0') == 1) vtype=1;
          if ($.cookie('vote1')+$.cookie('vote0') == 2) vtype = -1;
          if ((vtype == 0) || (vtype  <0 )) {domen='zpsy.ru'; $('.vote1').remove();}
          if ((vtype == 1) || (vtype  <0 )) {domen='solitarius.ru'; $('.vote2').remove();}







          //реклама собственных проектов  случайное перемешивание
          var e=$('#ajaxLoad .block1');
          var n=e.size();


          var hL=$('.main').height();
          var hR=$('.Right').height();
          var hh=0;
          for (i=0;i<n;i++)
          {
             hh=$(e[i]).height();
             if (hR + hh  < hL)  {$(e[i]).show();hR=hR+hh;}  else  $(e[i]).remove();


          }

  }
  );

  $('#voteSend').live('click',function(){
    if ($('#vote2 .v1 input:checked').size() == 0) {alert('Вы забыли ответить на первый вопрос "Ваше отношение..."');return;}
    if ($('#vote2 .v2 input:checked').size() == 0) {alert('Вы забыли ответить на второй вопрос "Что является..."');return;}

    var n=false;  $('#vote2 .v3 select').each(function(){
        if (!parseInt($(this).val())) n=true;
    })
    if (n)  {alert('Вы забыли ответить на вопросы краткой анкеты "Пол, возраст..."');return;}

    $('.button input').attr('style','visibility:hidden');
    $.cookie('vote'+vtype, 1,{expires: 100000 });
    $('#vote2').attr('action','http://'+domen+'/vote2').submit();





  })

  $('.v3select').live('click',function(){
    if ($('#vote2 .v2 input:checked').size() >3) {alert('Возможен выбор только трех пунктов. Вы можете отменить выбор одного из предыдущих пунктов');
    $(this).removeAttr('checked');
    }
  })

  $('.Twitter').click(function(){
    var e=$(this).parent().find('a').text() + ' /'+ $(this).parent().parent().find('i a').text()+'/ ' + location.href;

    location.href='http://twitter.com/home?status='+e
  })


  $('.rselect').change(function(){
     location.href='/cit'+$(this).val()+'.htm';
  });

})



