var base_url = '/';

$(document).ready(function ()
{
	// delete me (msg)
	$('body').live('deleteMe', function ()
	{
		setTimeout(function () { $('.deleteMe').hide(1500); }, 2000);
		setTimeout(function () { $('.deleteMe').remove(); }, 4000);
	});
	
	// tooltip
	$('.tooltip').live('mouseover', function (e)
	{
		$('#tooltip').html($(this).attr('title'));
		$('#tooltip').css('display', 'block');
		$('#tooltip').css('left', (e.pageX+5)).css('top', (e.pageY+5));
		$(this).attr('title', '');
	});
	$('.tooltip').live('mousemove', function (e)
	{
		$('#tooltip').css('left', (e.pageX+5)).css('top', (e.pageY+5));
	});
	$('.tooltip').live('mouseout', function (e)
	{
		$('#tooltip').css('display', 'none');
		$(this).attr('title', $('#tooltip').html());
	});
	$('body').append('<div id="tooltip" style="display: none;"></div>');
	
	
	// ajax
	$('body').bind('checkDomains', function () 
	{
		$('.domain_check').each(function ()
		{
			var domain_row = this;
			$.ajax(
			{
				url: '/ajax'+base_url+'domain/'+$(domain_row).find('.domainname').html(),
				type: 'get',
				success: function (data)
				{
					$(domain_row).find('.status').html(data);
				}
			});
		});
	});
	
	$('a.ajax').live('click', function ()
	{
		var self = this;
		$.ajax(
		{
			url: '/ajax' + $(self).attr('href').replace('http://'+window.location.hostname, ''),
			success: function (data) 
			{
				$('#'+$(self).attr('name')).html(data);
				$('body').trigger('checkEditable');
			}
		});
		return false;
	});

	$('form.ajax input[type="submit"]').live('click', function ()
	{
		var self = this;
		$.ajax(
		{
			url: '/ajax' + $(self).closest('form.ajax').attr('action'),
			data: $(self).closest('form.ajax').serialize(),
			type: 'post',
			success: function(data)
			{
				$('#'+$(self).closest('form.ajax').attr('name')).html(data);
				$('body').trigger('checkEditable');
			}
		});
		return false;
	});
	
	$('.deleteProduct').live('click', function ()
	{
		var self = this;
		$.ajax(
		{
			url: '/ajax' + $(self).attr('href').replace('http://'+window.location.hostname, ''),
			success: function (cart) 
			{
				$('#'+$(self).attr('name')).html(cart);
				
				if($('.product_overview').length)
				{
					$.ajax(
					{
						url: '/ajax/shop/overview/step3',
						success: function (shop)
						{
							$('#shop').html(shop);
						}
					});
				}
			}
		});
		return false;
	});
	
	$('.add_credits').live('click', function ()
	{
		$.ajax(
		{
			url: '/ajax/shop/cart/addcredits/'+$('#credits').val(),
			success: function (data) 
			{
				$('#cart').html(data);
			}
		});
		return false;
	});
	
	$('head').append('<style type="text/css">.step3savechanges { display:none; }</style>');
	
	var timer = 0;
	$('.product_overview input').live('keyup', function ()
	{
		clearTimeout(timer);
		timer = setTimeout(function () { $('.step3savechanges').trigger('click'); }, 1500);
	});
	
	$('#menu a').bind('click', function () {
		$('#menu a').removeClass('active');
		$(this).addClass('active');
	});
});