jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


 
 $(
 
	 function(){  
     
   
		 $('.buildInfo').each(function () {
	            var distance = 10;
	            var time = 250;
	            var hideDelay = 500;

	            var hideDelayTimer = null;

	            var beingShown = false;
	            var shown = false;
	            var triggerbuild = $('#buildbutton', this);
	            var infobuild = $('.buildpopup', this).css('opacity', 0);


	            $([triggerbuild.get(0), infobuild.get(0)]).mouseover(function (e) {
					
	                if (hideDelayTimer) clearTimeout(hideDelayTimer);
	                if (beingShown || shown) {
	                    // don't trigger the animation again
	                    return;
	                } else {
	                    // reset position of info box
	                    beingShown = true;
						var mouse = e.pageX - 305;

	                    infobuild.css({
	                        top: 0,
	                        left: mouse,
	                        display: 'block'
	                    }).animate({
	                        top: '+=' + distance + 'px',
	                        opacity: 1
	                    }, time, 'swing', function() {
	                        beingShown = false;
	                        shown = true;
	                    });
	                }

	                return false;
	            }).mouseout(function () {
	                if (hideDelayTimer) clearTimeout(hideDelayTimer);
	                hideDelayTimer = setTimeout(function () {
	                    hideDelayTimer = null;
	                    infobuild.animate({
	                        top: '-=' + distance + 'px',
	                        opacity: 0
	                    }, time, 'swing', function () {
	                        shown = false;
	                        infobuild.css('display', 'none');
	                    });

	                }, hideDelay);

	                return false;
	            });
	        });
      
	        


			 
		 
//$('body').supersleight();
	 
	 	$.preloadImages(siteroot + "/images/button_left_side.jpg", siteroot + "/images/button_selected.jpg", siteroot + "/images/button_both_gradient.jpg","image/button_selected.jpg", siteroot + "/images/button_left_gradient.jpg", siteroot + "/images/button_right_side.jpg", siteroot + "/images/button_left_side_gradient.jpg");



	  // $('.rounded').corners(); /* test for double rounding */
	   
	   
	 

		 $(".button_1").click(
			function(){
				 parent.location=linkroot+'missions/personal';
			 }
		 );

		 $(".button_2").click(
					function(){
						 parent.location=linkroot+'missions/family';
					 }
		);

		 $(".button_3").click(
					function(){
						 parent.location=linkroot+'missions/team';
					 }
		);

		 $(".button_4").click(
					function(){
						 parent.location=linkroot+'missions/freewrite';
					 }
		);


					 
	   
	 

		$('.button_1').hover(
			function() {

				$("#button1_popup").animate({ top: "0px" });
				$("#button2_popup").animate({ top: "257px" });
				$("#button3_popup").animate({ top: "257px" });
				$("#button4_popup").animate({ top: "257px" });
				$('.button_2').css("background-image",'url('+siteroot +'/images/button_left_gradient.jpg)');
				$('.button_1').css("background-image",'url(' + siteroot + '/images/button_left_side.jpg)');
				$('#button1_position').css("display", "block");

			}
			);
		
		
		
	
		$('.button_2').hover(
			function() {
				$(this).css("background-image",'url(' + siteroot + '/images/button_selected.jpg)');
				$('.button_1').css("background-image",'url(' + siteroot + '/images/button_left_side_gradient.jpg)');
				$('.button_3').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');
			
				$("#button1_popup").animate({ top: "257px" });
				$("#button2_popup").animate({ top: "0px" });
				$("#button3_popup").animate({ top: "257px" });
				$("#button4_popup").animate({ top: "257px" });
				$('#button2_position').css("display", "block");
			
			},
			function()
			{


			}
	
		);
		
		$('.button_3').hover(
			function() {
			//alert($('.button img.button_1').attr( 'src' ));
				$(this).css("background-image",'url(' + siteroot + '/images/button_selected.jpg)');
				$('.button_2').css("background-image",'url(' + siteroot + '/images/button_both_gradient.jpg)');
				$('.button_1').css("background-image",'url(' + siteroot + '/images/button_left_side.jpg)');
				 $('.button_4').css("background-image",'url(' + siteroot + '/images/button_right_side_gradient.jpg)');
 				
				$("#button1_popup").animate({ top: "257px" });
				$("#button2_popup").animate({ top: "257px" });
				$("#button3_popup").animate({ top: "0px" });
				$("#button4_popup").animate({ top: "257px" });
			},
			function()
			{


			}
	
		);
		
		$('.button_4').hover(
			function() {
			//alert($('.button img.button_1').attr( 'src' ));
				$(this).css("background-image",'url(' + siteroot + '/images/button_right_side.jpg)');
				$('.button_3').css("background-image",'url(' + siteroot + '/images/button_both_gradient.jpg)');
				$('.button_2').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');

				$("#button1_popup").animate({ top: "257px" });
				$("#button2_popup").animate({ top: "257px" });
				$("#button3_popup").animate({ top: "257px" });
				$("#button4_popup").animate({ top: "0px" });

			},
			function()
			{

			}
	
		);
		

		
		$('#panel2').mouseout(function(){
				$("#panel2").animate({ top: "257px" });
   		 });
         
         

             $('#button1_position').hover(
                function() {
                    
                },
                function()
                {
                    $("#button1_popup").animate({ top: "257px" }, "normal", "", function() {$('#button1_position').css("display", "none");});

                }
        
            );
            
             $('#button2_position').hover(
                function() {
                    
                },
                function()
                {
                    $("#button2_popup").animate({ top: "257px" }, "normal", "", function() {$('#button2_position').css("display", "none");});
                    $('.button_2').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');
    				$('.button_1').css("background-image",'url(' + siteroot + '/images/button_left_side.jpg)');

                }
        
            );
            
             $('#button3_position').hover(
                function() {
                    
                },
                function()
                {
                    $("#button3_popup").animate({ top: "257px" });
    				$('.button_2').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');
    				$('.button_3').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');
    				$('.button_4').css("background-image",'url(' + siteroot + '/images/button_right_side_gradient.jpg)');
					
                }
        
            );
            
             $('#button4_position').hover(
                function() {
                    
                },
                function()
                {
                    $("#button4_popup").animate({ top: "257px" });
                    $('.button_4').css("background-image",'url(' + siteroot + '/images/button_right_side_gradient.jpg)');
    				$('.button_3').css("background-image",'url(' + siteroot + '/images/button_left_gradient.jpg)');
    				

                }
        
            );
            

	  $(".button img.button_3").click(   
		  function(){ 
		  	
			$("#panel").animate({ top: "0px" });
			//$("div.panel_button").toggle();  
		 }); 
	 
		 $("div#hide_button").click(
			function(){  
				$("div#panel").animate({  
					   height: "0px"  
			   		}
		   		);  
   	 		}
		);

        
	
	 }
 
 );  
 

 
