// JavaScript Document

//special scroll handlers by http://james.padolsey.com/demos/scrollevents/
(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) );
        }
    };
    
})();



function getNextHighestZindex(obj){
	   var highestIndex = 0;
	   var currentIndex = 0;
	   var elArray = Array();
	   if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }
	   for(var i=0; i < elArray.length; i++){
		  if (elArray[i].currentStyle){
			 currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
		  }else if(window.getComputedStyle){
			 currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
		  }
		  if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
	   }
	   return(highestIndex+1);
	}
$(document).ready(function(){
	
	var username = 'broncha';
	jQuery.getScript('http://twitter.com/statuses/user_timeline/' + username + '.json?callback=twitterCallback2&count=1'); 
	
	var accorOpt = {
			buttons:["About Me","What I do!"],
			panelContainer:"panel",
		};
	
	$("#accord").accorbion(accorOpt);
	
	$("iframe").css({
						"zIndex":"2"
						});
	$(".head-link").css({
						"zIndex":"5"
						});
	
	$(window).bind('scrollstart', function(){
                $(".head-link").fadeOut();
				//console.log("scrolling");
												});
            
    $(window).bind('scrollstop', function(e){
                $(".head-link").fadeIn();
				//console.log("stopped scrolling");
											   });
	
});

