$j(document).ready( function(e) {
	$j('.videoThumbs').live('mouseover', function() {
		var index = $j(this).attr('id');
		first_thumbs[index] = $j(this).attr('src');
		startThumbChange(index, $j(this).attr('images'), 'http://www.foufounette.net/thumbs/');
	});
	$j('.videoThumbs').live('mouseout', function(){
		endThumbChange($j(this).attr('id'));
	});
});

var changing_thumbs = new Object();
var first_thumbs = new Object();

function changeThumb(index, i, thumbs, path)
{
	if (changing_thumbs[index] && thumbs.indexOf(';') != -1)
	{	
		var thumbs_array = thumbs.split(";");

		$j('#'+index).attr('src', path + thumbs_array[i]);

		if (++i == thumbs_array.length) i=0;
		changing_thumbs[index] = setTimeout("changeThumb('" + index + "'," + i + ",'" + thumbs + "', '" + path + "')", 600);
	}
}

function startThumbChange(index, thumbs, path)
{
	if(thumbs.substr(0, 7) == 'http://'){
		path='';
	}	
	changing_thumbs[index] = true;	
	changeThumb(index, 0, thumbs, path);
}

function endThumbChange(index)
{
	clearTimeout(changing_thumbs[index]);
	$j('#'+index).attr('src', first_thumbs[index]);
	changing_thumbs[index] = false;	
}



// CATEGORIES
function toggleCategories(show){
	if (show){
		show_div( getbyid( 'categories'  ) );
		hide_div( getbyid( 'MenuCateg1'  ) );
		show_div( getbyid( 'MenuCateg0'  ) );
	}
	else{
		hide_div( getbyid( 'categories'  ) );
		show_div( getbyid( 'MenuCateg1'  ) );
		hide_div( getbyid( 'MenuCateg0'  ) );
	}
}

function hide_div(itm){
	itm.style.display = "none";
}

function show_div(itm){
	itm.style.display = "";
}

function getbyid(id){
	itm = null;
	
	if (document.getElementById){
		itm = document.getElementById(id);
	}
	else if (document.all){
		itm = document.all[id];
	}
	else if (document.layers){
		itm = document.layers[id];
	}
	return itm;
}



// ETOILES
function changeStars (num, type, idgal){
	document.getElementById('vote_video_'+idgal).style.backgroundPosition = '0px -'+(type?'27':'0')+'px';
	document.getElementById('vote_video_'+idgal).style.width = num+'%';
}

function vote (vote_num, video_id){
	$j.ajax({
		cache: false,
		type: "POST",
		data: { note: vote_num, video : video_id },
		url: 'http://www.foufounette.net/ajax/vote.php',
		success: function(result){
			if (result.indexOf('|')) {
				update = result.split('|');
				$j('#stars_'+video_id).html('');
				if (isNaN(parseInt(update[0])) && isNaN(parseFloat(update[0]))) {
					changeStars('80', '2', video_id);
				}
				else {
					changeStars(update[0], 2, video_id);
				}

				if (!isNaN(parseInt(update[1]))) {
					$j('#num_voters_'+video_id).html(update[1]);
				}
			}
		}
	});
}




function click (video_id){
	$j.ajax({
		cache: false,
		type: "POST",
		data: { video : video_id },
		url: 'http://www.foufounette.net/ajax/click.php',
		success: function(result){
			if (result.indexOf('|')) {
				update = result.split('|');
				if (!isNaN(parseInt(update[0]))) {
					$j('#num_vues_'+video_id).html(update[0]);
				}
			}
		}
	});
}


