/* Author: */
BrowserDetect.init();

if (!efficacitic) {	
	var efficacitic = {
		settings: {
			debugMode: true,
			nbLoading: 0,
			oCountry:null,
			oLoading: null,
			oBody: null,
			oMain: null,
			strings: {
				errors: {
					failure: "Sorry, but this website can't run on your browser!",
					success: "Thank's mate ... good job",
					status: "...",
					unknown: "Whoops, something inexplicably went wrong. Sorry!"
				},
				messages: {
					loading: " ' l o a d i n g ' "
				}
			}
		},
		extendSettings: function(cfg) {
			return $.extend(efficacitic.settings, cfg);
		},
		common: {
			init: function() {
				efficacitic.debug.log(' common.init executed  ');

				if(BrowserDetect.OS=="Mac"){
					$('html').addClass("isMac" );
				}

				if(BrowserDetect.browser=="Safari"){
					$('html').addClass("safari" );
				}

				efficacitic.settings.oLoading			= $('<div />', { 'id': 'loading' });

				efficacitic.settings.oBody				= $('body');
				efficacitic.settings.oMain				= $('#container');
				efficacitic.settings.oLoading.hide().appendTo(efficacitic.settings.oBody);
				efficacitic.loading.init();
				efficacitic.loading.start();
				
			},
			finalize: function() {
				efficacitic.debug.log(' common.finalize executed  ');
				$(document).bind('finalized',function(){
					efficacitic.debug.log(' super low priority scripts are going here ');
				});

				efficacitic.loading.stop();
			}
		},

		blog: {
			init: function() {
				efficacitic.debug.log(' blog.init executed ');
			},
			show: function() {
				efficacitic.debug.log(' blog.show executed ');
			}
		},
		
		home: {
			init: function() {
				efficacitic.debug.log(' home.init executed ');
				(function(r,o){var t=navigator.appVersion.match(/MSIE/i)?navigator.appVersion.replace(/.*?MSIE ([^;]+);.*/i,"$1"):null;function u(c,a){var b,d={};for(b in a){d[b]=a[b]}for(b in c){d[b]=c[b]}return d}function v(c,a){return(a||o).getElementsByTagName(c)}function w(){var c,a,b=r,d=o,e=d.documentElement,f=d.body;if(b.innerWidth){c=b.innerWidth;a=b.innerHeight}else if(e.clientWidth){c=e.clientWidth;a=e.clientHeight}else{c=f.clientWidth;a=f.clientHeight}return{'w':c,'h':a}}function x(){var c=o,a=c.documentElement,b=c.body,d,e;e=a.scrollHeight;d=a.scrollWidth;if(a.clientHeight>e){e=a.clientHeight}if(a.clientWidth>d){d=a.clientWidth}if(b.scrollHeight>e){e=b.scrollHeight}if(b.scrollWidth>d){d=b.scrollWidth}return{'w':d,'h':e}}function y(c,a,b,d){if(c.addEventListener){c.addEventListener(a,b,d)}else{c.attachEvent("on"+a,b)}}function s(c,a){for(var b in a){c.style[b]=a[b]}}function p(c,a){a=(a==1)?0.99999:a;c.style.opacity=a;c.style.filter='alpha(opacity='+a*100+')';c.style.MozOpacity=a;c.style.KhtmlOpacity=a}function z(c,a,b,d){this.elem=c||o.body;this.to=a!==undefined?a:1;var e=this.elem.style;this.from=(b===undefined?(!e.opacity&&e.opacity!==0?(this.to>0?0:1):parseFloat(e.opacity)):b);d=d||{};this.duration=d.duration||500;this.frameRate=d.frameRate||30;this.onFinish=d.onFinish;this.totalFrames=Math.ceil(this.duration/1000*this.frameRate);this.perFrame=(this.to-this.from)/this.totalFrames;this.frameNb=0;var f=this;this.next=function(){this.prog=setTimeout(function(){f.frame()},1000/this.frameRate)};this.frame=function(){p(this.elem,this.from+this.perFrame*this.frameNb);if(this.frameNb===this.totalFrames){p(this.elem,this.to);if(typeof this.onFinish=='function'){setTimeout(this.onFinish,1)}}else{this.frameNb++;this.next()}};this.next()}function A(c,a,b){var d,e,f,j,k,l,i,g,h;b=b||{};d=b.max_w;e=b.min_w;f=b.max_h;j=b.max_h;k=b.round===undefined?1:b.round;l=c/a;i=a/c;g=a;h=c;if(h<e){h=e;g=h*i}if(g<j){g=j;h=g*l}if(d&&(h>d)){h=d;g=h*i}if(f&&(g>f)){g=f;h=g*l}h=h<0?0:h;g=g<0?0:g;return{w:k?Math.round(h):h,h:k?Math.round(g):g}}var q={defaults:{mode:'max',enlarge:1,reduce:1,ffHack:0,zIndex:-1,position:'absolute',align:'center',vertAlign:'top',fadeAfter:400,fadeOptions:{duration:250,frameRate:25}},redim:function(){var c=q,a,b,d=w(),e,f,j,k,l,i,g,h,m,n;a=c.img;f=j=k=l='';b=c.opt;i=a.fileDim;if(i){if(b.mode=='full'){g=m=d.w;h=n=d.h;if(!b.enlarge){if(g>i.w){g=m=i.w}if(h>i.h){h=n=i.h}}if(!b.reduce){if(m<i.w){m=i.w;g=Math.max(m,g)}if(n<i.h){n=i.h;h=Math.max(n,h)}}}else{m=g=d.w;n=h=0;if(!b.reduce){g=0}}i=A(i.w,i.h,{min_w:m,win_h:n,max_w:g,max_h:h,round:1});a.width=i.w;a.height=i.h;if(!a.width){a.removeAttribute("width")}if(!a.height){a.removeAttribute("height")}switch(b.align){case'left':k='0px';break;case'right':l='0px';break;default:k=-Math.round((i.w-d.w)/2)+'px'}if(b.vertAlign=='bottom'){j='0px'}else if(b.vertAlign=='middle'){e=b.position=="fixed"?d.h:x().h;f=(-b.ffHack+(e-a.offsetHeight)/2)+"px"}else{f=a.hack||'0px'}s(a,{left:k,right:l,top:f,bottom:j})}},show:function(){var c=q,a;a=c.img;a.fileDim={w:a.naturalWidth||a.clientWidth,h:a.naturalHeight||a.clientHeight};c.redim();if(c.fadeIt){z(c.img,1,0,c.opt.fadeOptions)}else{p(a,1)}},init:function(c,a){var b=q,d=v('body')[0],e,f,j;a=u(a,this.defaults);if(t&&t<7){a.position='absolute'}b.opt=a;e=a.fadeAfter;f=b.img=o.createElement('img');f.id="homeBkg";s(f,{zIndex:a.zIndex,position:a.position});j=navigator.userAgent.match(/Firefox.(\d+(\.\d+))/);if(j&&parseFloat(j[1])<3){s(d,{zIndex:0,position:'relative',top:0,left:0});f.hack='-'+a.ffHack}d.insertBefore(f,d.childNodes[0]);f.onload=b.show;if(e!==false){p(f,0);if(e){setTimeout(function(){b.fadeIt=1},e)}else{b.fadeIt=1}}y(r,'resize',b.redim);f.src=c}};r.homeBkg=q})(window,document);
			},
			fullbkg: function() {
				efficacitic.debug.log(' home.dropdown executed ');
				homeBkg.init(image_fond);
				$(function() {
				    $("ul.topnav li:has(.subnav)").hover(function() {
				        $("ul.subnav", this).slideDown('fast').show();
				    }, function() {
				        $("ul.subnav", this).slideUp('slow');
				    });
				});
			}
		},
		
		require: {
			init: function(modules, clb) {
				var mod = [];
				$.each(modules, function(i, v) {
					mod.push('lib/front/js/efficacitic.'+v+'.js');
				});
				require(mod, clb); // to use once the require engine is set up
			}
		},

		strings: {
			getString: function(prop) {
				var props = prop.split('.'),
					string = efficacitic.settings.strings,
					args = arguments;
				for (var i = 0; i < props.length; i++)
					string = string[props[i]] || {};
				if (typeof(string) != "string")
					string = "";
				return string;
			},
			setString: function (prop, val) {
				var props = prop.split('.'),
					container = efficacitic.settings.strings;
				for (var i = 0; i < props.length - 1; i++) {
					if (!container[props[i]]) {
						container[props[i]] = {};
					}
					container = container[props[i]];
				}
				container[props[i]] = value;
			}
		},

		debug: {
			log: function(msg, important) {
				if (!efficacitic.settings.debugMode)
					{return;}
				if (window.console && console.log)
					{window.console.log(msg);}
				else if (important)
					{alert(msg);}
			},
			error: function(msg, e) {
				if (!efficacitic.settings.debugMode)
					{return;}
				if (window.console && console.error)
					{window.console.error(msg);}
				else if (important)
					{alert(msg);}
			},
			fail: function(msg) {
				alert(efficacitic.strings.getString('errors.failure'));
			}
		},

		loading: {
			init: function() {
				efficacitic.debug.log(' loading executed  ');
				efficacitic.settings.oLoading.text(efficacitic.strings.getString('messages.loading'));
				efficacitic.debug.log(efficacitic.strings.getString('messages.loading'));
			},
			reinit: function() {
				efficacitic.settings.nbLoading = 0;
				efficacitic.loading.hide();
			},
			show: function() {
				efficacitic.settings.oLoading.show();
			},
			hide: function() {
				efficacitic.settings.oLoading.fadeOut(600);
			},
			start: function() {
				if (efficacitic.settings.nbLoading === 0)
				{
					efficacitic.loading.show();
				}
				efficacitic.settings.nbLoading++;
			},
			stop: function() {
				efficacitic.settings.nbLoading = Math.max(efficacitic.settings.nbLoading-1, 0);
				if (efficacitic.settings.nbLoading === 0)
				{
					efficacitic.loading.hide();
				}
			}
		}
	};
}

UTIL = {
	exec: function( controller, action ) {
		var ns = efficacitic,
			action = ( action === undefined ) ? "init" : action;

		if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
			ns[controller][action]();
		}
	},

	init: function() {
		var body = $("body"),
			controller = body.data( "controller" ),
			action = body.data( "action" );

		UTIL.exec( "common" );
		UTIL.exec( controller );
		UTIL.exec( controller, action );
		UTIL.exec( "common", "finalize" );
	}
};

$(document).ready(function() {
	UTIL.init();
});























