$(document).ready(function(){
	
	overposition=-45;
	originalposition=-90;
	addon=43;
	
	debugme="no";
	
	
	
	$(".notrigger").hover(function(){
							//alert($(this).position().left);
							pullup(100);
							
							$(this).css("background-position","-"+$(this).position().left+"px "+overposition+"px");
						},function(){
							
							$(this).css("background-position","-"+$(this).position().left+"px "+originalposition+"px");
						});
	
	



//all this stuff is for effects	*****************************************************
	
	function flynotes(whereat){
	
		
		$("#notebox").css("left",whereat+"px");	
		$("#notebox img").each(function(){
			
			notespeed=(Math.floor(Math.random()*1000)+500);
		
			
	
	$(this).stop().animate({top:'-150px'},{queue:false, duration:notespeed});
	
});
		
		
		
	}
	
	function returnnotes(){
		
		
		$("#notebox img").stop().css("top","0px");
	
		
	}
	
	
$("#notebox").css("top","100px");	
startnoteleft=0;
$("#notebox img").each(function(){
	$(this).css("left",startnoteleft+"px");
	startnoteleft=startnoteleft+20;
});
	
	
	//end of effects *************************************************************
	
	
	
	

	var timeOut=new Array();
	$(".choices").css("opacity",0);	
	
	
	
	
	
	
	
	
	//Remove outline from links
	$("a").click(function(){
		$(this).blur();
	});
	
	
	
	
	//When mouse rolls over
	
	$(".maintrigger").mouseover(function(){
		
		
	
	
		
		$(this).css("background-position","-"+$(this).position().left+"px "+overposition+"px");
		
		myoverid=$(this).attr("id");
		pullup("div"+myoverid);  //pulling up everything except this menu  *******
		
		if(timeOut["div"+myoverid]){
		
		clearTimeout(timeOut["div"+myoverid]);  //clears the timeout that would have pulled up the drop and swapped the bg position **************
		}
		
		
		//addon=43;
		
										// alert(this.id);
						
			$("#div"+this.id).stop().animate({top:addon+'px'},{queue:false, duration:1500, easing: 'easeOutExpo'});	  // animates the drop menu  *********************
			$("#div"+this.id).animate({opacity:1},{queue:false, duration:1500, easing: 'easeOutExpo'});   // animates the drop menu opacity  *********************
			
										});
	
	
	$(".choices").mouseover(function(){
		myidq=$(this).attr("id");
		origindivq=myidq.replace("div", "");

		thisid=$(this).attr("id");
		
		if(timeOut[thisid]){
	
		clearTimeout(timeOut[thisid]);
		}
		
	
		$(this).stop();
		$(this).animate({opacity:1},{queue:false, duration:0, easing: 'easeOutExpo'});
	
	});
	
	//When mouse is removed
	$(".choices").mouseout(function(){
		myids=$(this).attr("id");
		origindiv=myids.replace("div", "");
		pullup(myids);
		
	});
	$(".maintrigger").mouseout(function(){
		
	//returnnotes();
		
		
		
		
		myid=$(this).attr("id");
		timeOut["div"+myid] = setTimeout(function(){
			if(debugme=="yes"){
			alert("troy  I set the timeout"+myid);
			}
		
		
		$("#div"+myid).stop().animate({top:'-'+$("#div"+myid).height()},{queue:false, duration:1500, easing: 'easeOutExpo'})
		$("#div"+myid).animate({opacity:0},{queue:false, duration:0, easing: 'easeOutExpo'});
		$("#"+myid).css("background-position","-"+$("#"+myid).position().left+"px "+originalposition+"px");
		
		},200);
	});
	
	function pullup(whichup){
		if(debugme=="yes"){
		alert("troy  Im using pullup"+whichup);
		}
		checkup=whichup;
	
		$(".choices").each(function(){
			if($(this).attr("id")!="div"+checkup){
				
				$(this).stop().animate({top:'-'+$(this).height()},{queue:false, duration:500, easing: 'easeOutExpo',complete:function(){
					myidz=$(this).attr("id");
					if(debugme=="yes"){
				alert ("here is myidz"+myidz);
					}
		origindivz=myidz.replace("div", "");
		if(debugme=="yes"){
					alert("im switching "+origindivz+" back to normal state");
		}
					$("#"+origindivz).css("background-position","-"+$("#"+origindivz).position().left+"px "+originalposition+"px");
				}
				
				}
				);
				$(this).animate({opacity:0},{queue:false, duration:1500, easing: 'easeOutExpo'});
				
				
			}
			
		});
		
		
		
	}
	
});
