google.load("webfont", "1");
 
 
var pix_delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();


jQuery(function(){
 	function isMobile() {	//sniff a mobile browser
		if( navigator.userAgent.match(/Android/i) ||
			navigator.userAgent.match(/webOS/i) ||
			navigator.userAgent.match(/iPad/i) ||
			navigator.userAgent.match(/iPhone/i) ||
			navigator.userAgent.match(/iPod/i)
			){
				return true;
		}	
	}

   jQuery('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        && location.hostname == this.hostname) {
            var target = jQuery(this.hash);
            target = target.length && target
            || jQuery('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                var targetOffset = target.offset().top;
				jQuery('html,body')
				.animate({scrollTop: targetOffset}, 1000, 'easeInOutQuint');
				if(isMobile()){
					pix_delay(function(){
						jQuery(window).scroll();
					},1000);
				}
                return false;
            }
        }
    });
});

jQuery(function($) {
	function isMobile() {	//sniff a mobile browser
		if( navigator.userAgent.match(/Android/i) ||
			navigator.userAgent.match(/webOS/i) ||
			navigator.userAgent.match(/iPad/i) ||
			navigator.userAgent.match(/iPhone/i) ||
			navigator.userAgent.match(/iPod/i)
			){
				return true;
		}	
	}

	if ((jQuery.browser.msie && jQuery.browser.version > 7) || !jQuery.browser.msie) {
		jQuery('header').each(function(){
			var t = jQuery(this);
			var top = 0;
			var hT = parseFloat(t.height());
			jQuery(window).bind('load scroll resize',function($) {
				var sumScroll = jQuery('html').scrollTop()+jQuery('body').scrollTop();
				if (sumScroll < 400){
					t.css({'position':'relative','top':0});
					jQuery('#yellow_border').css({'position':'relative','top':0});
				} else {
					if(isMobile()){
						if(t.css('position')=='relative'){
							t.css({'display':'none','position':'absolute'}).fadeIn(1000);
							jQuery('#yellow_border').css({'display':'none','position':'absolute'}).fadeIn(1000);
						}
						t.css({'top':(sumScroll-400)+'px'});
						jQuery('#yellow_border').css({'top':(sumScroll+390)+'px'});
					} else {
						if(t.css('position')=='relative'){
							t.css({'position':'fixed','top':'-400px'});
							jQuery('#yellow_border').css({'position':'fixed','top':'89px'});
						}
					}
				}
			});
		});
	}
});
  
  
jQuery(window).bind('load resize',function() {
    pix_delay(function(){
		jQuery('.fit_screen').each(function(){
			var h = jQuery(window).height();
			var thisH = jQuery(this).outerHeight();
			var headerH,
				addMargin;
			if(jQuery(this).parent().index()==0) {
				jQuery(this).parent().addClass('activeScroll');
				headerH = jQuery('#header_base').height();
				addMargin = 0;
			} else {
				headerH = jQuery('#header_base').height() - 100;
				addMargin = 100;
			}
			
			var activeItem;
			if(thisH < (h-headerH)) {
				var missH = ((h-headerH)-thisH)*0.5
				jQuery(this).animate({'margin-top':missH+addMargin,'margin-bottom':missH},700, 'easeInOutQuint', function(){
					jQuery(this).waypoint({offset:'50%'});
					jQuery(this).bind('waypoint.reached',function(event, direction) {
						if (direction === 'up') {
							activeItem = jQuery(this).parents('div').prev();
						}
						else {
							activeItem = jQuery(this).parents('div');
						}
						
						if(activeItem.length){
							jQuery('.fit_screen').parents('div').removeClass('activeScroll');
							activeItem.addClass('activeScroll');
							jQuery('nav#main_nav li').removeClass('current');
							var attrId;
							if(activeItem.index()==0) {
								attrId = 'header_base';
							} else {
								attrId = activeItem.attr('id');
							}
							jQuery('nav#main_nav li a[href=#'+attrId+']').parents('li').addClass('current');
						}
					});
				});
			} else {
				jQuery(this).animate({'margin-top':100,'margin-bottom':100},700, 'easeInOutQuint', function(){
					jQuery(this).waypoint({offset:'50%'});
					jQuery(this).bind('waypoint.reached',function(event, direction) {
						if (direction === 'up') {
							activeItem = jQuery(this).parents('div').prev();
						}
						else {
							activeItem = jQuery(this).parents('div');
						}
						
						if(activeItem.length){
							jQuery('.fit_screen').parents('div').removeClass('activeScroll');
							activeItem.addClass('activeScroll');
							jQuery('nav#main_nav li').removeClass('current');
							var attrId;
							if(activeItem.index()==0) {
								attrId = 'header_base';
							} else {
								attrId = activeItem.attr('id');
							}
							jQuery('nav#main_nav li a[href=#'+attrId+']').parents('li').addClass('current');
						}
					});
				});
			}
		});
		if(jQuery('body').hasClass('mobile')){
			pix_delay(function(){
				var off = jQuery('#last_item').offset();
				var bottom = off.top;
				jQuery('.wrap_parallax').css({'height':bottom+'px'});
			},700);
		}
    }, 500);
});

jQuery(window).bind('load resize',function() {
	var w = jQuery(window).width();
	jQuery('body').css({'background-position': ((w*0.5)-1272)+'px 0'});
});


jQuery(function(){
	jQuery('#social_hide').each(function(){
		var t = jQuery(this);
		var mL = 0;
		if(jQuery('#search_form').length){
			mL = 43;
		}
		var le = t.find('a').length;
		var i = 0;
		var z = le;
		while(i < le){
			t.find('a').eq(z-1).delay(100+(i*300)).animate({'right':(i*43)+mL,'opacity':1},600);
			i++;
			z--;
		}
	});
});


jQuery(window).one('load',function(){
	if(jQuery('body').hasClass('mobile')){
		setTimeout(function(){
		jQuery('*[data-height="100"]').each(function(){
			var t = jQuery(this);
			jQuery(window).bind('scroll load resize',function(){
				var h = parseFloat(window.innerHeight);
				t.css({'height':h+'px'});
			});
		});
		jQuery('*').each(function(){
			var t = jQuery(this);
			var top = jQuery(this).css('top');
			var bottom = jQuery(this).css('bottom');
			var hT = parseFloat(t.height());
			if(t.css('position')=='fixed'){
				jQuery(window).bind('scroll load resize',function(){
					t.css({'position':'absolute'});
					var sumScroll = parseFloat(jQuery('html').scrollTop())+parseFloat(jQuery('body').scrollTop());
					var h = parseFloat(window.innerHeight);
					if(top!='not'){
						t.css({'top':(sumScroll+parseFloat(top))+'px'});
					} else {
						t.css({'top':((sumScroll+h)-(parseFloat(bottom)+hT))+'px','bottom':''});
					}
				});
			}
		});
		},2);
	}
});


jQuery(function(){
	jQuery('.options tr:odd').addClass('odd');
	jQuery('.options td:even').addClass('even');
});


jQuery(function(){
	var spt = jQuery('span.hireme');
	var at = / at /;
	var dot = / dot /g;
	var addr = jQuery(spt).text().replace(at,"@").replace(dot,".");
	jQuery(spt).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
	.hover(function(){window.status="Send a letter!";}, function(){window.status="";});
	jQuery(spt).remove();
});

jQuery(function(){
	if(jQuery('.pix_diapo').length!=0){
		jQuery('.pix_diapo').diapo({
			time:	5000
		});
	}
});

