/* modernizr-test.js
 * Daniel Ott
 * 3 March 2011
 * Custom Tests using Modernizr's addTest API
 */

/* iOS
 * There may be times when we need a quick way to reference whether iOS is in play or not.
 * While a primative means, will be helpful for that.
 */
Modernizr.addTest('ipad', function () {
  return !!navigator.userAgent.match(/iPad/i);
});

Modernizr.addTest('iphone', function () {
  return !!navigator.userAgent.match(/iPhone/i);
});

Modernizr.addTest('ipod', function () {
  return !!navigator.userAgent.match(/iPod/i);
});

Modernizr.addTest('appleios', function () {
  return (Modernizr.ipad || Modernizr.ipod || Modernizr.iphone);
});

/* CSS position:fixed
 * Not supported in older IE browsers, nor on Apple's iOS devices.
 * Actually the token example on the Modernizr docs. http://www.modernizr.com/docs/
 */
Modernizr.addTest('positionfixed', function () {
    var test    = document.createElement('div'),
        control = test.cloneNode(false),
        fake = false,
        root = document.body || (function () {
            fake = true;
            return document.documentElement.appendChild(document.createElement('body'));
        }());

    var oldCssText = root.style.cssText;
    root.style.cssText = 'padding:0;margin:0';
    test.style.cssText = 'position:fixed;top:42px'; 
    root.appendChild(test);
    root.appendChild(control);
    
    var ret = test.offsetTop !== control.offsetTop;

    root.removeChild(test);
    root.removeChild(control);
    root.style.cssText = oldCssText;
    
    if (fake) {
        document.documentElement.removeChild(root);
    }
    
    /* Uh-oh. iOS would return a false positive here.
     * If it's about to return true, we'll explicitly test for known iOS User Agent strings.
     * "UA Sniffing is bad practice" you say. Agreeable, but sadly this feature has made it to
     * Modernizr's list of undectables, so we're reduced to having to use this. */
    return ret && !Modernizr.appleios;
});

var home = false;

var minHeight = 927;
var socialiseVisible = false;

$(document).ready(function(){
	home = $('#me').length>0;
	
	resize ();
	checkScroll ();
	
	$(window).resize (resize);
	$(window).scroll(checkScroll);
  });

function checkScroll ()
{
	if (!home)
	{
		var y = $(document).scrollTop()+$(window).height();
		var height = $(document).height()-10;
		log (y+":"+height)
		if (y > height)
		{
			if (!socialiseVisible)
			{
				$('#socialise').fadeIn();
				socialiseVisible = true;
			}
		} else 
		{
			if (socialiseVisible)
			{
				$('#socialise').fadeOut();
				socialiseVisible = false;
			}
		}
	}
}

function resize ()
{
	var windowHeight = $(window).height();
	
	if (windowHeight > minHeight)
		$('#meContainer').addClass('fixed');
	else
		$('#meContainer').removeClass('fixed');
	
	if (windowHeight > 700)
		$('#quoteContainer').addClass('fixed'); 
	else
		$('#quoteContainer').removeClass('fixed');

}


// Hide address bar in Mobile Safari and Android
if (window.addEventListener)
	window.addEventListener("load",loaded,false);

function loaded () {
	  // Set a timeout...
	  setTimeout(function(){
	    // Hide the address bar!
	    window.scrollTo(0, 1);
	  }, 100);
}

var myScroll;

