/*=============================================================================
script :        anim_image.js
auteur :        Rémi Buisson
contenu :       Script Javascript : fonction permettant l'animation d'image : changer une image toutes les X ms
											
date creation : 15/09/2008

modifications :
=============================================================================*/
//--------------------------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------------------------
// 
//--------------------------------------------------------------------------------------------
function start_anim_image(nom_image, tab_prix, tab_prix_promo,tab_reduc, width_max, height_max, tab_url_lien_image, tab_src_image, temps_en_ms){
// initialisation de l'animation pour l'image <nom_image>, <tab_url_lien_image> tableau des url, <tab_src_image> tableau des url image

/*
		// cette version fonctionne, mais l'image de fond doit etre à la bonne taille ! => creer vignette ?
		document.write('<div style=" background:url('+tab_src_image[0]+'); font-size:28px; font-weight:bolder; width:250px; height:300px; "><span style="background:#FFFFFF; color:#000000;">test</span></div>');
		
		// dernier version  avec prix sur l'image
		document.write('<a href="'+tab_url_lien_image[0]+'" id=\"a_'+nom_image+'\" ><span id="calk_prix_'+nom_image+'" style="padding:10px 0px 10px 0px;position:absolute; z-index:10; width:'+width_max+'px; background-color:#B5030D; color:#FFFFFF; text-align:left;font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:14px;">&nbsp;&nbsp;Prix : '+ tab_prix[0] +' euros</span><img src="'+tab_src_image[0]+'" alt=\"CultureShop\" title=\"CultureShop\" name=\"'+nom_image+'\" width=\"'+width_max+'\" style="position:relative; z-index:1; "></a>');
*/
	if (get_version() >= 3){
		
		var height_reduc = height_max - 50;
		var width_reduc = width_max - 70;
		//document.write('<center><table border="0" cellpadding="0" cellspacing="0"><tr><td width="'+width_max+'" height="'+height_max+'"><a href="'+tab_url_lien_image[0]+'" id="a_'+nom_image+'" ><img src="'+tab_src_image[0]+'" alt="CultureShop" title="CultureShop" name="'+nom_image+'" width="'+width_max+'" height="'+height_max+'"></a><td></tr><tr><td style="background-color:#B5030D; color:#FFFFFF; text-align:left;font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:14px;"><a style="padding:10px 0px 10px 0px ;color:#FFFFFF; display:block; text-decoration:none;" href="'+tab_url_lien_image[0]+'" id=\"a_'+nom_image+'\" ><span id="calk_prix_'+nom_image+'" style="width:'+width_max+'px;">Prix : '+ tab_prix[0] +' €</span><blink><span id="calk_reduc_'+nom_image+'" style="margin:0px 0px 0px 10px; width:52px;" class=""></span></blink></a><td></tr></table><center>');
		document.write('<center><table border="0" cellpadding="0" cellspacing="0"><tr><td width="'+width_max+'" height="'+height_max+'"><a href="'+tab_url_lien_image[0]+'" id="a_'+nom_image+'" ><img src="'+tab_src_image[0]+'" alt="CultureShop" title="CultureShop" name="'+nom_image+'" width="'+width_max+'" height="'+height_max+'"></a><td></tr><tr><td style="background: url(./images/fond_prix_accueil_'+width_max+'_50.gif) no-repeat bottom left; color:#FFFFFF; height:50px; text-align:left;font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:13px;"><a style="padding:0px 0px 0px 5px ;color:#FFFFFF; display:block; text-decoration:none;" href="'+tab_url_lien_image[0]+'" id=\"a_'+nom_image+'\" ><span id="calk_prix_'+nom_image+'" style="width:'+width_max+'px;">Prix : '+ tab_prix[0] +' €</span>&nbsp;<blink><span id="calk_reduc_'+nom_image+'"  class=""></span></blink></a><td></tr></table><center>');
		defil_image(nom_image, tab_prix,tab_prix_promo,tab_reduc, width_max, height_max, tab_url_lien_image, tab_src_image, 0, temps_en_ms);
	}
	else{
		document.write('<a href="'+tab_url_lien_image[0]+'"><img src="'+tab_src_image[0]+'" alt=\"CultureShop\" title=\"CultureShop\" name=\"'+nom_image+'\" width=\"\" heigth=\"\"></a>')
	}
}
//--------------------------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------------------------
// 
//--------------------------------------------------------------------------------------------
function modif_image(nom_image, prix, prix_promo, reduc, width_max, height_max, src_image, url_lien_image){
// change l'image <nom_image> en lui donnant la valeur de <src_image>
// change le lien de l'image <nom_image> en lui donnant la valeur de <url_lien_image>

	document.images[nom_image].src = src_image;
	document.getElementById('a_'+nom_image+'').href = url_lien_image;
	
//	alert(prix);
	if(prix_promo != 0) {
		
		var prix_html = '&nbsp;&nbsp;'+prix_promo+'€&nbsp;HT&nbsp;&nbsp;<span class="prix_promo">('+prix+'&nbsp;€&nbsp;HT)</span>';
		
		document.getElementById('calk_reduc_'+nom_image+'').className = 'reduction';
		document.getElementById('calk_reduc_'+nom_image+'').innerHTML = '-'+reduc+'%';
	}
	else {
		var prix_html = '&nbsp;&nbsp;'+prix+'';
		document.getElementById('calk_reduc_'+nom_image+'').className = '';
		document.getElementById('calk_reduc_'+nom_image+'').innerHTML = '';
	}
	document.getElementById('calk_prix_'+nom_image+'').innerHTML = prix_html;
	
	
//	var tab_taille = get_style_taille_image(nom_image, width_max, height_max);	
//	document.images[nom_image].style.width = tab_taille[0];
//	document.images[nom_image].style.height = tab_taille[1];
}
//--------------------------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------------------------
// 
//--------------------------------------------------------------------------------------------
function defil_image(nom_image, tab_prix,tab_prix_promo,tab_reduc, width_max, height_max, tab_url_lien_image, tab_src_image, cpt, temps_en_ms){
	// on peut observer qu'après le premier passage tab_src_image[0] est égale au premier caractrèe de tab_src_image, comme s'il s'agissait d'une chaine ...	
	// tab_src_image (array) se transforme en chaine apres premier passage ?

	// Pour pallier au problème : on recréé le tableau
		
	//		alert(tab_src_image+ ' ' +tab_src_image[0]); // pour débug 
	old_tab_src_image = tab_src_image.toString();
	var reg=new RegExp("[ ,]+", "g");
	var tab_src_image=old_tab_src_image.split(reg);
	//		alert(tab_src_image+ ' ' +tab_src_image[0]); // pour débug
	
	
	//		alert(tab_url_lien_image+ ' ' +tab_url_lien_image[0]); // pour débug
	old_tab_url_lien_image = tab_url_lien_image.toString();
	var reg=new RegExp("[ ,]+", "g");
	var tab_url_lien_image=old_tab_url_lien_image.split(reg);
	//		alert(tab_url_lien_image+ ' ' +tab_url_lien_image[0]); // pour débug
	
	//		alert(tab_prix+ ' ' +tab_prix[0]); // pour débug 
	old_tab_prix = tab_prix.toString();
	var reg=new RegExp("[ ,]+", "g");
	var tab_prix=old_tab_prix.split(reg);
	//		alert(tab_prix+ ' ' +tab_prix[0]); // pour débug
	
	//		alert(tab_prix_promo+ ' ' +tab_prix_promo[0]); // pour débug 
	old_tab_prix_promo = tab_prix_promo.toString();
	var reg=new RegExp("[ ,]+", "g");
	var tab_prix_promo=old_tab_prix_promo.split(reg);
	//		alert(tab_prix_promo+ ' ' +tab_prix_promo[0]); // pour débug
	
	//		alert(tab_reduc+ ' ' +tab_reduc[0]); // pour débug 
	old_tab_reduc = tab_reduc.toString();
	var reg=new RegExp("[ ,]+", "g");
	var tab_reduc=old_tab_reduc.split(reg);
	//		alert(tab_reduc+ ' ' +tab_reduc[0]); // pour débug
	
	if (cpt == tab_url_lien_image.length ){ // si on est en bout de tableau, on reviens au début
	
		cpt = 0;
	}
	if (get_version() >= 3){
		
		modif_image(nom_image, tab_prix[cpt], tab_prix_promo[cpt], tab_reduc[cpt], width_max, height_max, tab_src_image[cpt], tab_url_lien_image[cpt]); // on modifie l'image
		cpt++;
		
		setTimeout("defil_image('"+nom_image+"', '"+tab_prix+"','"+tab_prix_promo+"','"+tab_reduc+"', '"+width_max+"', '"+height_max+"', '"+tab_url_lien_image+"', '"+tab_src_image+"', '"+cpt+"', '"+temps_en_ms+"')", temps_en_ms); // on passe à la suivante dans temps_en_ms ms
		
	}
}
//--------------------------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------------------------
// 
//--------------------------------------------------------------------------------------------
function get_version(){
// renvoie la version du navigateur

	return navigator.appVersion.substring(0,1); 
}
//--------------------------------------------------------------------------------------------
//
//
//--------------------------------------------------------------------------------------------
// 
//--------------------------------------------------------------------------------------------
function get_style_taille_image(nom_image, width_max, height_max) {
// on determine si la taille de l'image est trop grande => on la fixe à plus petit (pour que ca dépce pas)

	var width = document.images[nom_image].width;
	var height = document.images[nom_image].height;
	
	var tab_taille = new Array;
	
	tab_taille[0] = '';
	tab_taille[1] = '';
	
	if(width >= height) {// si paysage
	
		if ( width > width_max ) {
		
			tab_taille[0] = width_max+'px';
		}
	}
	else { // si portrait
	
		if ( height > height_max ) {
		
			tab_taille[1] = height_max+'px';
		}
	}
	return tab_taille; 
}