function affiche_planche_contact() {
	window.location = 'series-contact-' + YAHOO.lacompany.curphotographe + '-' + YAHOO.lacompany.curserie + '.html';
}

function affiche_mode_view() {
	window.location = 'series-' + YAHOO.lacompany.curphotographe + '.html?cur_serie='+YAHOO.lacompany.curserie;
}

function share(reseau, title) {

	var base = '';

	if (reseau=='google') {
		base = 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=';
	}
	if (reseau=='facebook') {
		base = 'http://www.facebook.com/sharer.php?u=';
	}
	if (reseau=='delicious') {
		base = 'http://del.icio.us/post?url=';
	}
	window.open(base + encodeURIComponent(window.location)+'&t='+encodeURIComponent(title),"Partager","menubar=no, status=no, scrollbars=no, menubar=no, width=630, height=430");
}

function download_me (type) {
	YAHOO.namespace("lacompany");
	var file = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][0].replace(/^.*[\/\\]/g, '');
	window.location = YAHOO.lacompany.url_root + '/resource/class/other/getImage.php?type='+ type +'&file=' + file ;
}

function change_serie_contact(id) {
	YAHOO.namespace("lacompany");
	document.getElementById('serie-disp-'+YAHOO.lacompany.curserie).style.display = 'none';
	document.getElementById('serie-disp-'+id).style.display = 'block';
	document.getElementById('name_serie_'+YAHOO.lacompany.curserie).style.color="#333";
	YAHOO.lacompany.curserie = id;
	document.getElementById('name_serie_' + id).style.color="#DB001B";
}

function change_serie(id) {
	YAHOO.namespace("lacompany");
	document.getElementById('name_serie_'+YAHOO.lacompany.curserie).style.color="#333";
	YAHOO.lacompany.curserie = id;
	YAHOO.lacompany.curimg = 0;
	document.getElementById('name_serie_' + id).style.color="#DB001B";
	update_img();
}



function update_img () {
	YAHOO.namespace("lacompany");
	document.getElementById('view-img').src = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][0];
	
	//amelioration des perfs en utilisant le cache du navigateur
	if (YAHOO.lacompany.curimg + 1 < YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie].length &&
		document.getElementById('view-img-next') != null) {
		document.getElementById('view-img-next').src = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg + 1][0];
	}
	
	//fix: image de taille variable
	var height = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][1];
	var src = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][0];
	var width = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][2];

	document.getElementById('view-img').innerHTML = '<img src="'+src+'" width="'+width+'" height="'+height+'" />';
	
	//Fix: le client ne souhaite plus avoir le titre de l'image
	//document.getElementById(YAHOO.lacompany.titleid).innerHTML = YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie][YAHOO.lacompany.curimg][1];
	

	//4 etats declenche l'activation ou non des boutons
	document.getElementById(YAHOO.lacompany.previd).style.visibility = 'hidden';
	document.getElementById(YAHOO.lacompany.nextid).style.visibility = 'hidden';
	
	if (YAHOO.lacompany.curimg > 0) {
		document.getElementById(YAHOO.lacompany.previd).style.visibility = 'visible';
	}
	
	if (YAHOO.lacompany.curimg < YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie].length - 1) {
		document.getElementById(YAHOO.lacompany.nextid).style.visibility = 'visible';
	}
}


function change_photo (newid) {
	YAHOO.namespace("lacompany");
 	if (newid >= 0 && newid < YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie].length) {
		YAHOO.lacompany.curimg = newid;
		update_img();
	}
}

//Controlleur portfolio	
//defini les listeners
function init_portfolio() {
	YAHOO.namespace("lacompany");
	YAHOO.lacompany.mutex = 1; //1 animation possible, 0 animation bloquee
	
	YAHOO.lacompany.overlay = new YAHOO.widget.Overlay("overlay-container", { visible:true, width:"685px" } );
	YAHOO.lacompany.overlay.render();

	var attributes = { scroll: { to: [0, 0] } };
  	YAHOO.lacompany.anim = new YAHOO.util.Scroll('overlay-container', attributes, 1, YAHOO.util.Easing.easeOut);

	//desactive les controleurs lors de l'animation
	YAHOO.lacompany.anim.onStart.subscribe(function () {
		YAHOO.lacompany.mutex = 0;
	});
	YAHOO.lacompany.anim.onComplete.subscribe(function () {
		YAHOO.lacompany.mutex = 1;
	});

	//decalle de la taille d'un bloc
  	YAHOO.util.Event.on('controler-right', 'click', slide_right);
	YAHOO.util.Event.on('controler-left', 'click', slide_left);
	
	//initialise le premier bloc
	YAHOO.lacompany.lastthumb = calc_nbimg_cur_bloc();
	YAHOO.lacompany.firstthumb = 0;
	change_photo_portfolio(0);
}

function calc_nbimg_cur_bloc () {
	var current_bloc = parseInt(YAHOO.lacompany.anim.attributes.scroll.to[0] / 685);
	
	var current_span = document.getElementById('overlay-container').getElementsByTagName('span')[current_bloc];
	
	return current_span.getElementsByTagName('img').length;
}

//algo de decallage a droite
function slide_right () {
	
	if (YAHOO.lacompany.mutex == 1) {
		if (YAHOO.lacompany.lastthumb < YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie].length ) {
	
			//incremente de l'ancien nombre
			YAHOO.lacompany.firstthumb += calc_nbimg_cur_bloc(); 
	
			YAHOO.lacompany.anim.attributes.scroll.to[0] += 685;
			YAHOO.lacompany.anim.animate();
		
			//incremente du nouveau nombre
			YAHOO.lacompany.lastthumb = YAHOO.lacompany.firstthumb + calc_nbimg_cur_bloc();
			
			change_photo_portfolio(YAHOO.lacompany.firstthumb);
		}
	}
} 

//algo de decallage a gauche
function slide_left () {
	if (YAHOO.lacompany.mutex == 1) {
		if (YAHOO.lacompany.anim.attributes.scroll.to[0] >= 685) { 
			
			YAHOO.lacompany.lastthumb = YAHOO.lacompany.firstthumb;
			
			YAHOO.lacompany.anim.attributes.scroll.to[0] -= 685;
			YAHOO.lacompany.anim.animate();
			
			YAHOO.lacompany.firstthumb -= calc_nbimg_cur_bloc();
				
			change_photo_portfolio(YAHOO.lacompany.firstthumb);
		}
	}
}

//algo de mise a jour de la photo view
function change_photo_portfolio (newid) {
	YAHOO.namespace("lacompany");
 	if (newid >= 0 && newid < YAHOO.lacompany.jall['id-0'].length) {
		
		YAHOO.lacompany.curimg = newid;
		update_img();

		//actione le slide si necessaire
		if (newid >= YAHOO.lacompany.lastthumb) {
			slide_right();
		}
		
		if (newid < YAHOO.lacompany.firstthumb) {
			slide_left();
		}
		
		//cache ou affiche les boutons des thumbnails
		document.getElementById('prev-thumbs').style.visibility = 'hidden';
		document.getElementById('next-thumbs').style.visibility = 'hidden';
	
		if (YAHOO.lacompany.firstthumb > 0) {
			document.getElementById('prev-thumbs').style.visibility = 'visible';
		}
	
		if (YAHOO.lacompany.lastthumb < YAHOO.lacompany.jall['id-' + YAHOO.lacompany.curserie].length - 1) {
			document.getElementById('next-thumbs').style.visibility = 'visible';
		}
		// \cache ou affiche les boutons des thumbnails
	}
}
