/**
* @package  genious
* @subpackage www
* @author
* @contributor
* @copyright
*/

if (typeof $.fn.imagesActives == 'undefined'){
	$.fn.imagesActives = function() {
		function log() {
			if (!$.debug || !window.console || !window.console.log) {return;}
			if (typeof window.console !='undefined'){
		    	window.console.log('[imagesActives context]' + [].join.call(arguments,''));
		    }
		}

		function setImageState (image){
			if (image.width==1){
				$('body').addClass('imagesactives').removeClass('noimages').removeClass('initDetection');
				log('We are in images actives mode');
			}else{
				$('body').addClass('noimages').removeClass('imagesactives').removeClass('initDetection');
			}
			$('.imageDisplayDetector , .imageDisplayState, #imageDetect').remove();
		}

		return this.each(function() {
			log('Detecting image state '+  this.width+' that was the width' );
			if ( this.width !== 'undefined' && this.complete == true ) {
				setImageState(this);
			} else {
				$(this).load(function(){setImageState(this)});
			}
	    });
	 };
}





//load editor for textarea inside jcms , check jquery.wymeditor.js for valid options
jQuery(function() {
	// before getting locale, juste hide immediatly
	var locale = $('html').attr('lang') ;
	//$('html').addClass('loading');
	// and start loading images
	//$.preloadCssImages({onComplete:function(){$('#cacheTout').remove();} });
	$.debug=true;
	log('getting translation');

$.localise('/genious/js/locales' , {language:locale.substring(0,2)} );

	//$('body').removeClass('noscriptmode').append('<div id="cacheTout" style="position:absolute;top:0;left:0;width:100%;height:150em;background-color:#fff;z-index:100;"><h1 id="chargement">'+chargement+'</h1></div>');
	$('body').removeClass('noscriptmode').append('<div id="cacheTout" style="display:none;"><h1 id="chargement">'+chargement+'</h1></div>');



	log('Showing loading');
	//var bodyHeight = $('body').css('display', 'block' ).height();
	log('Detecting images state');
	$('img.imageDisplayDetector').imagesActives();
	log('Start loading other scripts ');

	//$('#cacheTout').css('height',(bodyHeight*2)+'px');




	function log() {
			if (!$.debug || !window.console || !window.console.log) {return;}
			if (typeof window.console !='undefined'){
		    	window.console.log('[preload context]' + [].join.call(arguments,''));
		    }
	}

});