function get_powerpoint_file(url,nb_slide,uid_presentation) {
	var param='?uid_presentation='+uid_presentation+'&nb_slide='+nb_slide+'&slide_list=';
	var param2 = '&tx_stdoccenter_pi1[slide_list]=';

	var count=0;
	for(i=1;i<=nb_slide;i++) {
		if (document.getElementById("tx_stdoccenter_pi1[slide_"+i+"]").value==1) {
			if (count==0) {
				param = param + i;
				param2 = param2 + i;
				
			}
			else {
				param = param + ',' + i;
				param2 = param2 + ',' + i;
			}
			count++;
		}
	}
	
	//new Ajax('./typo3conf/ext/st_doccenter/pi1/create_powerpoint_file.php'+param,{method: 'GET'}).request();
	 //$url='http://dev1.sys-tech.net/iccmr_dev/index.php?id=4&no_cache=1&tx_stdoccenter_pi1[mod_type]=1&tx_stdoccenter_pi1[uid]='+uid_presentation+param2;
	 url=url+'&no_cache=1&tx_stdoccenter_pi1[mod_type]=1&tx_stdoccenter_pi1[nb_slide]='+nb_slide+'&tx_stdoccenter_pi1[uid]='+uid_presentation+param2;
	 //url='index.php?id=11&no_cache=1&tx_stdoccenter_pi1[mod_type]=1&tx_stdoccenter_pi1[nb_slide]='+nb_slide+'&tx_stdoccenter_pi1[uid]='+uid_presentation+param2;
	 
	 //alert(url);
	 window.location='/'+url;
}

function create_powerpoint_file(nb_slide,uid_presentation,nb_slide,slide_list,file_name_destination,file_name,file_name_complete) {
	wait_file()
	slide_list_array = slide_list.split(",");
	//var param='?uid_presentation='+uid_presentation+'&nb_slide='+nb_slide+'&file_name_destination='+file_name_destination+'&file_name='+file_name+'&slide_list='+slide_list;
	var param2='uid_presentation='+uid_presentation+'&nb_slide='+nb_slide+'&file_name_destination='+file_name_destination+'&file_name='+file_name+'&slide_list='+slide_list;

	document.getElementById("button_download").src = 'fileadmin/templates/images/en/btnConfirm_of.gif';

	if (nb_slide!=slide_list_array.length) {
		timerID = setInterval("wait_file()",500);
		//param_ajax = './typo3conf/ext/st_doccenter/classes/create_powerpoint_file.php'+param;
		url = document.getElementById("button_download_href").href;
		document.getElementById("button_download_href").href = 'javascript:void(0)';
		//new Ajax(param_ajax,{method: 'GET', onComplete: complet_file_powerpoint.bind()}).request();
		$.ajax({
			type: "GET",
			url: './typo3conf/ext/st_doccenter/classes/create_powerpoint_file.php',
			data: param2,
			success: complet_file_powerpoint()
		});
	}
	else {
		document.getElementById("button_download_href").href = file_name_complete;
		document.getElementById("button_download").src = 'fileadmin/templates/images/en/btnConfirm_of.gif';
	}
}

function wait_file() {
	no_image++;
	//alert('no_image='+no_image);
	if (no_image>5) {
		no_image=1;
	}
	document.getElementById("button_download").src = 'fileadmin/templates/images/en/wait'+no_image+'_of.gif';
	
}

function complet_file_powerpoint(request) {
	//alert('The file is completed and ready to download');
	if(timerID) {
		clearInterval(timerID);
		timerID  = 0;
	}
	document.getElementById("button_download_href").href = url;
	document.getElementById("button_download").src = 'fileadmin/templates/images/en/btnConfirm_of.gif';
	
}

function getVar (nomVariable)
{
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&";
	if (infos.indexOf("#")!=-1) infos = infos.substring(0,infos.indexOf("#"))+"&";
	var variable=0
	{
		nomVariable = nomVariable + "=";
		var taille = nomVariable.length;
		if (infos.indexOf(nomVariable)!=-1)
			variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"));
	}
	return variable;
} 


