//var $J = jQuery.noConflict();
jQuery(document).ready(function(){

	//submenu - third level
	$(".branch_1 a").mouseover(function(){
		$(this).next(".branch_2").show().siblings(".branch_2").hide();
	}).mouseout(function(){
		$(this).next(".branch_2").hide();
	});
	
	$(".branch_2").mouseover(function(){
		$(this).show().siblings(".branch_2").hide();
	}).mouseout(function(){
		$(this).hide();
	}).each(function(){
		$("li", this).filter(":last").css({background: "#fff"});
	}).prepend('<b class="b1t"></b><b class="b2t"></b><b class="b3t"></b><b class="b4t"></b>').append('<b class="b4t"></b><b class="b3t"></b><b class="b2t"></b><b class="b1t"></b>');
	
	//top submenu
	$("#menu a").mouseover(function(){
		$(this).next(".headmenu2").show().siblings(".headmenu2").hide();
	}).mouseout(function(){
		$(this).next(".headmenu2").hide();
	});
	
	$(".headmenu2").mouseover(function(){
		$(this).show().siblings(".headmenu2").hide();
	}).mouseout(function(){
		$(this).hide();
	}).each(function(){
		$("li", this).filter(":last").css({background: "#fff"});
	}).prepend('<b class="b1t"></b><b class="b2t"></b><b class="b3t"></b><b class="b4t"></b>').append('<b class="b4t"></b><b class="b3t"></b><b class="b2t"></b><b class="b1t"></b>');
	
	//$("#tabs, #tabs_types").tabs();
	//$('a.lightbox').lightBox();
	
	
	
	$('.itemAdd').click(function(){
		var input = $(this).parent().find('input:text');
		var name = input.attr('name');
		var qnt = input.val();
		//console.log('Name: [' + name + '] ' + 'Qnt: [' + qnt + '] ' + 'Mat: [' + material+ '] ' + 'Col: [' + color+ ']');
		//alert('/rus/ajax/?action=add2cart&'+name+'='+qnt);
		$.get('/ru/ajax/',{action: 'add2cart', name: name, qnt: qnt}, 
			function(data){
				//console.log(data);
				if (data!=0) {
					//alert(data);
					alert('Позиция добавлена в корзину');
					$('#cart_bit strong').text(data);
				}
		});
		return false;
	});
	
	// item_descr's same height
	max_h = 0;
	$(".item_descr").each(function(){
		if (max_h < $(this).height())
		{
			max_h = $(this).height();
		}
	});
	$(".item_descr").height(max_h);
	
});

function MaterialsChange(id, name) {
	$('.material').hide();
	$('#colors_set_'+id).show().find(':radio:first').attr('checked', 'checked');
	$('td.price span').hide();
	$('span.price_'+id).show();
	$('td.price').each(function(){
		//console.log($(this).find('span:visible').length);
		if ($(this).find('span:visible').length == 0) $(this).find('span.price_null').show();
	});
	$('.material_name').html(name);
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
for (var i=0; i < anchors.length; i++) 
	if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external")
			anchors[i].target = "_blank";
}
window.onload = externalLinks;


//document.oncontextmenu = function () { return false; } 
