/* Author: Brett Gullan

*/

SITE = {
	common : {
		init     : function() {
		},
		finalize : function() {
		}
	},
	
	landing : {
	
		frontpage : function() {
			$('#slideshow')
				.nivoSlider({
					effect: 'sliceDown',
					directionNav: false,
					controlNav: false,
					captionOpacity: 1
				});
		}
	}
};


UTIL = {
	
	namespace:	SITE,

	fire : function(func,funcname, args) {
	
		funcname = (funcname === undefined) ? 'init' : funcname;
		if (func !== '' && UTIL.namespace[func] && typeof UTIL.namespace[func][funcname] == 'function'){
		 	UTIL.namespace[func][funcname](args);
		} 
	}, 
	
	loadEvents : function() {
	
		var bodyId = document.body.id;
		
		// hit up common first.
		UTIL.fire('common');
		
		// do all the classes too.
		$.each(document.body.className.split(/\s+/),function(i,classnm){
			UTIL.fire(classnm);
			UTIL.fire(classnm,bodyId);
		});
		
		UTIL.fire('common','finalize');
	} 
 
};

//
// http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
//
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
//     ie === undefined
// If you're in IE (>=5) then you can determine which version:
//     ie === 7; // IE7
// Thus, to detect IE:
//     if (ie) {}
// And to detect the version:
//     ie === 6 // IE6
//     ie > 7 // IE8, IE9 ...
//     ie < 9 // Anything less than IE9
// ----------------------------------------------------------
 
// UPDATE: Now using Live NodeList idea from @jdalton
 
var ie = (function(){
 
    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');
 
    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );
 
    return v > 4 ? v : undef;
 
}());

// For now, assume that this script ONLY contains UX/UI code.
// Assume that the ENVIRONMENT has been set up, that is, all
// libraries, plugins, shims, etc., have been loaded as required.
// i.e.: DON'T USE yepnope within this script.

// Which means ... the way this script is 'kicked off' may change!

// kick it all off here 
$(document).ready(UTIL.loadEvents);

