$(document).ready(function(){
colors = new Array('#FF52C4', '#FFD501', '#00BDF9', '#BA21FF', '#0065E5', '#00C700','#f38f00')
  i=1;
  while(colors.length) {
    r = colors.splice( Math.floor(Math.random()* (colors.length) ),1 );
    $(".Theadmenunew li::nth-child("+i+") a").css("color",r);
    i++;
  }
  $(".Theadmenunew li a:hover").css("color","#000");
  
	w = parseInt($("#pic").css("width"));
	h = parseInt($("#pic").css("height"));
	if(w>300){
	  w=300;
	  var d = w/h;
      $("#pic").css("width",w);
      $("#pic").css("height",h*d);
	}
  
  $.ajax({
			url: '/cart/add/?goods_id=-1',
			data: { "_mode": "js" },
			cache: false,
			success: function(data) {
				$("#cart_block .Tfont3").html(data);
			}
		});
    
	$(".add_to_cart").click(function () {
		$("table .hint").remove();

		$("#hint").clone().insertBefore($(this)).show();
		
		$.ajax({
			url: this.href,
			data: { "_mode": "js" },
			cache: false,
			success: function(data) {
				$("#cart_block .Tfont3").html(data);
			}
		});

		return false;
	});
  
	$(".remove_from_cart").click(function () {
		$.ajax({
			url: this.href,
			data: { "_mode": "js" },
			cache: false,
			success: function(data){
				if (data == 0)
				{
					$(".catalog").parent().before("<p>Ваша корзина пуста.</p>")
					$(".catalog").parent().remove();
				}
				else 
				{
					$("#total").html(data);
				}
			}
		});
		
		$(this).parent().parent().remove();

		return false;
	});
  
  $(".Tleftmenu li").mouseover(function() {
    $(this).attr("class","Thover");
  });
  $(".Tleftmenu li").mouseout(function() {
    $(this).attr("class","");
  });
});


headmenuHover = function() {
	var sfEls = document.getElementById("headmenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		if(sfEls[i].className.substring(0,5)!="Thead") continue;
		sfEls[i].getElementsByTagName("div")[0].className = "Tnorm";
		sfEls[i].onmouseover=function() {
			this.getElementsByTagName("div")[0].className = "Thover";
			document.getElementById(this.className.substring(1)).className = "";
		}
		sfEls[i].onmouseout=function() {
			this.getElementsByTagName("div")[0].className = "Tnorm";
			document.getElementById(this.className.substring(1)).className = "Thidden";
		}

	}

	
	sfEls = document.getElementById("leftmenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className = "Thover";
		}
		sfEls[i].onmouseout=function() {
			this.className = ""; //this.className.replace(new RegExp("hover\\b"), "");
		}
	}
	
	sfEls = document.getElementsByName("arrow");
	for (var i=0; i<sfEls.length; i++)
		if (sfEls[i].className=="Tarrleftact") {
			sfEls[i].className = "Tarrleftcur"; sfEls[i].className = "Tarrleftact"; break;
		}
for (var i=0; i<sfEls.length; i++)
		if (sfEls[i].className=="Tarrrightact") {
			sfEls[i].className = "Tarrrightcur"; sfEls[i].className = "Tarrrightact"; break;
		}
	sfEls = document.getElementsByName("arrow");
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].className=="Tarrleftact"){
			sfEls[i].onmouseover=function() {
				this.className = "Tarrleftcur";
			}
			sfEls[i].onmouseout=function() {
				this.className = "Tarrleftact"; //this.className.replace(new RegExp("hover\\b"), "");
			}
		}
		if(sfEls[i].className=="Tarrrightact") {
			sfEls[i].onmouseover=function() {
				this.className = "Tarrrightcur";
			}
			sfEls[i].onmouseout=function() {
				this.className = "Tarrrightact"; //this.className.replace(new RegExp("hover\\b"), "");
			}
		}
	}
}
window.onload = headmenuHover;
