// JavaScript Document
var largeur_slide = 500;
var tempo_slide = 0.4;
var nb_dispo_gauche = 0;
var nb_dispo_droite = 0;

var largeur_slide_agrandi = 251;
var tempo_slide_agrandi = 0.4;
var nb_dispo_gauche_agrandi = 0;
var nb_dispo_droite_agrandi = 0;

var startX;
var startY;
var startXAgrandi;
var startYAgrandi;
var is_sliding = false;


function display_agrandi(ID_enregistrement_CMS) {
	if(startXAgrandi!= '' && startYAgrandi!='') {
		recupererObjet('button_next_agrandi').style.visibility = 'hidden';
		recupererObjet('button_prev_agrandi').style.visibility = 'hidden';
		
		var moveAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [startXAgrandi-tabXAgrandi[ID_enregistrement_CMS],startYAgrandi] } }, tempo_slide_agrandi );
		moveAgrandi.animate();
		nb_dispo_gauche_agrandi = tabNbDispoGauche[ID_enregistrement_CMS];
		nb_dispo_droite_agrandi = tabNbDispoDroite[ID_enregistrement_CMS];
		
		comp=(setTimeout("maj_bouton_deroulement_agrandi();",tempo_slide_agrandi*1000));	
	}
}

function maj_bouton_deroulement_agrandi() {
	var new_visibility;
	
	if(nb_dispo_droite_agrandi > 0) {
		new_visibility = 'visible';
	}
	else {
		new_visibility = 'hidden';
	}
	recupererObjet('button_next_agrandi').style.visibility = new_visibility;
	
	if(nb_dispo_gauche_agrandi > 0) {
		new_visibility = 'visible';
	}
	else {
		new_visibility = 'hidden';
	}
	recupererObjet('button_prev_agrandi').style.visibility = new_visibility;
}

function maj_bouton_deroulement() {
	var new_visibility;
	
	if(nb_dispo_droite > 0) {
		new_visibility = 'visible';
	}
	else {
		new_visibility = 'hidden';
	}
	recupererObjet('button_next_listing').style.visibility = new_visibility;
	
	if(nb_dispo_gauche > 0) {
		new_visibility = 'visible';
	}
	else {
		new_visibility = 'hidden';
	}
	recupererObjet('button_prev_listing').style.visibility = new_visibility;
}

YAHOO.namespace('example.anim');

YAHOO.example.anim.init = function() {

	startX = YAHOO.util.Dom.getX('content_listing_index_produit');
	startY = YAHOO.util.Dom.getY('content_listing_index_produit');
	startXAgrandi = YAHOO.util.Dom.getX('content_agrandi_index_produit');
	startYAgrandi = YAHOO.util.Dom.getY('content_agrandi_index_produit');

	var moveRightAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX+largeur_slide,startY] } }, tempo_slide );
	var moveLeftAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX-largeur_slide,startY] } }, tempo_slide );
	var moveRightAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [startXAgrandi+largeur_slide_agrandi,startYAgrandi] } }, tempo_slide_agrandi );
	var moveLeftAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [startXAgrandi-largeur_slide_agrandi,startYAgrandi] } }, tempo_slide_agrandi );
	
	
	var showNext = function(e) {
		recupererObjet('button_next_listing').style.visibility = 'hidden';
		recupererObjet('button_prev_listing').style.visibility = 'hidden';
		startX = YAHOO.util.Dom.getX('content_listing_index_produit');
		startY = YAHOO.util.Dom.getY('content_listing_index_produit');
		moveLeftAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX-largeur_slide,startY] } }, tempo_slide );
		moveRightAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX,startY] } }, tempo_slide );
		moveLeftAnim.animate();
		
		nb_dispo_gauche++;
		nb_dispo_droite--;
		
		comp=(setTimeout("maj_bouton_deroulement();",tempo_slide*1000));		
		
		return false;
	}
	
	var showPrev = function(e) {
		recupererObjet('button_next_listing').style.visibility = 'hidden';
		recupererObjet('button_prev_listing').style.visibility = 'hidden';
		startX = YAHOO.util.Dom.getX('content_listing_index_produit');
		startY = YAHOO.util.Dom.getY('content_listing_index_produit');
		moveLeftAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX,startY] } }, tempo_slide );
		moveRightAnim = new YAHOO.util.Motion('content_listing_index_produit', { points: {to: [startX+largeur_slide,startY] } }, tempo_slide );
		moveRightAnim.animate();
		
		nb_dispo_gauche--;
		nb_dispo_droite++;
		
		comp=(setTimeout("maj_bouton_deroulement();",tempo_slide*1000));		
		
		return false;
	}
	
	var showNextAgrandi = function(e) {
		if(!is_sliding) {
			recupererObjet('button_next_agrandi').style.visibility = 'hidden';
			recupererObjet('button_prev_agrandi').style.visibility = 'hidden';
			is_sliding = true;
			XAgrandi = YAHOO.util.Dom.getX('content_agrandi_index_produit');
			YAgrandi = YAHOO.util.Dom.getY('content_agrandi_index_produit');
			moveLeftAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [XAgrandi-largeur_slide_agrandi,YAgrandi] } }, tempo_slide_agrandi);
			moveRightAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [XAgrandi,YAgrandi] } }, tempo_slide_agrandi );
			moveLeftAnimAgrandi.animate();
			setTimeout("is_sliding = false;",tempo_slide_agrandi);
			
			nb_dispo_gauche_agrandi++;
	
			nb_dispo_droite_agrandi--;
			
			comp=(setTimeout("maj_bouton_deroulement_agrandi();",tempo_slide_agrandi*1000));	
		}
		
		return false;
	}
	
	var showPrevAgrandi = function(e) {
		if(!is_sliding) {
			recupererObjet('button_next_agrandi').style.visibility = 'hidden';
			recupererObjet('button_prev_agrandi').style.visibility = 'hidden';
			is_sliding = true;
			XAgrandi = YAHOO.util.Dom.getX('content_agrandi_index_produit');
			YAgrandi = YAHOO.util.Dom.getY('content_agrandi_index_produit');
			moveLeftAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [XAgrandi,YAgrandi] } }, tempo_slide_agrandi );
			moveRightAnimAgrandi = new YAHOO.util.Motion('content_agrandi_index_produit', { points: {to: [XAgrandi+largeur_slide_agrandi,YAgrandi] } }, tempo_slide_agrandi );
			moveRightAnimAgrandi.animate();
			setTimeout("is_sliding = false;",tempo_slide_agrandi);
			
			nb_dispo_gauche_agrandi--;
			nb_dispo_droite_agrandi++;
			
			comp=(setTimeout("maj_bouton_deroulement_agrandi();",tempo_slide_agrandi*1000));	
		}

		return false;
	}
	
	YAHOO.util.Event.addListener('button_next_listing', 'click', showNext);
	YAHOO.util.Event.addListener('button_prev_listing', 'click', showPrev);
	
	YAHOO.util.Event.addListener('button_next_agrandi', 'click', showNextAgrandi);
	YAHOO.util.Event.addListener('button_prev_agrandi', 'click', showPrevAgrandi);
}

YAHOO.util.Event.addListener(window, 'load', YAHOO.example.anim.init);