/**
 * @author spierson
 */

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 2;


var tss;
var jss = 0;
var iss = 0;

var preLoad = new Array();
var arrCaptions = new Array();
var arrWidth = new Array();
var arrHeight = new Array();
var arrImgs = new Array();

function addPicture(pictureURL)
{
	arrImgs[iss] = pictureURL;
	iss = iss + 1;
}

function runSlideShow(firstLoad)
{
	if(1 < iss){
		if(!firstLoad)
		{
		   $("a.lightBox:visible").hide();
		
		   if ((iss - 1) > jss) {
		   	jss++;
		   }
		   else {
		   	jss = 0;
		   }
		   
		   $('a.lightBox[href="'+arrImgs[jss]+'"]').show();
		   $('a.lightBox[href="'+arrImgs[jss]+'"]').css('display', 'block');
		}
	   window.setTimeout("runSlideShow(false)",SlideShowSpeed);
   }
}

function zoomImg(idImg, prefix, legend)
{
	if (0 < $("#"+idImg).size())
	{
		var img_to_zoom_src = $("#" +idImg).attr("src");
		var iLastSlash = img_to_zoom_src.lastIndexOf('/');
		var host = img_to_zoom_src.substring(0, iLastSlash + 1);
		var img_name = img_to_zoom_src.substr(iLastSlash + 1);
		var myReg = new RegExp("^_[a-zA-Z0-9]{3}_");
		var new_img_name = img_name.replace(myReg, prefix);
		var complet_new_src = host + new_img_name;
		
		if (0 < $("#picture").size())
		{
			$("#picture").attr("src",complet_new_src);
		}
		$("#legendeImage").html(legend);
	}
	setTimeout("redimensionne()", 10);
}

function popUpImg()
{
	if ($('#picture').size()>0)
	{
		var tabSRC = $('#picture').attr("src").split("_");
		var img_to_zoom_src = $('#picture').attr("src").replace("diapo", "600");
		
		var iLastSlash = img_to_zoom_src.lastIndexOf('/');
		var host = img_to_zoom_src.substring(0, iLastSlash + 1);
		var img_name = img_to_zoom_src.substr(iLastSlash + 1);
		var myReg = new RegExp("^_[a-zA-Z0-9]{3}_");
		var new_img_name = img_name.replace(myReg, '');
		var complet_new_src = host + new_img_name;
		complet_new_src = escape(complet_new_src);
		
		popupcentree("../view_image.php?image=" + complet_new_src, 800, 600);
	}
}

function popupcentree(page,largeur,hauteur)
{
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;
    var hdwnd;
					
	try
	{
        hdwnd = window.open(page,"","toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no,top="+top+",left="+left+",width="+largeur+",height="+hauteur);        
    }
    catch(erreur)
    {
        alert("erreur");
    }
    return hdwnd;
}
