/* 
	Customized Spin script to add message.
	Customized by: Jarques Pretorius @ jpretorius.com
	Original by: Elliott Kember @ elliottkember.com
*/

$.fn.spin = function(speed_word){
	moz = $(this).css('-moz-transform');
	webkit = $(this).css('webkit-transform');
	already_rotating = ((moz != 'none' && webkit == '') || (moz == '' && webkit != 'none'))
	var number = 0;
	var speed = 0;
	if (already_rotating){
		return false;
	} else  if (speed_word == 'silly-fast'){
		speed = 7;
	} else if (speed_word == 'fast'){
		speed = 0.3;
	} else if (speed_word == 'slow'){
		speed = 0.1;
	} else if (typeof(speed_word) == 'number'){
		speed = speed_word / 10;
	}
	var self = this;
	
	$theObject = jQuery(self);

	$("body").append("<div class='spunday_info' style='display: none; position: fixed; bottom: 10px; right: 10px; background: #fff; padding: 10px; -moz-border-radius: 4px; -webkit-border-radius: 4px; color: #1f1f1f; font-family: Georgia; font-size: 14px'><a href='javascript:makeItStop()' style='color: #fff; background: #6CBDEB; font-style: Italic; padding: 3px'> Make it stop! </a></div>");
	setTimeout("$('.spunday_info').fadeIn(1000)", 1000);

$anim = setInterval(function(){
	number += speed;
	$($theObject).css('webkit-transform', 'rotate(-'+number+'deg)');
	$($theObject).css('-moz-transform', 'rotate(-'+number+'deg)');
  	}, 50)
}

function makeItStop() {
	clearInterval($anim);
	$($theObject).css('webkit-transform', 'rotate(-0deg)');
	$($theObject).css('-moz-transform', 'rotate(-0deg)');
	$('.spunday_info').fadeOut(1000)
}
