/*================================================================
	JOURNAL DU 4x4 -> JS --------------------------------------------
================================================================*/

//Ajouter aux favoris
function ajouterFavoris() 
{	
	if (navigator.appName != 'Microsoft Internet Explorer')
	{ 
		window.sidebar.addPanel("Journal du 4x4","http://www.journaldu4x4.com",""); 
	}
	else 
	{
		window.external.AddFavorite("http://www.journaldu4x4.com","Journal du 4x4"); 
	} 
}


$(document).ready(function()
{
	/*-------------------------------------
		pour la page sommaire
	-------------------------------------*/
	$('#colonne1 #sommaire .item').eq(4).css('border', '0px');
	$('#colonne1 #sommaire .item').eq(4).css('margin-top', '0px');
	
	
	
	
	/*-------------------------------------
		Recherche
	-------------------------------------*/
	$('.formulaire_recherche').mouseover(function()
	{
		$('input', this).css('color', '#434343');
		$('input[type="image"]', this).attr('src', '/jd4x4Skel/images/menu-btn-rechercher-on.png');
	});
	
	$('.formulaire_recherche input[type="text"]').click(function()
	{
		if($(this).val()=='Rechercher')
		{
			$(this).val('');
		}						
	});
	
	$('.formulaire_recherche').mouseout(function()
	{
		$('input', this).css('color', '#d6d6d6');
		$('input[type="image"]', this).attr('src', '/jd4x4Skel/images/menu-btn-rechercher.png');
	});
	
	//Gestion styles des liens
	$('#sommaire #colonne1 .item .logo').mouseover(function()
	{
		$(this).next('.infos').children('.titre').find('a').css('text-decoration', 'underline');
	});
	
	$('#sommaire #colonne1 .item .logo').mouseout(function()
	{
		$(this).next('.infos').children('.titre').find('a').css('text-decoration', 'none');
	});
	
	
	$('#sommaire #colonne1 .articleFonce .logo').mouseover(function()
	{
		$(this).next('.infos').children('.titre').find('a').css('text-decoration', 'underline');
	});
	
	$('#sommaire #colonne1 .articleFonce .logo').mouseout(function()
	{
		$(this).next('.infos').children('.titre').find('a').css('text-decoration', 'none');
	});
	
	$('#sommaire #colonne1 .item .titre a').mouseover(function()
	{
		$(this).css('text-decoration', 'underline');
	});
	
	$('#sommaire #colonne1 .item .titre a').mouseout(function()
	{
		$(this).css('text-decoration', 'none');
	});
	
	
	$('#sommaire #colonne1 .articleFonce .titre a').mouseover(function()
	{
		$(this).css('text-decoration', 'underline');
	});
	
	$('#sommaire #colonne1 .articleFonce .titre a').mouseout(function()
	{
		$(this).css('text-decoration', 'none');
	});
	
	
	//Colonne Centre
	$('#colonne2 .item .texte').mouseover(function()
	{
		$(this).parent().find('.entete').css('text-decoration', 'underline');
	});
	
	$('#colonne2 .item .texte').mouseout(function()
	{
		$(this).parent().find('.entete').css('text-decoration', 'none');
	});
	
	$('#colonne2 .item .logo').mouseover(function()
	{
		$(this).parent().find('.entete').css('text-decoration', 'underline');
	});
	
	$('#colonne2 .item .logo').mouseout(function()
	{
		$(this).parent().find('.entete').css('text-decoration', 'none');
	});
	
	
	/*-------------------------------------
		Menu
	-------------------------------------*/
	$('#menu .item').mouseover(function()
	{
		$('#menu .item a').css('color', '#434343');
		$('a', this).css('color', '#000000');
		
		//Gestion du rollOver
		$('.onGauche').remove();
		$('.onCentre').remove();
		$('.onDroite').remove();
		largeur=$(this).width();
		marginLeft=largeur-4;
		largeur=largeur-8;
		$(this).prepend('<div class="onGauche"></div><div class="onCentre" style="width:'+largeur+'px;"></div><div class="onDroite" style="margin-left:'+marginLeft+'px;"></div>');
		
		//Gestion du sous-menu
		val=$(this).attr('id').substring(4);
		$('#sousMenu .blocSousMenu').hide();
		$('#sousMenu'+val).show();
	});
	
	$('#menu .separateur:last').remove();
	
	$('#sousMenu .blocSousMenu').each(function(index) 
	{
		$('.separateur:last', this).remove();
	});
	
	
	//Refermer les zones de test
	$(document).click(function(e)
	{
		var el= e.target||event.srcElement;
		classClic=el.getAttribute('class');
		if(classClic!='select' && classClic!='gauche resultat btnMenuListe' && classClic!='titre' && classClic!='btnMenuListe')
		{
			$('.contenuSelect').hide();
		}
	});
	
	/*-------------------------------------
		Zone test marques, pneus et accessoires
	-------------------------------------*/
	$('#tete #bandeauInf .zoneTest .select').click(function() 
	{		
		$('.contenuSelect').hide();	
		$(this).parents('.itemTest').children('.contenuSelect').css('display', 'block');
	});
	
	/*-------------------------------------
		Liste des annonces
	-------------------------------------*/
	var animationPosition=0;
	var animationAnnonce=0;
	var tabAnnonce=[];					
	
	$('#tete #annonces .flecheGauche').click(function()
	{
		if(animationAnnonce==0 && animationPosition>0)
		{
			animationAnnonce=1;
			animationPosition--;
			
			nMarginLeft=parseInt($('#tete #annonces .liste .ascenseur').css('margin-left'))+260;
			$('#tete #annonces .liste .ascenseur').animate({marginLeft:nMarginLeft}, 'normal', function()
			{
				animationAnnonce=0;
			});
		}
	});
	
	$('#tete #annonces .flecheDroite').click(function()
	{
		if(animationAnnonce==0)
		{
			animationAnnonce=1;
			animationPosition++;
			
			if(tabAnnonce[animationPosition]!=1)
			{
				$.ajax({
					type: "POST",
					url: "/spip.php?page=ajax-annonce&var_mode=recalcul",
					data: "position="+animationPosition,
					success: function(msg)
					{
						$('#tete #annonces .liste .ascenseur').append(msg);
						
						nMarginLeft=parseInt($('#tete #annonces .liste .ascenseur').css('margin-left'))-260;
						$('#tete #annonces .liste .ascenseur').animate({marginLeft:nMarginLeft}, 'normal', function()
						{
							animationAnnonce=0;
							tabAnnonce[animationPosition]=1;
						});
					}
				});
			}
			else
			{
				nMarginLeft=parseInt($('#tete #annonces .liste .ascenseur').css('margin-left'))-260;
				$('#tete #annonces .liste .ascenseur').animate({marginLeft:nMarginLeft}, 'normal', function()
				{
					animationAnnonce=0;
					tabAnnonce[animationPosition]=1;
				});
			}
		}
	});
	
	
	
	/*-------------------------------------
		Article
	-------------------------------------*/
	$('#article .forum:last').css('border', '0px');	;	
});

$(window).load(function()
{
	/*-------------------------------------
		Pied de page
	-------------------------------------*/
	$('#pied .colonne').css('height', $('#pied').height()+'px');
});
