$(function() {
    var interval = 60;
    var duration = 500;
    var shake = 10;
    var vibrateIndex = 0;
    var selector = $('#mouse_pointer');
    $(document).ready(
	function() {
	    vibrateIndex = setInterval(vibrate, interval);
	    setTimeout(stopVibration, duration);
	});

	$('#send_online_order').mouseout(
	function() {
	    vibrateIndex = setInterval(vibrate, interval);
	    setTimeout(stopVibration, duration);
	    $('#mouse_pointer').css("display","block");
	});

    var vibrate = function() {
        $(selector).stop(true, false)
	.css({ position: 'relative',
	    left: 20 + Math.round(Math.random() * shake) - ((shake + 1) / 2) + 'px',
	    top: 60 + Math.round(Math.random() * shake) - ((shake + 1) / 2) + 'px'
	});
    }

    var stopVibration = $('#send_online_order').mouseover(
	function() {
	    clearInterval(vibrateIndex);
	    $(selector).stop(true, false)
		.css({ position: 'relative', left: '20px', top: '60px' });
	    $('#mouse_pointer').css("display", "none");
	});
});

$(function() {
    var interval = 120;
    var duration = 100;
    var shake = 13;
    var vibrateIndex = 0;
	var selector = $('#mouse_pointer_ineedhelp');
	$(document).ready(
	function() {
	    vibrateIndex = setInterval(vibrate, interval);
	    setTimeout(stopVibration, duration);
	});

	$('#send_online_order_ineedhelp').mouseout(
	function() {
	    vibrateIndex = setInterval(vibrate, interval);
	    setTimeout(stopVibration, duration);
	    $('#mouse_pointer_ineedhelp').css("display", "block");
	});

	var vibrate = function() {
	    $(selector).stop(true, false)
	.css({ position: 'relative',
	    left: 20 + Math.round(Math.random() * shake) - ((shake + 1) / 2) + 'px',
	    top: 60 + Math.round(Math.random() * shake) - ((shake + 1) / 2) + 'px'
	});
	}

	var stopVibration = $('#send_online_order_ineedhelp').mouseover(
	function() {
	    clearInterval(vibrateIndex);
	    $(selector).stop(true, false)
		.css({ position: 'relative', left: '20px', top: '60px' });
	    $('#mouse_pointer_ineedhelp').css("display", "none");
	});

});
