function setMenuItems() {
	$img = new Image();
	$img.onload = function(){
		$img.onload = null;
	};
	$img.src = '/images/tooltip.gif';
	$div = '<div id="mip" style="position:absolute;display:none;background:url(/images/tooltip.gif) no-repeat;width:55px;height:55px;text-align:center;font-size:9px;"><div style="color:#7e191d;font-size:18px">0</div>товаров</div>';
	$('body').append($div);
	$('#menu_r li a').mouseover(function() {
		var mappos = {};  
		mappos = $(this).position();
		var items = $(this).attr('items');
		$('#mip').children().html(items);
		$('#mip').css({"left":(mappos['left']-42)+'px',
				  "top": (mappos['top']-45)+'px'
		}).show();		
	}).mouseout(function() {
		$('#mip').hide();
	});
}
function setShades() {
	$('.cat').each(function() {
		var _this = this;
		var minprice = $(this).attr('minprice');
		var c = $(this).attr('items');
		$(this).css('position', 'relative').
		append('<div onmouseover="$(this).show();" onclick="document.location.href=\''+$(this).attr('url')+'\'; "class="shade" style="position:absolute;top:45px;height:215px;width:217px;color:#FFFFFF;background:url(/images/shade.png) bottom no-repeat;display:none;cursor:pointer"><div style="padding-top:177px;font-weight:bold;padding-left:20px">Всего товаров: <span class="mci" style="color:#e5b200">'+c+'</span> шт.<br>Цена от: <span class="mcr" style="color:#e5b200">'+minprice+'</span> руб.</div></div>')
		.mouseout(function() {
			$('.shade', _this).hide();
		});
		$('img', this).
		mouseover(function() {
			$('.shade', _this).show();
		});
	});
	$(document).pngFix();
}
function letLogin() {
	$.blockUI({message: '<div style="font-size:18px;padding:10px"><img src="/images/busy1.gif" /><br><b>Осуществляю вход...</b></div>'});
	$('#lform').ajaxSubmit({
		success: function(data) {
			if (data == 1) {
				$.unblockUI();
				window.location.reload();
			}
			else {
				$.blockUI({message: '<div style="font-size:18px;padding:10px"><font color=red>Вы ввели неверные данные!</font><br><a href=# onclick="$.unblockUI();return false;">Закрыть окно</a></div>'});
			}			
		}
	});	
}
function addCart(_this) {
	$(_this).parent().parent().parent().parent().parent().block({  
	            message: '<img src="/images/busy1.gif" /><br><b>Добавляю...</b>',  
	            css: { 'padding':'5px 10px', border: '2px solid #989898', width: '100px'},
		    overlayCSS:  { backgroundColor:'#ADADAD'}
	        });	
	var p = $(_this).parent().parent().parent().parent().parent();
	var q = '';
	var i = 0;
	$('#paddtop input[@type=text]').each(function() {
		var id = $(this).attr('id_val');
		var k = $(this).val(); 
		$(this).val(0);
		if (k!=0) {
			q += id+':'+k+';';					   
			i++;
		}	
	});
	$.post('/ajax/add_cvot.php', {"q":q}, function(data) {
		if (data!='') addMessage(data);
		p.unblock();
		$('#kcont').load('/ajax/cart.php');
	});								   	
}
function addCOL(_this) {
	$(_this).parent().parent().block({  
	            message: '<img src="/images/busy1.gif" /><br><b>Добавляю...</b>',  
	            css: { 'padding':'5px 10px', border: '2px solid #989898', width: '100px'},
		    overlayCSS:  { backgroundColor:'#ADADAD'}
	        });	
	var p = $(_this).parent().parent();
	var q = '';
	var i = 0;
	$('#i_colors input[@type=text]').each(function() {
		var id = $(this).attr('id_val');
		var k = $(this).val(); 
		$(this).val(0);
		if (k!=0) {
			q += id+':'+k+';';					   
			i++;
		}	
	});
	$.post('/ajax/add_col.php', {"q":q}, function(data) {
		if (data!='') addMessage(data);
		p.unblock();
		$('#kcont').load('/ajax/cart.php');
	});								   	
}
function addFC(_this, id) {
	$(_this).parent().parent().parent().parent().parent().block({  
	            message: '<img src="/images/busy1.gif" /><br><b>Добавляю...</b>',  
	            css: { 'padding':'5px 10px', border: '2px solid #989898', width: '100px'},
		    overlayCSS:  { backgroundColor:'#ADADAD'}
	        });	
	var p = $(_this).parent().parent().parent().parent().parent();
	var q = '';
	var i = 0;
	$('#paddtop input[@type=text]').each(function() {
		var id = $(this).attr('id_val');
		var k = $(this).val(); 
		$(this).val(0);
		if (k!=0) {
			q += id+':'+k+';';					   
			i++;
		}	
	});
	$.post('/ajax/add_fc.php', {"id":id}, function(data) {
		if (data!='') addMessage(data);
		p.unblock();
		$('#kcont').load('/ajax/cart.php');
	});								   	
}
function addItem(_this, id) {
	$(_this).parent().parent().parent().parent().parent().block({  
	            message: '<img src="/images/busy1.gif" /><br><b>Добавляю...</b>',  
	            css: { 'padding':'5px 10px', border: '2px solid #989898', width: '100px'},
		    overlayCSS:  { backgroundColor:'#ADADAD'}
	        });	
	var p = $(_this).parent().parent().parent().parent().parent();
	var kol = $('#is').val();
	$.post('/ajax/add_item.php', {"id":id, 'kol':kol}, function(data) {
		if (data!='') addMessage(data);
		p.unblock();
		$('#kcont').load('/ajax/cart.php');
		$('#is').val(0);
	});								   	
}

