var to_handles = [];

function ready() {
	$('.colorbox').colorbox();
	
	cd_Tw.load();
	cd_Ig.load();
	cd_Lfm.load();
}

var cd_Tw = {
	get_url: cd_conf.dir+'/services/twitter/get.php',
	container: '#sidetwitter .body',
	load: function() {
		cd_Tw.init();
		
		$.ajax({
			url: cd_Tw.get_url,
			timeout: 5000,
			success: function(data) {
				if (data.length == 0) {
					cd_Tw.error();
				} else {
					$(cd_Tw.container).html(data);
				}
				clearTimeout(to_handles['Tw']);
			},
			error: function(e) {
				cd_Tw.error();
			}
		});
	},
	init: function() {
		to_handles['Tw'] = setTimeout('cd_Tw.error()', 6000);
	},
	error: function() {
		$(cd_Tw.container).html('Non disponible.');
	}
};

var cd_Ig = {
	get_url: cd_conf.dir+'/services/instagram/get.php',
	container: '#sideinstagram .body',
	load: function() {
		cd_Ig.init();
		
		$.ajax({
			url: cd_Ig.get_url,
			timeout: 5000,
			success: function(data) {
				if (data.length == 0) {
					cd_Ig.error();
				} else {
					$(cd_Ig.container).html(data);
				}
				clearTimeout(to_handles['Ig']);
			},
			error: function(e) {
				cd_Ig.error();
			}
		});
	},
	init: function() {
		to_handles['Ig'] = setTimeout('cd_Ig.error()', 6000);
	},
	error: function() {
		$(cd_Ig.container).html('Non disponible.');
	}
};

var cd_Lfm = {
	get_url: cd_conf.dir+'/services/lastfm/get.php',
	container: '#sidelastfm .body',
	load: function() {
		cd_Lfm.init();
		
		$.ajax({
			url: cd_Lfm.get_url,
			timeout: 5000,
			success: function(data) {
				if (data.length == 0) {
					cd_Lfm.error();
				} else {
					$(cd_Lfm.container).html(data);
				}
				clearTimeout(to_handles['Lfm']);
			},
			error: function(e) {
				cd_Lfm.error();
			}
		});
	},
	init: function() {
		to_handles['Lfm'] = setTimeout('cd_Lfm.error()', 6000);
	},
	error: function() {
		$(cd_Lfm.container).html('Non disponible.');
	}
};
