
StarterNews = 0;
NbNewsPerPage = 13;

StarterUne = 0;
NbUnePerPage = 3;


$(document).ready(function(){

	$("#moduleNews  #prevNews a").css('display','none');
	$("#moduleUne  #prevUne a").css('display','none');
	// If Index? 
	clickForSwitchNews = function(){
		$("#moduleNews  #nextNews a").click(function(){
			
			 $("#moduleNews #mNews, #moduleNews #oNews").animate({'margin-left' : '-100px', 'opacity':0},400);
					
			 StarterNews = (StarterNews+NbNewsPerPage);
			 setTimeout(function(){
					$.ajax({
						type : "POST",
						url : "loadIndexNews.php",
						data : "starter=" +StarterNews,
						success:function(dom){
							$("#moduleNews").html(dom);
							SetLinksLoad();
							PreLoadLinks();
					
					
							$("#moduleNews #mNews, #moduleNews #oNews").css({ 'margin-left' : '100px', 'opacity':0});
							$("#moduleNews #mNews, #moduleNews #oNews").animate({'margin-left' : '0px', 'opacity':1},400);
							NbOccurence = $("#moduleNews #oNews ul li").length;
							if(NbOccurence<NbNewsPerPage){
								$("#moduleNews  #nextNews a").css('display','none').data('hide',true);
							}
							clickForSwitchNews();
						}
					});
			},350);
		});
		
		
		$("#moduleNews  #prevNews a").click(function(){
			 $("#moduleNews #mNews, #moduleNews #oNews").animate({'margin-left' : '100px', 'opacity':0},400);
			 StarterNews = (StarterNews-NbNewsPerPage);
			 if(StarterNews<0) StarterNews = 0;
			 setTimeout(function(){
					$.ajax({
						type : "POST",
						url : "loadIndexNews.php",
						data : "starter=" +StarterNews,
						success:function(dom){
							$("#moduleNews").html(dom);
							SetLinksLoad();
							PreLoadLinks();
									$("#moduleNews #mNews, #moduleNews #oNews").css({ 'margin-left' : '-100px', 'opacity':0});
									$("#moduleNews #mNews, #moduleNews #oNews").animate({'margin-left' : '0px', 'opacity':1},400);
							clickForSwitchNews();
							if(StarterNews<=0)
							{
								$("#moduleNews  #prevNews a").css('display','none').data('hide',true);
							}
						}
					});
			  },350);
				
		});
	}
	clickForSwitchNews();
	
	clickForSwitchUne = function(){
		$("#moduleUne  #nextUne a").click(function(){
			
			 $("#moduleUne #fUne, #moduleUne #sUne, #moduleUne #tUne").animate({'margin-top' : '-100px', 'opacity':0},400);
					
			 StarterUne = (StarterUne+2);
			 
			 setTimeout(function(){
					$.ajax({
						type : "POST",
						url : "loadIndexUne.php",
						data : "starter=" +StarterUne,
						success:function(dom){
							$("#moduleUne").html(dom);
							SetLinksLoad();
							PreLoadLinks();
					
							$("#moduleUne #fUne, #moduleUne #sUne, #moduleUne #tUne").css({ 'margin-top' : '100px', 'opacity':0});
							$("#moduleUne #fUne, #moduleUne #sUne, #moduleUne #tUne").animate({'margin-top' : '0px', 'opacity':1},400);
							NbOccurence = $("#moduleUne .cadreUne").length;
							if(NbOccurence<NbUnePerPage){
								$("#moduleUne  #nextUne a").css('display','none').data('hide',true);
							}
							clickForSwitchUne();
						}
					});
			},350);
		});
		
		
		$("#moduleUne  #prevUne a").click(function(){
			 $("#moduleUne #fUne, #moduleUne #sUne, #moduleUne #tUne").animate({'margin-top' : '100px', 'opacity':0},400);
			 StarterUne = (StarterUne-NbUnePerPage);
			 if(StarterUne<0) StarterUne = 0;
			 setTimeout(function(){
					$.ajax({
						type : "POST",
						url : "loadIndexUne.php",
						data : "starter=" +StarterUne,
						success:function(dom){
							$("#moduleUne").html(dom);
							SetLinksLoad();
							PreLoadLinks();
							clickForSwitchUne();
							if(StarterUne<=0)
							{
								$("#moduleUne  #prevUne a").css('display','none').data('hide',true);
								
							}
						}
					});
			  },350);
				
		});
	}
	clickForSwitchUne();
	
	$("#modulesIndex div.modulesIndex").css('opacity',0.9);
	$("#modulesIndex div.modulesIndex").hover(function(){ $(this).css('opacity',1)},function(){ $(this).css('opacity',0.9); });
	
	$("#archives a").click(function(){
		$.ajax({
			type : "GET",
			url : "news.load.php",
			data : "page=1",
			success:function(result){
				$("#contentArchive").html(result);
			}
		});
		if($("body").find('#archiveLoader').is('#archiveLoader'))
			return;
			
		$("body").append('<div id="archiveLoader"><div id="contentArchive"></div><div id="col1" class="elems"></div><div id="col2" class="elems"></div><div id="teles" class="elems"></div><div id="chao" class="elems"></div><a href="javascript:void(0)" id="closeArchive"></a<</div>');
		al = $("#archiveLoader");
		$('a#closeArchive').click(function(){
			
			$(this).parent().remove();
			
		});
		$(al).animate({
			height : '399px',
			'margin-top' : '-200px'
		},1200,function(){
			$('#col1').animate({
				height : '190px',
				opacity : 1
			},800);	
			$("#contentArchive").animate({
				height : '100%'
			},1000);
			
			setTimeout(function(){
				$('#chao').animate({
					'margin-top':'0px',
					opacity : 1
				},1000,function(){
					$(this).animate({
						opacity : 0.75
					},1600,function(){
						$(this).animate({
							opacity : 1
						},1600);
					});
				});	
			},300);
			
			setTimeout(function(){
				$('#col2').animate({
					height : '71px',
					opacity : 1
				},500);	
			},400);
			setTimeout(function(){
				$('#teles').animate({
					height : '394px',
					opacity : 1
				},500);	
			},500);
			
		});
	});	
});

