$(document).ready(function() { var referal = document.referrer;
 $.post('/ultra/count.php', {w: $(window).width(), h: $(window).height(), ref: referal });

 $('.slidetabs > div > a').click(function(){
  var se = $(this).css('background-position');
  alert(se);
  if(se == '0% -8px'){   $('.slidetabs > div > a').css('background-position', '0px 0px')
   $(this).css('background-position', '0 -16px')
   var j = $(this).attr('href');
 	 $('div.blog_cont > div').css('display', 'none');
 	 $('div.'+j).fadeIn('slow');
  }  return false; })
 $("div.co img").css('opacity', '0.3');
 $("div.co img").hover(function(){$(this).animate({'opacity': '1'})}, function(){$(this).animate({'opacity': '0.3'})})

 $("#cabinet").click(function(){
  $(document.body).append($("<div class=\"fon\" />"));
  $("div.fon").fadeIn('slow');
  $.post('/ultra/loginform/', function(d){$("div.fon").html(d);})
  return false; })
 $("#en").live('click', function(){  var va = $(this).attr('rel');
  if(va == "exit"){$("div.fon").fadeOut('slow');} })

 $("#en").live('mouseover', function(){  $(this).animate({backgroundPosition: '0px -170px'}, 1000); })
 $("#en").live('mouseout', function(){
  $(this).animate({backgroundPosition: '0px 0px'}, 'slow');
 })

        // Tabs
        $("div[id=sha_tab]").click(function(){         $("div[id=sha_tab]").css({'color': '#FFF', 'height': '20px', 'margin-top': '20px'});
         $(this).css({color: '#ff8a00', height: '40px', 'margin-top': '0px'})        })
        var max_num = $('div.all_port > img').size();
        var end_num = max_num*147;
        end_num = 882-end_num; end_num = end_num+'px';  //1029
        $('div[id=slide]').click(function(){         var type = $(this).attr('rel'), y = $("div.all_port").css('margin-left');
          if(type == "right"){
          if(y != end_num){
          $("div.all_port").dequeue().animate({'marginLeft': '-=147px'}, 100)
          }

          }else{if(y < "0"){$("div.all_port").dequeue().animate({'marginLeft': '+=147px'}, 100)}}        return false;        })

        $("div.all_port > img").click(function(){
         $("div.all_port > img").css('border', '1px solid #555')
         $(this).css('border', '1px solid #ff8a00');
          $.ajax({
           type: "POST",
           url: "/ultra/viewport/",
           dataType: "text",
           data : 'nid='+$(this).attr('rel'),
           success: function(data) {
            json = eval("(" + data + ")");

             $("#pbimg").attr('src', '/i/port/norm/'+json.img)
             $("#pbname").html(json.sitename)
             $("div.port_linkv").html('<a href="http://'+json.link+'" target="_blank">'+json.link+'</a>')
             $("#pbcont").html(json.text)
           }
           });
        })

        $("div.all_port > img").hover(function(){
         var path = $(this).attr('src');
         var np = $(this).attr('src').replace('b.jpg', '.jpg');
         $(this).attr('src', np);        }, function(){         var path = $(this).attr('src');
         var np = $(this).attr('src').replace('.jpg', 'b.jpg');
         $(this).attr('src', np);        })

        $("#send_pub").click(function(){         var fi = $("#ufile").val();
         $.post('/ultra/stest/', {file: fi, date: $("#udate").val(), title: $("#utitle").val(), text: $("#redactor_content").val()})         alert('Сообщение отправлено');        })
        $("img[id=resimg]").live('click', function(){         var jid = $(this).attr('rel');
         $.post('/ultra/resvcont/', {uid: jid}, function(d){$("#print").html(d)})
         //alert(jid);        })



})

$(document).ready(
       function(){
        $('ul#portfolio').innerfade({
         speed: 2000,
         timeout: 5000,
         type: 'sequence',
         containerheight: '220px'
        });

        $('.fade').innerfade({
         speed: 1000,
         timeout: 6000,
         type: 'random_start',
         containerheight: '1.5em'
        });


      });