function initialize(sellId, nb_max_display_temp, fullImages_temp,reductImages_temp,notes_temp,titles_temp,count_slide,web_path_image_general_temp) {

	slide_library_fullImages=fullImages_temp;
	slide_library_reductImages=reductImages_temp;
	slide_library_notes=notes_temp;
	slide_library_titles=titles_temp;
	slide_library_web_path_image_general=web_path_image_general_temp;

	slide_library_sellId = sellId;
	//this.object = ref_objet;
	//this.ssHandle = $("ss"+sellId);

	slide_library_max_display = nb_max_display_temp;
	slide_library_max_display = 4;

	slide_library_compteur = 0;
	slide_library_img = 0;

	slide_library_index_j = 0;
	slide_library_reset = 0;
	slide_library_index2 = new Array();


	////////////////////////////////////////////////////////////
	slide_library_comment = new Array();
	slide_library_uid = new Array();

	//Initialiser
	slide_library_img=count_slide;


	////////////////////////////////////////////////////////////
	slide_library_select_slide(-1);
	slide_library_ssStart(0);

}


function slide_library_ssStart (reset) {
	var html = "";

	var index = slide_library_index2;
	if (reset!=1) {
		index = new Array();

		if(slide_library_img<=slide_library_max_display) {
			   var max_i = slide_library_img;
		}else{
			   var max_i = slide_library_compteur+slide_library_max_display;
			   if(max_i>slide_library_img){max_i=slide_library_img;}
		}


		var j = 0;
		for(var i=slide_library_compteur;i<max_i;i++) {
			   index[j] = i;
			   j++;
		}

		if(slide_library_img>slide_library_max_display) {
			   var j = 0;
			   while(index.length<4){
				       index[index.length]=j;
				       j++;
			   }
		}
	}
	slide_library_index2 = index;

	//alert('reset='+reset+' slide_library_index_j='+slide_library_index_j+' index='+index[0+slide_library_index_j]);
	document.getElementById('javascript_slide_title').innerHTML = slide_library_titles[index[0+slide_library_index_j]];
	document.getElementById('javascript_slide_notes').innerHTML = slide_library_notes[index[0+slide_library_index_j]];
	document.getElementById('javascript_slide_number').innerHTML = 'SLIDE '+(index[0+slide_library_index_j]+1);


	//document.getElementById("javascript_slide_title[slide_1]").innerHTML=1;

	navigation = '<div class="slideNavigation" >Slide <strong style="color: black;">'+(index[0+slide_library_index_j]+1)+'</strong> of <strong style="color: black;">'+slide_library_img+'</strong></div>'

	if(slide_library_img>0) {
		//html_big_image = '<a href="javascript:void(0)"><img src="'+slide_library_fullImages[index[0+slide_library_index_j]]+'" alt="photo" /></a>';
		html_big_image = '<img src="'+slide_library_fullImages[index[0+slide_library_index_j]]+'" alt="photo" />';
		
		   for(var j=0;j<index.length;j++) {
				//if (j==0) {
				if (j==slide_library_index_j) {

					$img_selected = 'class="selected"';
				}
				else {
					$img_selected = '';
				}
				var i = index[j];
				var checkbox = slide_library_default_check_box(i);
				html = html + '<div class="selectable"><a href="javascript:;"><img src="'+slide_library_reductImages[i]+'" id="p'+slide_library_sellId+'" alt="Thumb" '+$img_selected+'  onclick="slide_library_select_image('+i+','+j+');" /><br /><input name="slide_'+(i+1)+'" value="1" id="select1" '+checkbox+' onclick="slide_library_select_slide(this);" type="checkbox" value="" /></div>';

				//html = html + '<div class="selectable"><a href="javascript:;"><img src="'+slide_library_reductImages[i]+'" id="p'+slide_library_sellId+'" width="81" height="68" alt="Thumb" '+$img_selected+'  onclick="'+slide_library_object+'.slide_library_select_image('+i+','+j+');" /><br /><input name="slide_'+(i+1)+'" value="1" id="select1" '+checkbox+' onclick="'+slide_library_object+'.slide_library_select_slide(this);" type="checkbox" value="" /></div>';
		   }
	}else{
		   html = '<div class="contener_photo"><img src="../images/noimagefiche.jpg" width="175" height="125" /></div>';
	}
	image_left='';
	if(slide_library_img>slide_library_max_display) {
		   image_left='<div><a href="javascript:;" onclick="slide_library_prev();"><img  src="'+slide_library_web_path_image_general+'btn_previous_of.gif"  alt="Previous" width="13" height="14" onmouseover="rollOver(this);" onmouseout="rollOver(this);" /></a></div> ';
	}
	image_right='';
	if(slide_library_img>slide_library_max_display) {
		   image_right='<div><a href="javascript:;" onclick="slide_library_next();"><img src="'+slide_library_web_path_image_general+'btn_next_of.gif"  alt="Next" width="13" height="14" onmouseover="rollOver(this);" onmouseout="rollOver(this);" /></a></div>';
	}
	html = html_big_image + navigation + '<div class="slideScrollerOutside"><div class="slideScroller">'+image_left+html+image_right+'</div></div><div class="clear"></div>';


	//slide_library_ssHandle.setHTML(html);
	document.getElementById(slide_library_sellId).innerHTML = html;
}

