/**
 * Initalization
 * @author Ambroise Maupate
 */

/* -------------------------------------------------
Cache
--------------------------------------------------*/
if (window.applicationCache) {
	window.applicationCache.addEventListener("updateready", updateCache, false);
}
jQuery.easing.def = "easeOutCubic";

$.ajaxSetup ({
// enable caching of AJAX responses
cache: true
});

jQuery(document).ready(function($) {
	/* -------------------------------------------------
	Site init
	--------------------------------------------------*/
	newsLoop = setInterval(launchNews, 7000);
	
	// use videoJS for html5
	VideoJS.setupAllWhenReady();

	$.history.init(function(hash){
		if(hash == "") {
		    // initialize your app
			delay = window.setTimeout(showVignettes, 100);
			//var delay1 = setTimeout(rearrangeVignettes, 500);
			
			$("#ajax_loader").fadeOut();
		}
		else {
			
			if ($('body').hasClass("vignettes_showed") == false ) {
				delay = window.setTimeout(showVignettes, 100);
			};
			// restore the state from hash
			// our hash is #!/
			var hash = hash.substring(2, hash.length);
			//alert(hash);
			loadData( hash );
	    }
		
		generateTopPageLinks();
		
		try {
			window.applicationCache.update();
		} catch(myError) {
		    //this catches the error and alerts the message
		    console.log( myError.message );
		}
	},
	{ unescape: ",/" });

});

function updateCache() {
	window.applicationCache.swapCache();
}
