// JavaScript Document


function setMainPicture(pic_id,h,w) {
		
	var t_img = 'p_img_'+pic_id;
	var t_img_title = 'p_img_title_'+pic_id;
	var t_img_desc = 'p_img_desc_'+pic_id;

	/*
	var img_title = document.getElementById(t_img_title); 
	var img_desc = document.getElementById(t_img_desc); 
	var img_icon = document.getElementById(t_img);
	var img_id = document.getElementById(t_img_id);
	*/

	if(pic_id) {
		var main_pic = document.getElementById("p_main_picture");
		main_pic.src= "/ressources/e.gif";
		main_pic.style.height= h;
		main_pic.style.width= w;
		main_pic.src= '/images/show_image.php?id='+pic_id+'&format=mediumlarge';
		main_pic.style.height= h;
		main_pic.style.width= w;
		
		//Description
		var spdesc = document.getElementById('portfolio_description');	
		var spd2 = document.getElementById('sp_desc_'+pic_id);
		spdesc.innerHTML = spd2.innerHTML;		

	}

}

function portfolioGetNext() {
	
	var curpic = parseInt(document.getElementById('current_picture').value);
	var picnum = parseInt(document.getElementById('picture_number').value);

	var newcurpic = curpic+1;
	var t_curpic = newcurpic;
	//Update vignettes
	//1
	if(picnum >= newcurpic+7) {
		
		for(pic=0;pic<6;pic++) {
			if(document.getElementById('sp_img_'+t_curpic)) {
				var sp1 = document.getElementById('sp_'+pic);	
				var sp2 = document.getElementById('sp_img_'+t_curpic);
				sp1.innerHTML = sp2.innerHTML;
			}
		t_curpic = t_curpic+1;	
		}
	} else {
	//Un-highlight button
		var n_button = document.getElementById('p_next');
		n_button.src = '/ressources/portfolio_next_off.gif';
	}
	
	var cpic = document.getElementById('current_picture');
	cpic.value = newcurpic;

	var p_button = document.getElementById('p_prev');
	p_button.src = '/ressources/portfolio_prev_on.gif';

}

function portfolioGetPrevious() {
	
	var curpic = parseInt(document.getElementById('current_picture').value);
	var picnum = parseInt(document.getElementById('picture_number').value);

	var newcurpic = curpic-1;
	var t_curpic = newcurpic;
	//Update vignettes
	//1
	if(t_curpic > 0) {		
		for(pic=0;pic<6;pic=pic+1) {
			if(document.getElementById('sp_img_'+t_curpic)) {
				var sp1 = document.getElementById('sp_'+pic);	
				var sp2 = document.getElementById('sp_img_'+t_curpic);
				sp1.innerHTML = sp2.innerHTML;	
			}
		t_curpic = t_curpic+1;	
		}
	} else {
	//Un-highlight button
		var n_button = document.getElementById('p_prev');
		n_button.src = '/ressources/portfolio_prev_off.gif';
	}
	
	var cpic = document.getElementById('current_picture');
	cpic.value = newcurpic;

	var p_button = document.getElementById('p_next');
	p_button.src = '/ressources/portfolio_next_on.gif';

}	

function portfolioShowFullSize() {
	
		var main_pic = document.getElementById("p_main_picture");
		var psrc = main_pic.src;
		var pid = psrc.slice(psrc.indexOf("id=")+3,psrc.indexOf("&format="));

		var d_full = document.getElementById("div_full_size_pict");
		var p_full = document.getElementById("img_full_size");
		p_full.src = "/images/show_image.php?id="+pid+"&format=image";
		var td_full = document.getElementById("td_full_size");
		//td_full.style.background = "url(/images/show_image.php?id="+pid+"&format=image)";
		//td_full.style.backgroundRepeat = "no-repeat";
		//td_full.style.backgroundPosition = "center";
		d_full.className = "on";
}


//Accents
function replaceCaracters(c) {

	while(c.indexOf("#comma#") != -1) c = c.replace("#comma#",",");
	while(c.indexOf("#apos#") != -1) c = c.replace("#apos#","'");

return c;
}

