/* Spritely Plugin */
(function($){$._spritely={animate:function(options){var el=$(options.el);var el_id=el.attr('id');options=$.extend(options,$._spritely.instances[el_id]||{});if(options.play_frames&&!$._spritely.instances[el_id]['remaining_frames']){$._spritely.instances[el_id]['remaining_frames']=options.play_frames+1;}
if(options.type=='sprite'&&options.fps){var frames;var animate=function(el){var w=options.width,h=options.height;if(!frames){frames=[];total=0
for(var i=0;i<options.no_of_frames;i++){frames[frames.length]=(0-total);total+=w;}}
if($._spritely.instances[el_id]['current_frame']>=frames.length-1){$._spritely.instances[el_id]['current_frame']=0;}else{$._spritely.instances[el_id]['current_frame']=$._spritely.instances[el_id]['current_frame']+1;}
var yPos=$._spritely.getBgY(el);el.css('background-position',frames[$._spritely.instances[el_id]['current_frame']]+'px '+yPos);if(options.bounce&&options.bounce[0]>0&&options.bounce[1]>0){var ud=options.bounce[0];var lr=options.bounce[1];var ms=options.bounce[2];el.animate({top:'+='+ud+'px',left:'-='+lr+'px'},ms).animate({top:'-='+ud+'px',left:'+='+lr+'px'},ms);}}
if($._spritely.instances[el_id]['remaining_frames']&&$._spritely.instances[el_id]['remaining_frames']>0){$._spritely.instances[el_id]['remaining_frames']--;if($._spritely.instances[el_id]['remaining_frames']==0){$._spritely.instances[el_id]['remaining_frames']=-1;delete $._spritely.instances[el_id]['remaining_frames'];return;}else{animate(el);}}else if($._spritely.instances[el_id]['remaining_frames']!=-1){animate(el);}}else if(options.type=='pan'){if(!$._spritely.instances[el_id]['_stopped']){if(options.dir=='left'){$._spritely.instances[el_id]['l']=($._spritely.instances[el_id]['l']-(options.speed||1))||0;}else{$._spritely.instances[el_id]['l']=($._spritely.instances[el_id]['l']+(options.speed||1))||0;}
var bp_top=$._spritely.getBgY(el);$(el).css('background-position',$._spritely.instances[el_id]['l']+'px '+bp_top);}}
$._spritely.instances[el_id]['options']=options;window.setTimeout(function(){$._spritely.animate(options);},parseInt(1000/options.fps));},randomIntBetween:function(lower,higher){return parseInt(rand_no=Math.floor((higher-(lower-1))*Math.random())+lower);},getBgY:function(el){if($.browser.msie){var bgY=$(el).css('background-position-y')||'0';}else{var bgY=($(el).css('background-position')||' ').split(' ')[1];}
return bgY;},getBgX:function(el){if($.browser.msie){var bgX=$(el).css('background-position-x')||'0';}else{var bgX=($(el).css('background-position')||' ').split(' ')[0];}
return bgX;}};$.fn.extend({spritely:function(options){var options=$.extend({type:'sprite',do_once:false,width:null,height:null,fps:12,no_of_frames:2,stop_after:null},options||{});var el_id=$(this).attr('id');if(!$._spritely.instances){$._spritely.instances={};}
if(!$._spritely.instances[el_id]){$._spritely.instances[el_id]={current_frame:-1};}
$._spritely.instances[el_id]['type']=options.type;$._spritely.instances[el_id]['depth']=options.depth;options.el=this;options.width=options.width||$(this).width()||100;options.height=options.height||$(this).height()||100;var get_rate=function(){return parseInt(1000/options.fps);}
if(!options.do_once){window.setTimeout(function(){$._spritely.animate(options);},get_rate(options.fps));}else{$._spritely.animate(options);}
return this;},sprite:function(options){var options=$.extend({type:'sprite',bounce:[0,0,1000]},options||{});return $(this).spritely(options);},pan:function(options){var options=$.extend({type:'pan',dir:'left',continuous:true,speed:1},options||{});return $(this).spritely(options);},flyToTap:function(options){var options=$.extend({el_to_move:null,type:'moveToTap',ms:1000,do_once:true},options||{});if(options.el_to_move){$(options.el_to_move).active();}
if($._spritely.activeSprite){if(window.Touch){$(this)[0].ontouchstart=function(e){var el_to_move=$._spritely.activeSprite;var touch=e.touches[0];var t=touch.pageY-(el_to_move.height()/2);var l=touch.pageX-(el_to_move.width()/2);el_to_move.animate({top:t+'px',left:l+'px'},1000);};}else{$(this).click(function(e){var el_to_move=$._spritely.activeSprite;$(el_to_move).stop(true);var w=el_to_move.width();var h=el_to_move.height();var l=e.pageX-(w/2);var t=e.pageY-(h/2);el_to_move.animate({top:t+'px',left:l+'px'},1000);});}}
return this;},isDraggable:function(options){if(!$(this).draggable){alert('To use the isDraggable method you need to load jquery-ui.js');return this;}
var options=$.extend({type:'isDraggable',start:null,stop:null,drag:null},options||{});var el_id=$(this).attr('id');$._spritely.instances[el_id].isDraggableOptions=options;$(this).draggable({start:function(){var el_id=$(this).attr('id');$._spritely.instances[el_id].stop_random=true;$(this).stop(true);if($._spritely.instances[el_id].isDraggableOptions.start){$._spritely.instances[el_id].isDraggableOptions.start(this);}},drag:options.drag,stop:function(){var el_id=$(this).attr('id');$._spritely.instances[el_id].stop_random=false;if($._spritely.instances[el_id].isDraggableOptions.stop){$._spritely.instances[el_id].isDraggableOptions.stop(this);}}});return this;},active:function(){$._spritely.activeSprite=this;return this;},activeOnClick:function(){var el=$(this);if(window.Touch){el[0].ontouchstart=function(e){$._spritely.activeSprite=el;};}else{el.click(function(e){$._spritely.activeSprite=el;});}
return this;},spRandom:function(options){var options=$.extend({top:50,left:50,right:290,bottom:320,speed:4000,pause:0},options||{});var el_id=$(this).attr('id');if(!$._spritely.instances[el_id].stop_random){var r=$._spritely.randomIntBetween;var t=r(options.top,options.bottom);var l=r(options.left,options.right);$('#'+el_id).animate({top:t+'px',left:l+'px'},options.speed)}
window.setTimeout(function(){$('#'+el_id).spRandom(options);},options.speed+options.pause)
return this;},makeAbsolute:function(){return this.each(function(){var el=$(this);var pos=el.position();el.css({position:"absolute",marginLeft:0,marginTop:0,top:pos.top,left:pos.left}).remove().appendTo("body");});},spSet:function(prop_name,prop_value){var el_id=$(this).attr('id');$._spritely.instances[el_id][prop_name]=prop_value;return this;},spGet:function(prop_name,prop_value){var el_id=$(this).attr('id');return $._spritely.instances[el_id][prop_name];},spStop:function(bool){$(this).each(function(){var el_id=$(this).attr('id');$._spritely.instances[el_id]['_last_fps']=$(this).spGet('fps');$._spritely.instances[el_id]['_stopped']=true;$._spritely.instances[el_id]['_stopped_f1']=bool;if($._spritely.instances[el_id]['type']=='sprite'){$(this).spSet('fps',0);}
if(bool){var bp_top=$._spritely.getBgY($(this));$(this).css('background-position','0 '+bp_top);}});return this;},spStart:function(){$(this).each(function(){var el_id=$(this).attr('id');var fps=$._spritely.instances[el_id]['_last_fps']||12;$._spritely.instances[el_id]['_stopped']=false;if($._spritely.instances[el_id]['type']=='sprite'){$(this).spSet('fps',fps);}});return this;},spToggle:function(){var el_id=$(this).attr('id');var stopped=$._spritely.instances[el_id]['_stopped']||false;var stopped_f1=$._spritely.instances[el_id]['_stopped_f1']||false;if(stopped){$(this).spStart();}else{$(this).spStop(stopped_f1);}
return this;},fps:function(fps){$(this).each(function(){$(this).spSet('fps',fps);});return this;},spSpeed:function(speed){$(this).each(function(){$(this).spSet('speed',speed);});return this;},spRelSpeed:function(speed){$(this).each(function(){var rel_depth=$(this).spGet('depth')/100;$(this).spSet('speed',speed*rel_depth);});return this;},spChangeDir:function(dir){$(this).each(function(){$(this).spSet('dir',dir);});return this;},spState:function(n){$(this).each(function(){var yPos=((n-1)*$(this).height())+'px';var xPos=$._spritely.getBgX($(this));var bp=xPos+' -'+yPos;$(this).css('background-position',bp);});return this;}})})(jQuery);try{document.execCommand("BackgroundImageCache",false,true);}catch(err){}

