/*
 * Anhang Zhu Resume
 *
 * Copyright (c) 2010 Anhang Zhu
 *
 */
if (!AZHU ) {
  var AZHU  = {};
}

AZHU = {
	init : function() {
		var name = String.fromCharCode(97,110,104,97,110,103);
		var domain = String.fromCharCode(98,101,114,107,101,108,101,121,46,101,100,117);
		var email = name+String.fromCharCode(64)+domain;
		AZHU.formatEmail(email);
		AZHU.displayTooltip();
	},
	formatEmail : function(email) {
		$('#email_address').attr("href", "mailto:" + email);
		$('#email_address img').attr("title", "Send me an email at " + email);
	},
	displayTooltip : function(){
		$('.poshytip').poshytip({
			className: 'tip-yellowsimple',
			showTimeout: 1,
			alignTo: 'target',
			alignX: 'center',
			alignY: 'bottom',
			offsetY: 5,
			allowTipHover: true,
			fade: true,
			slide: true
		});
	}
}

$(document).ready(function () {
	AZHU.init();
});



/*scroll animation*/
(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() {
				$('#to-experience').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#experience-section").offset().top}, 400);
					}
				);
				
				$('#nav_up').click(
					function (e) {
						$('html, body').animate({scrollTop: '0px'}, 500);
					}
				);
				
				$('#bto-education').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#education-section").offset().top}, 400);
					}
				);
				
				
				$('#to-skills').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#skills-section").offset().top}, 400);
					}
				);
				
				$('#bto-experience').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#experience-section").offset().top}, 400);
					}
				);
				
				$('#to-projects').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#projects-section").offset().top}, 400);
					}
				);
				
				$('#bto-projects').click(
					function (e) {
						$('html, body').animate({scrollTop: $("#projects-section").offset().top}, 400);
					}
				);

				
            });
			
