Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //global variable needed because function that uses it is recursive
  2. var totalCycles = 0;
  3.  
  4. $(document).ready(function() {
  5.    
  6.     $(".email").slideToggle("slow");
  7.        
  8.     //br is the most efficient way to get desired effect with inline h3's
  9.    $("<br/>").insertBefore("h3");
  10. });
  11.  
  12. $(window).load(function() {
  13.    
  14.     parallelNavbar();
  15.    
  16.    //collapse all expandable sections on page load
  17.    toggleExpansion($(".expansion_text"));
  18.    
  19.    totalCycles = assignCycleNumbers();
  20.    cycleAssociates();
  21.    
  22.    
  23. });
  24.  
  25. // window is resized
  26. $(function(){
  27.     $(window).resize(function() {
  28.         parallelNavbar();
  29.         totalCycles = assignCycleNumbers();
  30.     });
  31. });
  32.  
  33. // h3 clicked for expansion
  34. $(function(){
  35.     $("h3").click( function(){
  36.         toggleExpansion($(this).siblings(".expansion_text"));
  37.     });
  38. });
  39.  
  40. $(function(){
  41.     $("#expand_email").click( function(){
  42.         $(".email").slideToggle("slow");
  43.     });
  44. });
  45.  
  46. /* ^ Events ^ */
  47.  
  48. function toggleExpansion(expandableText){
  49.     expandableText.slideToggle( "slow", function(){
  50.             if ( $(this).is(":visible") ){
  51.                
  52.                 //remove ".." that sugests expansion
  53.                 var oldtext = $(this).siblings("h3").text();
  54.                 $(this).siblings("h3").text(oldtext.replace("..",""));
  55.        
  56.                 var page = $("#page");
  57.  
  58.                 page.animate({scrollTop: page.scrollTop() +
  59.                     $(this).siblings("h3").position().top},1100);
  60.                
  61.             }
  62.             else{
  63.                 $(this).siblings("h3").append("..");
  64.             }
  65.         });
  66. }
  67.  
  68. function parallelNavbar(){
  69.    
  70.     //make the navigation parallel with the content
  71.     var distance = $("#header").outerHeight();
  72.     $("#header_equivalent").height(distance);
  73.    
  74.        
  75. }
  76.  
  77. function cycleAssociates(){
  78.     var cycle = 0;
  79.  
  80.     var recursiveCycling = function(cycle, totalCycles){
  81.         var currentAssociate = ".cycle" + cycle;
  82.         //fade in all img with the current cyle class over a second,
  83.         //wait 3 seconds before fading out over a second.
  84.         $(currentAssociate).delay(100).fadeIn(1000).delay(3000).fadeOut(1000,
  85.             function(){
  86.                 cycle++;
  87.                 if(cycle > totalCycles){
  88.                     cycle = 0;
  89.                 }
  90.                 recursiveCycling(cycle, totalCycles);
  91.             });
  92.    
  93.     };
  94.     recursiveCycling(cycle, totalCycles);
  95.  
  96. }
  97.  
  98.  
  99. function assignCycleNumbers(){
  100.     //first remove any old cycle# classes (resized window case)
  101.     $('[class*="cycle"]').removeClass( function(unusedIdx,c){
  102.         return c.match(/cycle\d+/g).join(" ");
  103.     });
  104.        
  105.     //measure div width
  106.     var divSpace = $("#bodies").innerWidth();
  107.     //assign a cycle number to a number of logos until no more will fit in that div
  108.     var cycleNum = 0;
  109.     $(".associate").each(function(){
  110.        
  111.         if( divSpace - $(this).width() > 0){
  112.             $(this).addClass("cycle" + cycleNum);
  113.             divSpace = divSpace - $(this).width();
  114.         }
  115.         else{ //next logo won't fit current cycle, create next cycle
  116.             cycleNum++
  117.             $(this).addClass("cycle" + cycleNum);
  118.             divSpace = $("#bodies").innerWidth() - $(this).width();
  119.         }
  120.     });
  121.     return cycleNum;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement