$(document).ready(function() {
jQuery.preloadImages = function()
{
 for(var i = 0; i<arguments.length; i++)
 {
  jQuery("<img>").attr("src", arguments[i]);
 }
};


 var referal = document.referrer;
 $.post('/ultra/count.php', {w: $(window).width(), h: $(window).height(), ref: referal }); var wi; wi = $(window).width();

 /*
 $("img[id=soc]").hover(function(){  var pa = $(this).attr('src');
  pa =pa.replace("_0", "_1");
  $(this).attr('src', pa); }, function(){  var pa = $(this).attr('src');
  pa =pa.replace("_1", "_0");
  $(this).attr('src', pa); })
 */
 $(".counters").hover(function(){  $(this).animate({opacity: 1}) }, function(){ $(this).animate({opacity: 0.3}) })

 $("a[id=playmusic]").click(function(){
  $("#playnow").html('Идет загрузка песен, пожалуйста подождите...');
  $.post('/ultra/pmusic/', {uid: $(this).attr('href')}, function(d){   $("#playnow").html(d);  })  return false; })

 $("img[id=gphoto]").hover(function(){  var s = $(this).attr('rel');
  $("#td_"+s).css('background-color', '#f4f4f4'); }, function(){  var s = $(this).attr('rel');
  var bg = $(this).attr('rel2');
  $("#td_"+s).css('background-color', bg); })


 var he;
 $("#black_img").load(function(){
 $.preloadImages("/i/prod/big/cs_05.jpg", "/i/prod/big/cs_06.jpg");
  he = $("#black_img").css('height');  $('#sss').animate({height: he}) })

 $("a[id=black_gallery]").click(function(){
  var iname = $(this).attr('href');
  $("#black_img").fadeOut('slow', function(){  	$('#black_img').attr('src', '/i/prod/big/'+iname);
  	$("#black_img").fadeIn('slow');  })
   he = $("#black_img").height();
  return false; })

 $("#addcomment").click(function(){  var uid = $(this).attr('href');
  $.post("/ultra/getform/", {sid: uid}, function(d){
   $("#bform").html(d);
  })
  return false; })

 $("#send_comment").live('click', function(){  var uid = $(this).attr('rel');
  $.post('/ultra/sendm/', {uname: $("#uname").val(), ucomm: $("#ucomm").val(), num: uid}, function(d){   if(d == "bad"){alert('Ошибка!\n - Вы заполнили не все поля.');}
   else{   	window.location = '/blog/'+uid+'.html';   }  }) })

});

$(function(){
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 15;


	var divWidth = div.width();


	div.css({overflow: 'hidden'});


	var lastLi = ul.find('li:last-child');

	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
