
// Remember, when pasting code into here - after updating to wordpress version 2.9, 
// you have to call jQuery in a different way.  You have to replace every “$” with jQuery

jQuery(document).ready(function() {

   // Persistent header with opacity - http://davidwalsh.name/persistent-header-opacity
   (function() {
      //settings
      var fadeSpeed = 200, fadeTo = 0.5, topDistance = 30;
      var topbarME = function() { jQuery('#header').fadeTo(fadeSpeed,1); }, topbarML = function() { jQuery('#header').fadeTo(fadeSpeed,fadeTo); };
      var inside = false;
      //do
      jQuery(window).scroll(function() {
         position = jQuery(window).scrollTop();
         if(position > topDistance && !inside) {
            //add events
            topbarML();
            jQuery('#header').bind('mouseenter',topbarME);
            jQuery('#header').bind('mouseleave',topbarML);
            inside = true;
            }
         else if (position < topDistance){
            topbarME();
            jQuery('#header').unbind('mouseenter',topbarME);
            jQuery('#header').unbind('mouseleave',topbarML);
            inside = false;
         }
      });

      // Improving Search Boxes with jQuery - http://yensdesign.com/2009/01/improving-search-boxes-with-jquery/
      var searchBoxes = jQuery(".search_input");
      var mySearchBox = jQuery("#s");
      var searchBoxDefault = "Search Cazh1 ...";
         // Effects for both searchbox
      searchBoxes.focus(function(e){
      	jQuery(this).addClass("active");
      });
      searchBoxes.blur(function(e){
    	  jQuery(this).removeClass("active");
      });
         // Show/hide default text if needed
      mySearchBox.focus(function(){
      	if(jQuery(this).attr("value") == searchBoxDefault) jQuery(this).attr("value", "");
      });
      mySearchBox.blur(function(){
      	if(jQuery(this).attr("value") == "") jQuery(this).attr("value", searchBoxDefault);
      });
   
   })();

   // Creating A Simple Tooltip Using jQuery and CSS - http://blufusion.net/2009/07/27/creating-a-simple-tooltip-using-jquery-and-css/
   // (but I hacekd it a bit to give me a fixed tooltip
   jQuery(".tooltips").hover(
      function() { jQuery(this).contents("span:last-child").css({ display: "block" }); },
      function() { jQuery(this).contents("span:last-child").css({ display: "none" }); }
   );
//   jQuery(".tooltips").mousemove(function(e) {
//	      var mousex = e.top + 140 ;
//	      var mousey = e.left - 100;
//	      var mousex = e.pageX + 10;
//	      var mousey = e.pageY + 5;
//      jQuery(this).contents("span:last-child").css({  top: mousey, left: mousex });
//   });
   
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Scrolling to the Top and Bottom with jQuery - 
jQuery(function() { // Scrolling to the Top and Bottom with jQuery 
                    // http://tympanus.net/codrops/2010/01/03/scrolling-to-the-top-and-bottom-with-jquery/
   // the element inside of which we want to scroll
   var jQueryelem = jQuery('#content');

   // show the buttons
   jQuery('#nav_up').fadeIn('slow');
   jQuery('#nav_down').fadeIn('slow');  

   // whenever we scroll fade out both buttons
   jQuery(window).bind('scrollstart', function(){
      jQuery('#nav_up,#nav_down').stop().animate({'opacity':'0.2'});
   });
   // ... and whenever we stop scrolling fade in both buttons
   jQuery(window).bind('scrollstop', function(){
	   jQuery('#nav_up,#nav_down').stop().animate({'opacity':'1'});
   });

   // clicking the "down" button will make the page scroll to the $elem's height
   jQuery('#nav_down').click(
      function (e) {
         jQuery('html, body').animate({scrollTop: jQuery("body").css("height")}, 800);
      }
   );
   
   // clicking the "up" button will make the page scroll to the top of the page
   jQuery('#nav_up').click(
      function (e) {
         jQuery('html, body').animate({scrollTop: '0px'}, 800);
      }
   );
});

(function(){
    
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
        
    special.scrollstart = {
        setup: function() {
            
            var timer,
                handler =  function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
                    
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid1, handler);
            
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
    
    special.scrollstop = {
        latency: 300,
        setup: function() {
            
            var timer,
                    handler = function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    }
                    
                    timer = setTimeout( function(){
                        
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
                        
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid2, handler);
            
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
    
})();

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var name = "#floatMenu";
var menuYloc = null;

jQuery(document).ready(function(){
    menuYloc = parseInt(jQuery(name).css("top").substring(0,jQuery(name).css("top").indexOf("px")))
    jQuery(window).scroll(function () {
        var offset = menuYloc+jQuery(document).scrollTop()+"px";
        jQuery(name).animate({top:offset},{duration:500,queue:false});
    });
});

