Guest User

Untitled

a guest
Jan 12th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** jQuery **/
  2. var sitemap =  isPage = 0;
  3. var currPage = "";
  4.  
  5. //Determine what page it is on load
  6. //Must be in correct order
  7. var pages = new Array("about", "introduction", "benefits", "how-we-work", "become-a-member", "next-step", "hours", "testimonials", "contact", "partners");
  8.  
  9. var sbItemId;
  10. var dashPos;
  11. var sbPage;
  12. var posNum;
  13. var hoverPos;
  14. var selPos;
  15. var selId;
  16. var pagePos
  17.  
  18. function arraySearch(arr,val) {
  19.     for (var i=0; i<arr.length; i++){
  20.         if (arr[i] == val)
  21.             return i;
  22.     }
  23.     return false;
  24. }
  25.    
  26. $(document).ready(function(){
  27.    
  28.  
  29.     //SIDEBAR CODE
  30.     var url = window.location.hash;
  31.     var linkPos = url.lastIndexOf("/");
  32.    
  33.     if(linkPos >= 0){
  34.         currPage = url.substring(linkPos+1);
  35.    
  36.         $.each(pages, function(i, val){
  37.             if(currPage == val){
  38.                 isPage=1;
  39.                 return;
  40.             }
  41.         });
  42.         if(isPage==0){
  43.             currPage = "about";
  44.         }
  45.     }
  46.     else
  47.             currPage = "about";
  48.        
  49.    
  50.     sbPage = arraySearch(pages, currPage);
  51.    
  52.     //position to hover to:
  53.         //position to hover to:
  54.         switch(sbPage){
  55.             case 0:
  56.             case 1:
  57.             case 2:
  58.                 pagePos = (sbPage * 40);
  59.                 break;
  60.             case 3:
  61.             case 4:
  62.             case 5:
  63.             case 6:
  64.                 pagePos = (sbPage * 40)+6;
  65.                 break;
  66.             case 7:
  67.                 pagePos = (sbPage * 40)+12;
  68.                 break; 
  69.             case 8:
  70.                 pagePos = (sbPage * 40)+18;
  71.                 break;     
  72.             case 9:
  73.                 pagePos = (sbPage * 40)+24;
  74.                 break;         
  75.         }
  76.        
  77.     //pagePos = (sbPage * 40) + 6;
  78.    
  79.     $('#pos-'+sbPage).addClass('sel-sbitem');
  80.     $('.sel-sbitem-bar').css({"top":+pagePos+"px"});
  81.    
  82.     //move color sidebar tab when hover
  83.     hoverPos = 0;
  84.     $('.sb-item').mouseover(function(){
  85.        
  86.         $(this).addClass('hov-sbitem');
  87.         //get ID to get position #
  88.         sbItemId = $(this).attr('id');
  89.         dashPos = sbItemId.indexOf('-')+1; 
  90.        
  91.         //get the position number of element as listed in id (1st, 2nd, etc)   
  92.         posNum = sbItemId.substring(dashPos);
  93.         posNum = parseInt(posNum);
  94.        
  95.         //position to hover to:
  96.         switch(posNum){
  97.             case 0:
  98.             case 1:
  99.             case 2:
  100.                 hoverPos = (posNum * 40);
  101.                 break;
  102.             case 3:
  103.             case 4:
  104.             case 5:
  105.             case 6:
  106.                 hoverPos = (posNum * 40)+6;
  107.                 break;
  108.             case 7:
  109.                 hoverPos = (posNum * 40)+12;
  110.                 break; 
  111.             case 8:
  112.                 hoverPos = (posNum * 40)+18;
  113.                 break;     
  114.             case 9:
  115.                 hoverPos = (posNum * 40)+24;
  116.                 break;         
  117.         }
  118.        
  119.         //move hover bar and change color
  120.         $('.sel-sbitem-bar').stop().animate({"top":+hoverPos+"px"}, '400');
  121.        
  122.        
  123.         }).mouseout(function(){
  124.             //not hovering over anymore
  125.             $(this).removeClass('hov-sbitem');
  126.            
  127.             //pos of selected sb item
  128.             selId = $('.sel-sbitem').attr('id');
  129.             dashPos = selId.indexOf('-');
  130.             selNum = selId.substring(dashPos+1);
  131.            
  132.             /*/position to hover to:
  133.             switch(selNum){
  134.                 case 0:
  135.                 case 1:
  136.                 case 2:
  137.                     selPos = (selNum * 40);
  138.                     break;
  139.                 case 3:
  140.                 case 4:
  141.                 case 5:
  142.                 case 6:
  143.                     selPos = (selNum * 40)+6;
  144.                     break;
  145.                 case 7:
  146.                     selPos = (selNum * 40)+12;
  147.                     break; 
  148.                 case 8:
  149.                     selPos = (selNum * 40)+18;
  150.                     break;     
  151.                 case 9:
  152.                     selPos = (selNum * 40)+24;
  153.                     break;         
  154.             }//*/
  155.             if(selNum == 0 || selNum == 1 || selNum == 2)
  156.                 selPos = (selNum * 40);
  157.             else if(selNum == 3 || selNum == 4 || selNum == 5 || selNum == 6)
  158.                 selPos = (selNum * 40)+6;
  159.             else if(selNum == 7)
  160.                 selPos = (selNum * 40)+12;
  161.             else if(selNum == 8)
  162.                 selPos = (selNum * 40)+18;
  163.             else if(selNum == 9)
  164.                 selPos = (selNum * 40)+24;
  165.            
  166.             //selPos = parseInt(selNum*40)+6;
  167.             //alert(selPos);
  168.             $('.sel-sbitem-bar').stop().animate({"top":+selPos+"px"}, '400');
  169.     });
  170.    
  171.     //set the correct current section to show
  172.     setSec(currPage);
  173.    
  174.     //pops up buttons
  175.     //twitter
  176.     buttonPop('social-tweet', -28, -28, -193, -218);
  177.     //facebook
  178.     buttonPop('social-fb', -80, -80, -193, -218);
  179.    
  180. }); //end doc.ready
  181.  
  182. $('.sb-item').click(function(){
  183.         $('.sb-item').each(function(){
  184.             $(this).removeClass('sel-sbitem');
  185.         });
  186.  
  187.         $(this).addClass('sel-sbitem');
  188.        
  189.         sel2Id = $(this).attr('id');
  190.         dashPos = sel2Id.indexOf('-');
  191.         sel2Num = sel2Id.substring(dashPos+1);
  192.        
  193.         //position to hover to:
  194.         switch(sel2Num){
  195.             case 0:
  196.             case 1:
  197.             case 2:
  198.                 sel2Pos = (sel2Num * 40);
  199.                 break;
  200.             case 3:
  201.             case 4:
  202.             case 5:
  203.             case 6:
  204.                 sel2Pos = (sel2Num * 40)+6;
  205.                 break;
  206.             case 7:
  207.                 sel2Pos = (sel2Num * 40)+12;
  208.                 break; 
  209.             case 8:
  210.                 sel2Pos = (sel2Num * 40)+18;
  211.                 break;     
  212.             case 9:
  213.                 sel2Pos = (sel2Num * 40)+24;
  214.                 break;         
  215.         }
  216.         //selPos = parseInt(selNum*40)+6;
  217.        
  218.         $('.sel-sbitem-bar').css({"top":+sel2Pos+"px"});
  219. });
  220. //END SIDEBAR CODE
  221.  
  222. function setSec(currSec){
  223.     $('#'+currSec).addClass('active');
  224.     $('#'+currSec).removeClass('inactive');
  225.     $('#'+currSec).css({'z-index':3, 'opacity':1});
  226.    
  227.     $('.section[id!="'+currSec+'"]').each(function(){
  228.         $(this).removeClass('active');
  229.         $(this).addClass('inactive');
  230.         $(this).css({'z-index':1, 'opacity':0});
  231.     });
  232. }
  233.    
  234. function switchSec(currSec){
  235.  
  236.     //edit all sections but the one chosen
  237.     $('.section[id!="'+currSec+'"]').each(function(){
  238.         //put behind
  239.         $(this).css({'z-index':1});
  240.         //fade
  241.         $(this).stop().animate({
  242.             "opacity":0
  243.         }, 400, function(){
  244.             //must do this after or height will be sloppily changed
  245.             $(this).removeClass('active');
  246.             $(this).addClass('inactive');
  247.            
  248.            
  249.             $('#'+currSec).removeClass('inactive');
  250.             $('#'+currSec).stop().animate({
  251.                 "opacity":1
  252.             }, 400, function(){
  253.                 $('#'+currSec).addClass('active');
  254.                 $('#'+currSec).css({'z-index':3});
  255.             });
  256.            
  257.         });
  258.     });
  259.    
  260. }
  261.  
  262. //pops up specified button
  263. function buttonPop(buttonId, bgStartX, bgEndX, bgStartY, bgEndY){
  264.     $('#'+buttonId).hover(function(){
  265.         $(this).css({backgroundPosition: bgStartX+'px '+bgStartY+'px'});
  266.         $(this).stop().animate({backgroundPosition: bgEndX+'px '+bgEndY+'px'}, 250);
  267.     },function(){
  268.         $(this).stop().animate({backgroundPosition: bgStartX+'px '+bgStartY+'px'}, 250);
  269.     });
  270. }
Add Comment
Please, Sign In to add comment