// JavaScript Document

function initGallery ( tempgallery, count, first_id, startwidth, startheight ) {
	imggallery = tempgallery;
	if (preloadimg=="yes"){
		for (x=0; x<imggallery.length; x++){
			var myimage=new Image()
			myimage.src=imggallery[x][0]
		}
	}
	thumbnailnum = imggallery.length;
	current_imgid = first_id;
	currentwidth=startwidth;
	currentheight=startheight;
	window.addEvent('load', function() {
		var setloadersize = new Fx.Styles('main_image_wrapper',{duration:transspeed,onComplete: function(){loadfirstimage(currentwidth,currentheight)}});
		setloadersize.start({
			// MODIF OREN : TAILLE MAX TD
			'width':900, // 'width':imggallery[0][1],
			'height':400 // 'height':imggallery[0][2]	
		});
	});
	
	
}
window.addEvent('domready', function() {
	initGallery( tempgallery, tempgallery.length, tempgallery[photo_nb][8], tempgallery[photo_nb][1], tempgallery[photo_nb][2], 0 );
});

function getstarted(width, height, loadarea, imgindex, img_id, current_imgid){
	checknext(img_id);
	if(current_imgid!=img_id){
		if(firstimagestart==1){
			currentwidth=firstimagewidth;
			currentheight=firstimageheight;
			firstimagestart=0;		
		}
		if(nextorprev==1){
			currentwidth=cwidth;
			currentheight=cheight;
			nextorprev=0;		
		}



			
		// Oren
		// var fadeiptc = new Fx.Style('iptc_btn','opacity', {duration:transspeed });
		// fadeiptc.set(0);
		// Oren : A ajouter en cas de titres
		// var titlefade = new Fx.Style('imgtitle','opacity', {duration:transspeed });
		// titlefade.set(0);
		currentheight=height;currentwidth=width;
		var info=document.getElementById('iptc_info');
		// info.style.width=currentwidth;
		// info.style.left=(firstimagewidth-currentwidth)/2;
		modifyimage(loadarea, imgindex, img_id);
	}
}
function loadfirstimage(currentwidth,currentheight){
	// var fadefirst = new Fx.Style('imgloader', {property: 'opacity', duration: 'short'});
	// fadefirst.set(0);
	// Oren :A ajouter en cas de title 
	// var firsttitlefade = new Fx.Style('imgtitle','opacity', {duration:transspeed });
	// firsttitlefade.set(0);
	function setfirstimage(){
		var imgobj=document.getElementById('imgloader');
		imgobj.innerHTML = "<img src='"+tempgallery[photo_nb][0]+"' />";
		imgobj.style.verticalAlign="midlle";
	
		// Oren : A ajouter en cas de title	
		// var firsttitle=document.getElementById('imgtitle');
		// firsttitle.innerHTML="<strong>"+tempgallery[photo_nb][4]+"</strong> "+tempgallery[photo_nb][7];
		// fadefirst.start(0,1);
		//firsttitlefade.start(0,1);
		currentheight=imggallery[photo_nb][2];
		currentwidth=imggallery[photo_nb][1];
		var iptch=document.getElementById('iptc_info');
		iptch.innerHTML="";
		iptch.innerHTML=returniptc(tempgallery[photo_nb]);
	}
	new Asset.image(imggallery[photo_nb][0], {onload: setfirstimage});
}
function nextimage(current_imgid){
	
	newimgid = Number(current_imgid)+1;
	newwidth =imggallery[newimgid][1]
	newheight =imggallery[newimgid][2]
	newimgindex =imggallery[newimgid][8]
	newimgid = imggallery[newimgid][8]
	cwidth=imggallery[current_imgid][1]
	cheight=imggallery[current_imgid][2]
	checknext(newimgid);
	nextorprev=1;
	getstarted(Number(newwidth), Number(newheight), 'imgloader',Number(newimgindex) ,Number(newimgid) , Number(current_imgid), Number(cwidth), Number(cheight))
}

function previmage(current_imgid){
	newimgid = Number(current_imgid)-1;
	newwidth =imggallery[newimgid][1]
	newheight =imggallery[newimgid][2]
	newimgindex =imggallery[newimgid][8]
	newimgid = imggallery[newimgid][8]
	cwidth=imggallery[current_imgid][1]
	cheight=imggallery[current_imgid][2]
	checknext(newimgid);
	nextorprev=1;
	getstarted(Number(newwidth), Number(newheight), 'imgloader',Number(newimgindex) ,Number(newimgid) , Number(current_imgid), Number(cwidth), Number(cheight))
}