/* js for Hello Calvin website 
 * Author: Calvin Webster
 *
*/

// spritely animations
$(function(){
				$("#bird").sprite({fps:2,no_of_frames:3}).spRandom({top:50,bottom:300,left:500,right:320});
				$("#wave").pan({fps:30,speed:4,dir:'left',depth:30});
				$("#cloud").pan({fps:30,speed:0.5,dir:'left',depth:10});
				});
// background fade day/sunset
var bright=false;
$(function(){
	setInterval(
		function(){
			if(bright){
				$("#sky2, #cloud").css({"z-index":-1});
				if($.browser.msie)
					$("#sky, #sun").css({"z-index":0});
				else
					$("#sky, #sun").css({opacity:0,"z-index":0}).animate({opacity:1},4000);
			}else{
			  	$("#sky, #sun").css({"z-index":-1});
				if($.browser.msie)
					$("#sky2, #cloud").css({"z-index":0});
				else
					$("#sky2, #cloud").css({opacity:0,"z-index":0}).animate({opacity:1},4000);}
		bright=!bright;},8000);});
// tooltip
function bind_mousemove(e){$("#tooltip").css({"left":(e.pageX+5)+"px","top":(e.pageY+5)+"px"});}
$(function(){
	$("a.tip").hover(function(e){var title=$(this).attr("title");
	$("#tooltip").html(title).css({"display":"block","left":(e.pageX+5)+"px","top":(e.pageY+5)+"px"});
	$(this).attr("title","");$(this).bind("mousemove",bind_mousemove);},
	function(){var title=$("#tooltip").html();
	$(this).attr("title",title);
	$("#tooltip").css({"display":"none"}).html("");
	$(this).unbind("mousemove",bind_mousemove);});
  
});