function slide_library_select_image(i,j) {
	slide_library_compteur = i-j;

	//alert('j='+j);
	slide_library_index_j = j;
	slide_library_ssStart(1);
}

function slide_library_default_check_box(number) {

	number++;

	if (document.getElementById("tx_stdoccenter_pi1[slide_"+number+"]").value==1) {
		//alert('x');
		return 'checked="checked"';
	}
	return '';
}

function slide_library_select_slide(uid_slide) {

	if (uid_slide != -1) {
		name = uid_slide.name;
		name=name.substring(6,name.length);
		if (uid_slide.checked == true) {
			document.getElementById("tx_stdoccenter_pi1[slide_"+name+"]").value=1;
		}
		else {
			document.getElementById("tx_stdoccenter_pi1[slide_"+name+"]").value=0;
		}
	}
	
	var nb_check = 0;
	for(var i=1;i<=slide_library_img;i++) {
		if (document.getElementById("tx_stdoccenter_pi1[slide_"+i+"]").value==1) {
			nb_check++;
		}
	}
	
	
	if (nb_check==0) {
		html = '<img src="fileadmin/templates/images/en/btnDownloadSelectedSlides_of_inactive.gif" alt="Download selected slide(s)" width="302" height="29" border="0" onmouseover="rollOver(this);" onmouseout="rollOver(this);" />';
		if(typeof isIpad == "undefined"){}else if( isIpad == 1){
		  html = '<span class="btn-consult-ipad">View Selected Slides</span>';
		}
		document.getElementById('selectedslide').innerHTML = html;
	}
	else {
		html = '<a onclick="get_powerpoint_file(\''+slide_library_url+'\','+slide_library_presentation_slide_count+','+slide_library_uid_presentation+');"><img src="fileadmin/templates/images/en/btnDownloadSelectedSlides_of.gif" alt="Download selected slide(s)" width="302" height="29" border="0" onmouseover="rollOver(this);" onmouseout="rollOver(this);" /></a>';
		if(typeof isIpad == "undefined"){}else if( isIpad == 1){
		  html = '<a class="btn-consult-ipad" onclick="get_powerpoint_file(\''+slide_library_url+'\','+slide_library_presentation_slide_count+','+slide_library_uid_presentation+');">View Selected Slides</a>';
		}
		document.getElementById('selectedslide').innerHTML = html;
	}
}

function slide_library_prev() {
	if(slide_library_compteur>0) {
		   slide_library_compteur--;
		   slide_library_ssStart(0);
	}else{
		   slide_library_compteur=slide_library_img-1;
		   slide_library_ssStart(0);
	}
}


function slide_library_next() {
	if(slide_library_compteur<slide_library_img-1) {
		   slide_library_compteur++;
		   slide_library_ssStart(0);
	}else{
		   slide_library_compteur=0;
		   slide_library_ssStart(0);
	}
}





