var tmpStr = '';
var navOffSet = 0;
var __mzOverride = false;
Event.observe(document, 'dom:loaded', function() {

	navOffSet = $('features-nav').cumulativeOffset()[1];
	
	if ( !__mzOverride ) {
		
		/* Target Test */
		if ( document.location.hash == '' ){
			document.body.id = 'target-selector';
			document.location.hash = 'target-selector';
		} else {
			h = document.location.hash.substr(1);
			document.location.hash = '';
			document.body.id = h;
			document.location.hash = h;
		}
		
		/* http://jsbin.com/afosa */
		__addHTML5Tests();
		
		/* Add our input type tests to HTML */
		__addInputTests();
	
		// Highligh correct tab in Primary navigation
		$$('#home-nav ul a').invoke('observe','click', function() {
			$(this).up('ul').select('li').each(function(e) {
				e.removeClassName('active');
			});
			$(this).up('li').addClassName('active');
		});
		
		/* Modernizer
		------------------------------------------------*/
		if ($$('ul.modernizer-support')[0]) {
			var mzrList = $$('ul.modernizer-support')[0];
		}
		
		// Get the Modernizr Object and convert to a Hash
		var mzr = $H(window.Modernizr);
		
	} else {
		
		document.documentElement.className = '';
		$$('.selector-tests').invoke('removeClassName','selector-tests');
		
		$H(__mzOverride).each(function(pair){
			if ( pair.value == '1' ) {
				// console.log([pair.key,$(pair.key),pair.value]);
				$(pair.key).setStyle({ 
					backgroundImage :'url(/r/i/icons/silk_set_ie6/tick.png)' 
				});
			} else {
				$(pair.key).setStyle({ 
					backgroundImage :'url(/r/i/icons/silk_set_ie6/cross.png)' 
				});
			}
		})
	}
	
	
	
	
	/* Other bits & bobs.. 
	------------------------------------------------*/
	/** Hook up the navigation widget.. */
	Event.observe(window,'scroll',__navScroller);
	 
});

function checkOverwrite(mzr){
	if ( typeof __mzOverride != 'undefined' ) {
		$H(__mzOverride).each(function(pair){
			if ( mzr.get(pair.key) != 'undefined' ) {
				alert( pair.key + " = " + pair.value + " == " + !!(pair.value=='1'));
				mzr.set(pair.key, !!(pair.value=='1'));
			}
		})
	}
}	



function __addHTML5Tests(){
	if ( $('modernizer') ) {
		!!window.localStorage 			&& $('modernizer').addClassName('localstorage');
		!!window.sessionStorage			&& $('modernizer').addClassName('sessionstorage');
		!!window.postMessage			&& $('modernizer').addClassName('postmessage');
		!!window.applicationCache		&& $('modernizer').addClassName('offlineapplications');
		!!window.Worker					&& $('modernizer').addClassName('workers');
		!!document.querySelector		&& $('modernizer').addClassName('queryselector');
		!!window.openDatabase			&& $('modernizer').addClassName('webdatabase');
		//!!navigator.geolocation			&& $('modernizer').addClassName('geolocation');
	}
}


function __addInputTests(){
	inputClasses = [];
	$H( window.Modernizr.inputtypes ).each(function(a,b){
		// God knows what's happened but a prototype/modernizr clash... 
		if (Object.isString(a[0]) && !a[0].startsWith('function')){
			if ( a[1] ) { // true
				inputClasses.push('input-'+a[0]);
			}
		}
	});
	if ( document.documentElement ) {
		document.documentElement.className += ' ' + inputClasses.join( ' ' );
	}
}




















function __navScroller(){
	if ( $('features-nav') ) {
		if( document.body && document.body.scrollTop ) {
			y = document.body.scrollTop;
		} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
			y = document.documentElement.scrollTop;
		} else {
			y = 0;
		}
		
		
	
		if ( y > navOffSet ) {
			if ( !$('features-nav').hasClassName('floating-nav-container') ){
				$('features-nav').addClassName('floating-nav-container');
			}
		} else {
			
			if ( $('features-nav').hasClassName('floating-nav-container') ){
				$('features-nav').removeClassName('floating-nav-container');
			}
		}
	}
}