function addIspolItem(_this, id, key) {
	var iid = id;
	$(_this).parent().parent().block({  
	            message: '<img src="/images/busy1.gif" /><br><b>Добавляю...</b>',  
	            css: { 'padding':'5px 10px', border: '2px solid #989898', width: '100px'},
		    overlayCSS:  { backgroundColor:'#ADADAD'}
	        });	
	var p = $(_this).parent().parent();
	var q = '';
	var i = 0;
	$('input[@ob_id='+key+']').each(function() {
		var id = $(this).attr('id_val');
		var k = $(this).val(); 
		$(this).val(0);
		if (k!=0) {
			q += id+':'+k+';';					   
			i++;
		}	
	});
	$.post('/ajax/add_ii.php', {"q":q, 'id':iid, 'ob_id':key}, function(data) {
		if (data!='') addMessage(data);
		p.unblock();
		$('#kcont').load('/ajax/cart.php');
	});								   	
}

function del_vic(_this, key) {
	$.get('/ajax/del_vic.php?id='+key, function(data) {if (data!=0) $(_this).parent().parent().hide('fast').empty();$('#kcont').load('/ajax/cart.php');});
}
function del_cvot(_this, key) {
	$.get('/ajax/del_cvot.php?id='+key, function(data) {if (data!=0) $(_this).parent().parent().hide('fast').empty();$('#kcont').load('/ajax/cart.php');});
}

function del_fc(_this, key) {
	$.get('/ajax/del_fc.php?id='+key, function(data) {if (data!=0) $(_this).parent().parent().hide('fast').empty();$('#kcont').load('/ajax/cart.php');});
}	
function del_item(_this, key) {
	$.get('/ajax/del_item.php?id='+key, function(data) {if (data!=0) $(_this).parent().parent().hide('fast').empty();$('#kcont').load('/ajax/cart.php');});
}
function del_oic(_this, key) {
	$.get('/ajax/del_oic.php?id='+key, function(data) {if (data!=0) $(_this).parent().parent().hide('fast').empty();$('#kcont').load('/ajax/cart.php');});
}			   

function addMessage(data) {
	if (data!='0') {
		var div = $('<div style="position:relative;top:0;border:2px solid #c4c0c3;padding:20px;background:#f6f1f5;color:#822c5d"><div style="font-size:18px;padding-bottom:5px">Добавлено в корзину:</div>'+data+'</div>');
		$('#messages').append(div);
		setTimeout(function() {div.fadeOut("400")}, 3000);
	}
}
function headerHackIe() {	 
	if ($('#head_l').width()<620)
		$('#head_l').css('width', '620px');
	else
		$('#head_l').css('width', 'auto');

	if ($('#head_rt1').width()>379)
		$('#head_rt1').css('width', '379px');
	else
		$('#head_rt1').css('width', 'auto');

	if ($('#head_rt2').width()>484)
		$('#head_rt2').css('width', '484px');
	else
		$('#head_rt2').css('width', 'auto');
		
	if ($('#head_rt3').width()>395)
		$('#head_rt3').css('width', '395px');
	else
		$('#head_rt3').css('width', 'auto');
	
	if ($('#head_rb').width()>541)
		$('#head_rb').css('width', '541px');
	else
		$('#head_rb').css('width', 'auto');
		
}		

function bubbling_no(e) {
	e = bubbling_ie(e); /* for ie */
	if (!e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}
function bubbling_ie(e) {
	if (!e) var e = window.event;
	return e;
} 
function toggle(e, _this, el) {
	bubbling_no(e);
	var mappos = {};  
	mappos = $(_this).position(); 
	$("#"+el).click(function(e) {
		bubbling_no(e);
	});
	$('#'+el).css({
		'right': '30px',
		'top': (mappos['top']+20)+'px'
	}).show();
	$(document).click(function() {
		$('#'+el).hide();
	});
}	
var show_tooltip = [];
function tooltip (zn, _this, el, pos, x, y) {
	if (show_tooltip[zn]>0) {
		var mappos = {};  
		mappos = $(_this).position();
		if (pos == 1) {
			$('#'+el).css({
				'right': '30px',
				'top': (mappos['top']+y)+'px'
			}).show();
		}  else {
			$('#'+el).css({
				'left': (mappos['left']+x)+'px',
				'top': (mappos['top']+y)+'px'
			}).show();
		}
	}
}	  
var save = false;
function showSave() {
	if (!save) {
		$('#save').html('<a href=# onclick="recall_cart();return false;"><img src="/images/save.jpg"></a>&nbsp;&nbsp;');
		$('#save').show('slow');  
		
		save = true;
	}	
}														  

function recall_cart() {																   
	$('#cart_full').block({  
        message: '<img src="/images/busy1.gif" /> <b>Пересчитываем</b>',  
        css: { background: '#FFFFFF'},
	    overlayCSS:  { backgroundColor:'#ADADAD'}
    });
	$('#recall_form').ajaxSubmit({success: function(responseText) {
		$('#bg').load('/ajax/cart.php');
		$('#tbl').load('/ajax/cart_full.php', function() {save=false;$('#save').hide('slow');inp();$('#cart_full').unblock();});
	}});	
}

function inp() {
	$('.inp').change(function() {
		$(this).attr('value', Math.floor($(this).attr('value')));
	});	
	$('.inp').click(function() {
		showSave();		
	});
}
