$(document).ready(function(){
	set_table();

    $('#map_head').corner('tl 6px').corner('tr 6px');
    $('#map_out').corner('tr 6px').corner('br 6px').corner('bl 6px');
});


function set_table()
{
	$('table.spisok td').mouseover(
	function()
	{
		$(this).parent().addClass('hover');
	}
	)

	$('table.spisok td').mouseout(
	function()
	{
		$(this).parent().removeClass('hover').removeClass('show');
	}
	)

	$('table.spisok td').click(
	function(event)
	{
		$('div.add_to_cart_over' ,$(this).parent()).toggle();
if($(this).parent().hasClass('clicked'))
{
$(this).parent().removeClass('clicked')
}
else
{
$(this).parent().addClass('clicked')
}
	}
	)

	$('div.add_to_cart_over a').bind('click', function(event){
		event.stopPropagation();
		event.cancelBubble = true;
		
		if($(this).get(0).id!='')
		{
			if($(this).text() == 'Добавить к заказу')
			{
				AddToCart('/store/',$(this).get(0).id);
				$(this).text('Удалить заказ');
				$(this).parent().parent().addClass('remove');
			}
			else
			{
				DeleteFromCart('/store/',$(this).get(0).id);
				$(this).text('Добавить к заказу');
				$(this).parent().parent().removeClass('remove');
			}
		}
		return false;
	});
	
	
	
	$('div.add_to_cart').mouseover(
	function()
	{
		$(this).addClass('add_to_cart_hover');
	}
	)
	$('div.add_to_cart').mouseout(
	function()
	{
		$(this).removeClass('add_to_cart_hover');
	}
	)

check_form();
}


function show_spinner()
{
	$('#spinner').hide();
	$('#spinner').css('visibility','hidden');
	$('#spinner').show();
	
	if($('#spinner').get(0).r)
	{}
	else
	{
		t1 = $('#spinner').get(0).offsetTop;
		$('#spinner').get(0).r = t1;
	}
	
	
	t1 = $('#spinner').get(0).r;
	
	t = $(window).scrollTop();
	t2 = t + t1 + 'px';

	$('#spinner').css('top',t2);
	
	$('#spinner').css('visibility','visible');
}

function hide_spinner()
{
	$('#spinner').hide();
}


function check_form(name)
{
	$(':text',name).each(
	function()
	{
		this.val = this.value;
		$(this).focus(
		function()
		{
			if(this.value==this.val)
				this.value = '';
		}
		)
		$(this).blur(
		function()
		{
			if(this.value=='')
				this.value = this.val;
		}
		)
	}
	)
}
