$(function(){
	/* Lightbox */
	var name = $('#contenu a').each(function()
	{
		if($(this).children(':first-child').is('img')){
			var href = $(this).attr('href');
			
			var ext = href.substring(href.length-3,href.length);
			if(ext=='jpg' || ext=='gif' || ext=='png')
				$(this).attr('rel','prettyPhoto[gal]');
			css = '';
			$(this).children('img').each(function()
			{
				css = $(this).attr('class');
			});
			if(css!='')
				$(this).addClass(css);
		}
	});
	$('#content a[rel="prettyPhoto[gal]"]').prettyPhoto({theme:'light_square',overlay_gallery:false});

	/* Accueil */
	$('#onglets a:gt(0)').hover(function()
	{
		Onglet($(this).parent('li').index());
	},function(){
		Onglet(0);
	});
	/*$('#onglets a').click(function(event)
	{
		event.preventDefault();
		Onglet($(this).parent('li').index()+1);
	});*/
	equalHeight($("#content .bloc_home"));
	$('#secteur_drop').change(function()
	{
		$(this).parents('form').attr('action', $(this).val()).submit();
	});
	$('#occasion_liste dt a').css('display','block');
	equalHeight($('#occasion_liste dt a'));
	Onglet(0);

});

function Onglet(id)
{
	var current = 0;
	var current = $('#blocs_accueil_pad dl.active').index();
	if(id!=current || id==0)
	{
		$('#blocs_accueil_pad dl').each(function(i)
		{
			if($(this).index() == current)
			{
				/*$(this).stop().addClass('transition_bottom').removeClass('active').find('.img').stop().animate({'opacity':0},100);*/
				$(this).stop().addClass('transition_bottom').removeClass('active');
			}else if($(this).index() == id){
				var image = $(this).children('dd.img').children().first();
				tag = image[0].tagName;
				if(tag=='SPAN')
				{
					var url = $(image[0]).html();
					$(this).children('dd.img').html('<img src="'+url+'" alt="" />');
				}
				/*$(this).stop().removeClass('transition_bottom').addClass('active').css('opacity',0).show().animate(
				{
					'opacity':1
				}, 300).find('.img').stop().css('opacity',1);*/
				$(this).stop().removeClass('transition_bottom').addClass('active').show();
			}else{
				$(this).stop().removeClass('');
			}
			$('#onglets a').removeClass('active');
			$('#onglets a:eq('+id+')').addClass('active');
		});
	}
}
function commercial(id,action)
{
	if(action=='show')
	{		
		$('#conseiller_liste dl[id!="conseiller'+id+'"]').stop().css('margin-left','0');
		$('#conseiller'+id).stop().animate({'margin-left':'50px'}, 500);
	}else if(id=='' && action=='hide'){
		$('#conseiller_liste dl').stop().css('margin-left','0');
	}
}

