function moveIcons(direction,decal) {
	if (direction == 'left') {
		var thediv = $('#bande_ticker div').eq(0);
		var margleft = parseInt(thediv.css('margin-left'));
		if (margleft <= -79) {
			var div = thediv.html();
			var id = thediv.attr('id');
			thediv.remove();
			$('#bande_ticker').append('<div id="'+id+'">'+div+'</div>');
			rebindDivTicker();
		}
		else {
			thediv.css('margin-left',(margleft-decal)+'px');
		}
	}
	else {
		var thediv = $('#bande_ticker div').eq(0);
		var lastdiv = $('#bande_ticker div').last();
		var margleft = parseInt(thediv.css('margin-left'));
		if (margleft >= 0) {
			var div = lastdiv.html();
			var id = lastdiv.attr('id');
			lastdiv.remove();
			$('#bande_ticker').prepend('<div id="'+id+'" style="margin-left:-79px;">'+div+'</div>');
			rebindDivTicker();
		}
		else {
			thediv.css('margin-left',(margleft+decal)+'px');
		}	
	}
}
function rebindDivTicker() {
	$('div#bande_ticker div').unbind('mouseover').unbind('mouseout');
	$('div#bande_ticker div').bind('mouseover',function() {
		clearInterval(tickerMove);
		id = $(this).attr('id');
		$('div#bande_ticker div').each(function() {
			if ($(this).attr('id') != id) {
				$(this).css('opacity','0.4');
			}
		});
	})
	.bind('mouseout',function() {
		clearInterval(tickerMove);
		tickerMove = setInterval(function() { moveIcons('right',1) },50);
		$('div#bande_ticker div').css('opacity','1');
	})
	.bind('click',function() {
		var idicon = $(this).attr('id').split('_');
		function callback() {
			idApp = parseInt(idicon[1]);
			reloadApp();
		}
		if (page != 2) {
			page = 2;
			changePage(callback);
		}
		else {
			callback();
		}
	});
}
function appTicker() {
	document.write('<div id="app_ticker"><div id="toleft_ticker"><div id="alpha_gauche"><img src="design/img/alpha_gauche.png" /></div></div><div id="toright_ticker"><div id="alpha_droite"><img src="design/img/alpha_droite.png" /></div></div></div>');
	$.ajax({
			url: "ajax/getAppInfo.php",
			type: "POST",
			data: ({info : "infos_ticker"}),
			async: true,
			success: function(jsdatas) {
				var datas = eval('('+jsdatas+')');
				var html = '<div id="bande_ticker">';
				for (icon in datas.icons) {
					html += '<div id="iconticker_'+datas.icons[icon].id+'"><img src="'+datas.icons[icon].src+'" alt="icon" /><span>'+datas.icons[icon].name+'</span></div>';
				}
				html += '</div>';
				$('#app_ticker').append(html);
				tickerMove=setInterval(function() {moveIcons('right',1)},50);
				$('#toleft_ticker').bind('mouseover',function() { clearInterval(tickerMove);tickerMove=setInterval(function() {moveIcons('right',2)},10); }).bind('mouseout',function() { clearInterval(tickerMove);tickerMove=setInterval(function() {moveIcons('right',1)},50); });
				$('#toright_ticker').bind('mouseover',function() { clearInterval(tickerMove);tickerMove=setInterval(function() {moveIcons('left',2)},10); }).bind('mouseout',function() { clearInterval(tickerMove);tickerMove=setInterval(function() {moveIcons('right',1)},50); });
				rebindDivTicker();
			}
	}).responseText;
}
