function onHover(elt) {	
	$(elt).addClass("resultOnRow-hover");  
}

function onOut(elt) {
	$(elt).removeClass("resultOnRow-hover");
}

$(document).ready(function(){
	
	$('#triSelect').change(function() {
		  document.location = $('#url_'+this.value).html();
	});

	
	$('.resultOnRow').hover(
		function() {
			onHover($(this));
			
			divI = $(this).children('div.item');
			divP = divI.children('div.photobloc');
			hasV = $(divP).children('#hasVideo');
			
			if($(hasV).val() == '1') {
				liVisible = $(divP).children('ul').children('li:visible').children('a');
				var img = $('#imgDivVideo').html();
				$(liVisible).append(img);
			}
		},
		function() {
			onOut($(this));
			
			divI = $(this).children('div.item');
			divP = divI.children('div.photobloc');
			hasV = $(divP).children('#hasVideo');
			
			if($(hasV).val() == '1') {
				liVisible = $(divP).children('ul').children('li:visible').children('a');
				
				$(liVisible).children('#imgVideo').remove();
			}
		}
	);

	$('.item > div:not(.photobloc)').click(
		function(){
			Ahref = $(this).parents('div.item').children('div.modele').children('h3').children('a').attr('href');
			
			if(Ahref == undefined) Ahref = '#undefined';
			
			window.location.href = Ahref;
		}
	);
		
	$('.photobloc > img').click(
		function(e) {
			elt = $(this);
			div = $(elt).parents('div');
			
			ulPhoto = $(div).children('ul.liPhoto');// on selection l'element ul qui correspond
			
			switch ($(elt).attr('class')) {
			case 'next':
				
				liVisible = $(ulPhoto).children('li:visible');
				nextLi = $(liVisible).next('li');
				
				$(liVisible).hide();
				$(nextLi).show(50);
				
				if(!$(nextLi).next('li:hidden').html()) {
					$(div).children('img.next-disable').show();
					$(div).children('img.next').hide();
				}
				
				if($(nextLi).prev('li:hidden').html() != null) {
					$(div).children('img.prev').show();
					$(div).children('img.prev-disable').hide();
				}
				
				break;
			case 'prev':
				
				liVisible = $(ulPhoto).children('li:visible');
				prevLi = $(liVisible).prev('li');
				
				$(liVisible).hide();
				$(prevLi).show(50);
				
				if(!$(prevLi).prev('li:hidden').html()) {
					$(div).children('img.prev-disable').show();
					$(div).children('img.prev').hide();
				}
				
				if($(prevLi).next('li:hidden').html() != null) {
					$(div).children('img.next').show();
					$(div).children('img.next-disable').hide();
				}
				
				break;
			}// end of switch
		}// end of function
	);
});
