var nextBubbleId = 0;
var interval = 100;
var bubbleCount = 5;
var timeBasedTaskList = {};
var scrollDistance = 4;
var scrollInitialY = null;
var scrollInitialTop = null;
var strCurrentUrl = null;
$(function(){
	//prepare plants
	$('div#container').prepend('<div class="plants" id="plantsTopLayer1"></div><div class="plants" id="plantsTopLayer2"></div><div class="plants" id="plantsTopLayer3"></div>')
	$('div#container').append('<div class="plants" id="plantsLayer1"></div><div class="plants" id="plantsLayer2"></div><div class="plants" id="plantsLayer3"></div>')
	//modals
		$('#modal').jqm({modal:true,overlay:80,onShow:function(hash){hash.o.fadeIn('fast',function(){hash.w.fadeIn();})},onHide:function(hash){hash.w.fadeOut('fast',function(){hash.o.fadeOut()}) } });
	$('#aCustomise').click(function(){
		//$('body').prepend('<div id="modal" class="jqmWindow"><a href="#" class="jqmClose">Close</a><p>Hello!</p></div>');
		$('#modal').jqmShow()
		return false;
	})
	$('#modalAlert').jqm({modal:true,overlay:80,onShow:function(hash){$(document).keydown(captureReturn);hash.o.fadeIn('fast',function(){hash.w.fadeIn();})},onHide:function(hash){$(document).unbind('keydown',captureReturn);hash.w.fadeOut('fast',function(){hash.o.fadeOut()}) } });
	window.alert = function(strHeading,strSubheading,strMessage,strClass) {
		$('#alertHeading').html(strHeading);
		$('#alertSubheading').html(strSubheading);
		$('#alertMessage').html(strMessage);
		$('#modalAlert .inner').removeClass('info').removeClass('error');
		$('#modalAlert .inner').addClass(strClass);
		$('#modalAlert').jqmShow();
		return false;
	}
	function captureReturn(evt){
		if (evt.keyCode == 13 || evt.keyCode == 32) {
			$('#modalAlert').jqmHide();	
		} else {
			return true;
		}
	}
	//links
	function loadAjax(url,$srcEl) {
		//pulseBites();
		$('div#loading').fadeIn('normal',function(){
			$.ajax( {'type':'get',url:url,success:
				function(data)	{
					$('div#nav ul li a, div#content div#secondaryNav ul li a').removeClass('active');
					$srcEl.addClass('active');
					$('#loadPoint').html(data);
					setTint();
					$('.tint').css({'background-color':$.cookie('tint')});
					prepareScrollbars();
					prepareEmailForm();
					prepareFileForm();
					prepareExternalLinks();
					$('a.aContact').click(function(){
						loadAjax('ajax/contact.html',$(this));
						return false;
					});
					$('#playPong').click(ss.games.pong.preparePong);
					$('div#loading').fadeOut('slow');
					$('#imgAntony').mouseover(function(){this.src='img/antony.gif';});
					//stopPulsing();
					strCurrentUrl = url;
				}
			});	
		});
	}
	function prepareExternalLinks() {
		$('a[rel=external]').unbind('click').click(function(){
			window.open(this.href);
			return false;
		});
	};
	function prepareFileForm () {
		$('form.file .submit').click(validateForm);
		$('form.file').submit(validateForm);
		function validateForm() {
			booErrors = false;
			strErrMsg = '<ul>';
			var file = $(this).parents('form').find('.file').val();
			if (file == '') {
				strErrMsg += '<li>Please select a file.</li>'
				booErrors = true;
			}
			switch (file.substring(file.length, file.length - 3)) { 
				case "bmp" : 
					break; 
				case "jpg" : 
					break; 
				case "gif" : 
					break;
				case "png" : 
					break;
				default : 
					strErrMsg += '<li>Please use the right kind of file (.bmp, .jpg, .gif or .png).</li>'
					booErrors = true;
			};
			strErrMsg += '</ul>';
			if (booErrors) {
				alert('Oops! There seems to be a problem&hellip;','Please fix me!',strErrMsg,'error')
				return false;
			}
			$('iframe#fileSubmit').load(function(){
				$('#alertMessage').html('Converting image to HTML...');
				var sObj = String($(this).contents().text());
				var obj = eval('(' + sObj + ')');
				var imageUri = obj.imageUri;
				$.ajax({
					dataType : 'json',
					url : '/services/Services.asmx/Img2Html',
					data : {'imageURL':imageUri},
					success : function(obj) {
						$('#fullContent .copy').html('<p>' +
						'<strong>IMG2HTML</strong>' +
						'Your code was generated!' +
						'<div class="third"><p>Here is the code:</p>' +
						'<textarea id="txtCode">objI2H = ' + sObj + ';sImg = htmlImage(objI2H.colour_array,objI2H.pixel_array);</textarea><input type="button" value="Copy to clipboard" id="btnCopyCode"/></div>' +
						'<div class="third"><p>Here is the CSS you need on your page:</p>' +
						'<textarea>table.tableImage {line-height:1px;font-size:1px;margin: 1em; ;padding:0;overflow:hidden;border-collapse:collapse;}\ntable.tableImage td {line-height:1px;font-size:1px;height:1px;margin:0;padding:0;overflow:hidden;border:none;}</textarea></div>' +
						'<div class="third"><p>Here is the JS you need to decompress it:</p>' +
						'<textarea>function htmlImage(a,b){var c=\'<table cellpadding="0" cellspacing="0" border="0" style="background-color:#\'+a[0]+\';width:\'+(b[0].length)+\'px;" class="tableImage">\';for(var i=0,j=b.length;i<j;i++){var d=\'<tr>\';for(var k=0,l=b[i].length;k<l;k++){d+=\'<td\';if(b[i][k][0]){d+=\' colspan="\'+b[i][k][1]+\'" bgcolor="#\'+a[b[i][k][0]]+\'"\';}else if(b[i][k]>1){d+=\' colspan="\'+b[i][k]+\'"\';}else if(b[i][k]<0){d+=\' bgcolor="#\'+a[b[i][k]*-1]+\'"\';};d+=\'>&nbsp;</td>\';};d+=\'</tr>\';c+=d;};c+=\'</table>\';return c;}</textarea></div>' +
						'<p>And here is an example of the rendered HTML image:</p></p>' +
						'<div id="img2htmlRendering"></div>')
						$('#img2htmlRendering').img2html(obj.colour_array,obj.pixel_array);

						$('#btnCopyCode').click(function() { copyToClipboard( $('#txtCode').val() ) });

						// $('#img2htmlRendering').html(img2html(obj.colour_array,obj.pixel_array));
						$('#img2html').remove()
						$('#modalAlert').jqmHide();
					}
				});
				
			})
			alert('One Moment Please','Loading','Uploading your image','info');
			$('form.file').submit();
			return false;
		};
	}
	function prepareEmailForm() {
		$('form.email .submit').click(validateForm);
		$('form.email').submit(validateForm);			
		function validateForm() {
			var name = $(this).parents('form').find('.name').val();
			var email = $(this).parents('form').find('.email').val();
			var message = $(this).parents('form').find('.message').val();
			booErrors = false;
			strErrMsg = '<ul>';
			if (name == '') {
				strErrMsg += '<li>Please enter your name.</li>'
				booErrors = true;
			}
			if (email == '') {
				strErrMsg += '<li>Please enter your email address.</li>'
				booErrors = true;
			} else if (!isEmail(email)) {
				strErrMsg += '<li>Your email address appears to be invalid.</li>'
				booErrors = true;
			}
			if (message == '') {
				strErrMsg += '<li>Please enter your message.</li>'
				booErrors = true;
			}
			strErrMsg += '</ul>';
			if (booErrors) {
				alert('Oops! There seems to be a problem&hellip;','Please fix me!',strErrMsg,'error')
				return false;
			}
			$.ajax({
				url:'/Img2Html/Img2Html.asmx/SendEmail',
				type:'POST',
				data: {
					senderName:$(this).parents('form').find('.name').val(),
					senderEmail:$(this).parents('form').find('.email').val(),
					subject:'feedback',
					body:$(this).parents('form').find('.message').val(),
					toName:'info',
					toEmail:'info@silversquid.net'
				},
				success: function() {
					alert('Yes!','Message sent','Your message has been sent successfully, and you can expect to hear back from us very soon.','info')
				},
				error: function() {
					alert('Uh-Oh','Something Went Wrong','There was a problem and your message has not been sent. Please try again. We\'re sorry for messing it up.','error');
				}
			});
			return false;
		}
	}
	$('#aHome').click(function(){
		loadAjax('ajax/home.html',$(this));
		return false;
	});
	$('#aWho').click(function(){
		loadAjax('ajax/who.html',$(this));
		return false;
	});
	$('#aWhy').click(function(){
		loadAjax('ajax/why.html',$(this));
		return false;
	});
	$('#aWhat').click(function(){
		loadAjax('ajax/what.html',$(this));
		return false;
	});
	$('#aToys').click(function(){
		loadAjax('ajax/toys.html',$(this));
		return false;
	});
	$('#aSol').click(function(){
		loadAjax('ajax/sol.html',$(this));
		return false;
	});
		$('#aSol').hover(function(){
			$(this).find('ul.dropdown').slideDown();
			return false;
		},	function(){
				$(this).find('ul.dropdown').slideUp();
				return false;
		});
	$('#aImg2Html').click(function(){
		loadAjax('ajax/img2html.html',$(this));
		return false;
	});
		$('#aImg2Html').hover(function(){
			$(this).find('ul.dropdown').slideDown();
			return false;
		},	function(){
				$(this).find('ul.dropdown').slideUp();
				return false;
		});
	$('#aContact').click(function(){
		loadAjax('ajax/contact.html',$(this));
		return false;
	});
	$('#aFeedback').click(function(){
		loadAjax('ajax/feedback.html',$(this));
		return false;
	});
	//colour control
	var fb = $.farbtastic('#colorpicker');
	fb.linkTo(function(color){
		if ($('#radUntinted')[0].checked) {
			return false;
		}
		$('.tintBorder').css({'border-color':color});
		$('.tint').css({'background-color':color});
		$('.tintText').css({'color':color});
		$.cookie('tint',color)
	});
	function setTint() {
		if ($.cookie('tint') && $.cookie('tint') != 'transparent') {
		 	fb.setColor($.cookie('tint'));
		} else {
			$('.tintBorder').css({'border-color':'transparent'});
			$('.tint').css({'background-color':'transparent'});
			$('.tintText').css({'color':'#FF5100'});
		}
	}
	$('#radTinted').click(function(){
		if (this.checked) {
			$('#radUntinted').parents('label').removeClass('selected');
			$(this).parents('label').addClass('selected');
			if (!$.cookie('tint') || $.cookie('tint') == 'transparent') {
				color = '#FF5100';
				fb.setColor('#FF5100');
				setTint();
				$('.tintBorder').css({'border-color':color});
				$('.tint').css({'background-color':color});
				$('.tintText').css({'color':color});
				$.cookie('tint',color)
			} else {
				fb.setColor($.cookie('tint'));
			}
		}
	});
	$('#radUntinted').click(function(){
		if (this.checked) {
			$('#radTinted').parents('label').removeClass('selected');
			$(this).parents('label').addClass('selected');
			$.cookie('tint','transparent')
			setTint();			
		}
	});
	if (!$.cookie('tint') || $.cookie('tint') == 'transparent') {
		$('#radTinted')[0].checked = false;
		$('#radUntinted')[0].checked = true;
		$('#radTinted').parents('label').removeClass('selected');
		$('#radUntinted').parents('label').addClass('selected');
	} else {
		$('#radUntinted')[0].checked = false;
		$('#radTinted')[0].checked = true;
		$('#radUntinted').parents('label').removeClass('selected');
		$('#radTinted').parents('label').addClass('selected');
	}
	setTint();
	//parallax control
	$('#chkParallax').click(function(){
		if (this.checked) {
			$.cookie('parallax',1)
			$(document).mousemove(moveScreen);
			//$('div#container').jparallax({'mouseResponse':false});
		} else {
			$.cookie('parallax',0)
			$(document).unbind('mousemove',moveScreen);
		}
	});
	if ($.cookie('parallax') == 1) {
		$(document).mousemove(moveScreen);
		$('#chkParallax').checked = true;
	}
	//bubble control
	$('#chkBubbles').click(function(){
		if (this.checked) {
			$.cookie('bubbles',1)
			if ($.cookie('bubblesCount') > 0) {
				$('#selBubbleCount').val($.cookie('bubblesCount'));
			} else {
				$('#selBubbleCount').val('5');
				$.cookie('bubblesCount',5)	
			}
			$('#divBubbleCount').slideDown();
			$('div#container').append('<div id="bubbleLayer"><div id="bubbles"></div></div>');
			createNewBubble($.cookie('bubblesCount'));
			timeBasedTaskList.animateBubbles = animateBubbles;			
		} else {
			$('.bubble').hide('explode',{},1000).remove();
			$.cookie('bubbles',0)
			$('#divBubbleCount').slideUp();
			$('#bubbleLayer').remove();
			timeBasedTaskList.animateBubbles = null;
		}
	});
	$('#selBubbleCount').change(function(){
		$.cookie('bubblesCount',$(this).val());
		/*
			TODO check current bubble count and add/subtract bubbles
		*/
	})
	if ($.cookie('bubbles') == 1) {
		bubbleCount = $.cookie('bubblesCount');
		$('#divBubbleCount').show();
		$('#selBubbleCount').val($.cookie('bubblesCount'));
		$('div#container').append('<div id="bubbleLayer"><div id="bubbles"></div></div>');
		createNewBubble(bubbleCount);
		timeBasedTaskList.animateBubbles = animateBubbles;
	}
	function prepareScrollbars() {
		if ((pxToInt($('div#primarySplitContent div.content, div#fullContent div.content')[0].scrollHeight) - 20) <= pxToInt($('div#primarySplitContent div.content, div#fullContent div.content').height())) {
			$('.track .handle').hide();
			$('.scrollbarSurround').addClass('scrollbarDisabled');
			
			return false;
		}
		//make handle the right size
		var $target = $('div#primarySplitContent div.content, div#fullContent div.content');
		var contentTravel = $target[0].scrollHeight - $target.height();
		var fraction = $target[0].scrollHeight / $target.height();
		var trackHeight = $('.track').height() - pxToInt($('.track').css('margin-top')) - pxToInt($('.track').css('margin-bottom'));
		$('.track .handle .button').height(trackHeight / fraction);
		$('.track .handle').height((trackHeight / fraction) - 2);
		
		//scrollbar functions
		function scrollTrack(evt) {
			//scroll up one block
			//newTop = $('.track .handle').css('top',newTop);
		}
		function scrollHandle(evt) {
			var $target = $('div#primarySplitContent div.content, div#fullContent div.content');
			var intYMovement = (-1 * (scrollInitialY - evt.pageY));
			newTop =  scrollInitialTop + intYMovement;
			var trackHeight = $('.track').height() - pxToInt($('.track').css('margin-top')) - pxToInt($('.track').css('margin-bottom')) - $('.track .handle').height() + 32;
			var contentDistance = $target[0].scrollHeight - $target.height();
			if (newTop < 12) {
				newTop = 12;
				$('.track .handle').css('top',newTop);
				$target.scrollTop(0);
			} else if (newTop >= /*218*/trackHeight) {
				newTop = trackHeight;
				$('.track .handle').css('top',newTop);
				$target.scrollTop(contentDistance);
			} else {
				$('.track .handle').css('top',newTop);
				newTop = newTop * (contentDistance / trackHeight) -15;
				$target.scrollTop(newTop);
			}
		}
		function scrollUp(velocity) {
			var scrollDistance = 4;
			if (velocity) {
				scrollDistance = velocity * 2;
			}
			var $target = $('div#primarySplitContent div.content, div#fullContent div.content');
			var trackHeight = $('.track').height() - pxToInt($('.track').css('margin-top')) - pxToInt($('.track').css('margin-bottom')) - $('.track .handle').height() + 32;
			var trackOffset = pxToInt($('.track').css('margin-top'));
			var contentDistance = $target[0].scrollHeight - $target.height();
			if (pxToInt($('.track .handle').css('top')) == 12) {
				return false;
			}
			var newTop = pxToInt($('.track .handle').css('top')) - scrollDistance;
			if (newTop <= 12) {
				//at the top
				newTop = 12;
				$('.track .handle').css('top',newTop);
				$target.scrollTop(0);
				timeBasedTaskList.scrollUp = null;
				return true;
			} else {
				$('.track .handle').css('top',newTop);
				newTop = newTop * (contentDistance / trackHeight) -15;
				$target.scrollTop(newTop);
				return true;
			}
		};
		function scrollDown(velocity) {
			var scrollDistance = 4;
			if (velocity) {
				scrollDistance = velocity * 2;
			}
			var $target = $('div#primarySplitContent div.content, div#fullContent div.content');
			var trackHeight = $('.track').height() - pxToInt($('.track').css('margin-top')) - pxToInt($('.track').css('margin-bottom')) - $('.track .handle').height() + 32;
			var trackOffset = pxToInt($('.track').css('margin-top'));
			var contentDistance = $target[0].scrollHeight - $target.height();
			if (pxToInt($('.track .handle').css('top')) == 218) {
				return false;
			}
			var newTop = pxToInt($('.track .handle').css('top')) + scrollDistance;
			if (newTop >= trackHeight){	//trackHeight) {
				//at the bottom
				newTop = trackHeight;
				$('.track .handle').css('top',newTop);
				$target.scrollTop(contentDistance);
				timeBasedTaskList.scrollDown = null;
				return true;
			} else {
				$('.track .handle').css('top',newTop);
				newTop = newTop * (contentDistance / trackHeight) -15;
				$target.scrollTop(newTop);
				return true
			}
		}
		//scrollbar events
		$('div#fullContent, div#primarySplitContent').mousewheel(function(evt,delta){
			if (delta < 0) {
				delta *= -1;
					return !scrollDown(delta);
			} else {
					return !scrollUp(delta);
			}
		});
		$('.scrollbar .up').mousedown(function(){
			$(this).addClass('activeButton')
			timeBasedTaskList.scrollUp = scrollUp;	
			$(document).mouseup(function(){
				$('.scrollbar .activeButton').removeClass('activeButton')
				timeBasedTaskList.scrollUp = null;
			});
		});
		$('.scrollbar .down').mousedown(function(){
			$(this).addClass('activeButton')
			timeBasedTaskList.scrollDown = scrollDown;
			$(document).mouseup(function(){
				$('.scrollbar .activeButton').removeClass('activeButton')
				timeBasedTaskList.scrollDown = null;
			});
		});
		$('.scrollbar .handle').mousedown(function(evt){
			$(this).find('.button').addClass('activeButton')
			scrollInitialY = evt.pageY;
			scrollInitialTop = pxToInt($(this).css('top'));
			$(document).mousemove(scrollHandle);
			$(document).mouseup(function(){
				$('.scrollbar .activeButton').removeClass('activeButton')
				scrollInitialY = null;
				scrollInitialTop = null;
				$(document).unbind('mousemove',scrollHandle);
			})
			return false;
		})
		//$('.scrollbar .track').click(scrollTrack);
	}
	//start timed tasks
	setInterval(timeBasedTasks,interval);
	$('#aHome').click();//loadAjax('/ajax/img2html.html',$('dsf'));	
	//try to fix overlapped elements and events
	// $('div#plantsTopLayer1').mouseover(function(evt){
	// 	$('div#panel').mouseover();
	// })
})
function isEmail(str) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) return true;
	return false;
}
function timeBasedTasks () {
	$.each(timeBasedTaskList,function(a,b){
		if (b) b();
	})
	// for (var i=0, j=timeBasedTaskList.length; i < j; i++) {
	// 		timeBasedTaskList[i]();
	// 	};
}
function pxToInt(str) {
	return parseInt(String(str).replace('px',''))
}
function moveScreen(evt) {
	var intX = evt.pageX + ($('div#bubbles').width()/2);
	var intLeft = $('div#bubbles').width() - intX;
	intLeft /= 4;
	//$('div#bubbles').css('left',intLeft + 'px');
	intLeft /= 8;
	$('div#plantsTopLayer3').css('background-position',intLeft + 'px top');
	$('div#plantsLayer3').css('background-position',intLeft + 'px bottom');
	intLeft /= 2;
	$('div#plantsTopLayer2').css('background-position',intLeft + 'px top');
	$('div#plantsLayer2').css('background-position',intLeft + 'px bottom');
	intLeft /= 2;
	$('div#plantsTopLayer1').css('background-position',intLeft + 'px top');
	$('div#plantsLayer1').css('background-position',intLeft + 'px bottom');
}
function animateBubbles() {
	$('.bubble').each(function(){
		elBubble = $(this);		
		if (elBubble.data('delay') > 0) {
			elBubble.data('delay',elBubble.data('delay')-interval);
			if (elBubble.data('delay') < 0) {
				elBubble.data('delay',0)
			}
			return false;
		}
		elBubble.css('top',elBubble.position().top - elBubble.data('speed'));
		intLeft = parseInt(elBubble.position().left);
		intOriginalLeft = elBubble.data('originalLeft');
		intSway = elBubble.data('sway');
		intHalfSway = intSway/2;
		intQuarterSway = intHalfSway/2;
		if (elBubble.data('dir') == 'l') {
			if (intLeft <= (intOriginalLeft - intHalfSway)) {
				//Do nothing
			} else if ((intLeft + intQuarterSway > (intOriginalLeft + intHalfSway)) || (intLeft - intQuarterSway < (intOriginalLeft - intHalfSway))) {
				//getting within a quarter
				elBubble.css('left',intLeft - 1)
			} else {
				elBubble.css('left',intLeft - 2)
			}
			if (intLeft <= (intOriginalLeft - intHalfSway)) {
				elBubble.data('pauseCount',elBubble.data('pauseCount') + 1)
				if (elBubble.data('pauseCount') >= 3) {
					elBubble.data('dir','r');
					elBubble.data('pauseCount',0)
				}
			}	
		} else {
			if (intLeft >= (intOriginalLeft + intHalfSway)) {
				//Do nothing
			} else if ((intLeft + intQuarterSway > (intOriginalLeft + intHalfSway)) || (intLeft - intQuarterSway < (intOriginalLeft - intHalfSway))) {
				//getting within a quarter
				elBubble.css('left',intLeft + 1)
			} else {
				//not within 5
				elBubble.css('left',intLeft + 2)
			}
			if (intLeft >= (intOriginalLeft + intHalfSway)) {
				elBubble.data('pauseCount',elBubble.data('pauseCount') + 1)
				if (elBubble.data('pauseCount') >= 3) {
					elBubble.data('dir','l');
					elBubble.data('pauseCount',0)
				}
			}
		}
		//off screen?
		if (elBubble.position().top + elBubble.height() < 0 ) {
			elBubble.remove();
			nextBubbleId = elBubble[0].id;
			createNewBubble(1);
		}
	})
}
function createNewBubble(count) {
	for (var i=1, j=count; i <= j; i++) {
		if (nextBubbleId) {
			id = nextBubbleId;
		} else {
			if ($('.bubble').length == 0) {
				id = 'bubble1';
			} else {
				id = 'bubble' + ($('.bubble').length + 1);
			}	
		}
		var intDim = randomNumber(10,38);
		var intSway = randomNumber(4,30);
		var intLeft = randomNumber(intSway/2,$('#bubbles').width()-intDim-(intSway/2));
		var intDelay = randomNumber(0,2000);
		var intSpeed = randomNumber(1,10);
		var dir = randomNumber(0,1) == 0 ? 'l' : 'r';
		$('#bubbles').append('<div id="' + id + '" class="bubble"><img src="img/bubblesample1.png" width="' + intDim + '" height="' + intDim + '" alt="Bubblesample1"></div>')
		elBubble = $('#' + id);
		elBubble.css({'bottom':0-elBubble.height(),'left':intLeft,'height':intDim + 'px','width':intDim + 'px'});
		elBubble.data('originalLeft',intLeft).data('sway', intSway).data('dir',dir).data('pauseCount',0).data('delay',intDelay).data('speed',intSpeed);
		elBubble.click(function(){
			nextBubbleId = this.id;
			$(this).hide('explode',{},1000).remove();
			createNewBubble(1);
		})
	};
};
function pulseBites() {
	window.currentBite = 0;
	window.pulsing = true;
	$('span.squidBite span.pulse').fadeOut('slow',pulseBite);
};
function pulseBite() {
	 if (!window.pulsing) {
	 		return false;
	}
	$('span.squidBite span.pulse').fadeIn('slow',function(){
			$('span.squidBite span.pulse').fadeOut('slow',function(){
 			pulseBite();
 		})
 	})
	// 	var $bites = $('span.squidBite span.pulse');
	// 	if (window.currentBite >= $bites.length) {
	// 		window.currentBite = 0;
	// 	}
	// 	$bites.eq(window.currentBite).fadeIn('fast',function(){
	// 		$('span.squidBite span.pulse').eq(window.currentBite).fadeOut('fast',function(){
	// 			window.currentBite++;
	// 			pulseBite();
	// 		})
	// 	})
	
}
function stopPulsing() {
	window.pulsing = false;
}
function randomNumber(min,max) {
	return Math.floor((max-(min-1))*Math.random()) + min;
}