var timeout ;
var idCreation ;
var idRow ;
var slideTable = new Array();
var slideshowLength = slideTable.length;
function displayDiaporama(pBoolean, pCreation, pId){
	if(pBoolean){
		idCreation = pCreation ;
		idRow = pId ;
		displayFreeze(true);
		$('diaporama').style.display = 'block' ;
		$('diaporama_command_left').style.display = 'block' ;
		$('diaporama_command_right').style.display = 'block' ;
		$('diaporama_command_close').style.display = 'block' ;
		loadImage ();
	}
	else {
		clearInterval(timeout);
		$('diaporama').innerHTML = '' ;
		$('diaporama').style.display = 'none' ;
		$('diaporama_command_left').style.display = 'none' ;
		$('diaporama_command_right').style.display = 'none' ;
		$('diaporama_command_close').style.display = 'none' ;
		displayComment(false);
	}
}

function loadImage(){
	var http = ajax_createRequestObject (); 
	vars = 'id_creation=' + idCreation + '&row=' + slideTable[idRow-1] ;
	http.open("GET", 'codes/gallery/ajax.gallery.php?' + vars);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			var json = eval('('+ http.responseText +')');
			$("diaporama").style.width = new Number(json.w) + 20 + 'px' ;
			$("diaporama").style.height = new Number(json.h) + 20 + 'px' ;
			$("diaporama").style.marginLeft = 0 - (new Number(json.w) + 20) / 2 + 'px';
			$("diaporama").style.marginTop = 0 - (new Number(json.h) + 20) / 2 + 'px';
			$("diaporama").innerHTML = '<p class="diaporama_mention_photo" style="position:absolute; bottom:10px; left:10px; padding:5px; background:#000; font-size:14px; color:#fff; font-weight:bold; text-align:left; width:' + (new Number(json.w) - 10) + 'px;">' + json.mention + '</p><img src="' + json.current + '" width="' + json.w + '" height="' + json.h + '" style="margin:10px;" />' ;
			$('diaporama_command_left').style.marginLeft = 0 - (new Number(json.w) + 70) / 2 + 'px' ;
			$('diaporama_command_right').style.marginLeft = 0 - (new Number(json.w)) / 2 + new Number(json.w) + 10 + 'px' ;
			$('diaporama_command_close').style.marginLeft = 0 - (new Number(json.w)) / 2 + new Number(json.w) - 52 + 'px' ;
			$('diaporama_command_close').style.marginTop = 0 - (new Number(json.h)) / 2 + 'px' ;
			$("freeze").onclick = function (){ displayDiaporama(false);}
		}
	}
	http.send(null);
}

function slide_show_prev(){
	var id = idRow - 1 ;
	if(id == 0) id = slideshowLength ;
	displayDiaporama(true, idCreation, id);
}

function slide_show_next(){
	var id = idRow + 1;
	if(id > slideshowLength) id = 1 ;
	displayDiaporama(true, idCreation, id);
}

function displayOtherComments(){
	var disp = $('creation_other_comments').style.display ;
	$('creation_other_comments').style.display = (disp=='block'?'none':'block') ;
	$('add_comment_action').innerHTML = (disp=='block'?'See':'Hide') ;
}

function displayVideo(pBoolean){
	displayFreeze(pBoolean);
	if(pBoolean){
		$("comment_form").style.display = 'block' ;
		$("comment_form").innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td><div><iframe id="video_frame" src="popup/video/video.php" frameborder="0"></iframe></div></tr></td></table>' ;
	}
}
