// JavaScript Document
function initGalleryAgenda ( tempgallery, count, first_id, startwidth, startheight ) {
	imggallery_agenda = tempgallery;
	if (preloadimg_agenda=="yes"){
		for (x=0; x<imggallery_agenda.length; x++){
			var myimage=new Image()
			myimage.src=imggallery_agenda[x][0]
		}
	}
	
	current_imgid_agenda = first_id;
	currentwidth_agenda=startwidth;
	currentheight_agenda=startheight;
	
	window.addEvent('load', function() {
		var setloadersize = new Fx.Styles('main_image_wrapper_agenda',{duration:transspeed_agenda,onComplete: function(){loadfirstimageAgenda(currentwidth_agenda,currentheight_agenda)}});
		
		setloadersize.start({
			'width':imggallery_agenda[0][1],
			'height':imggallery_agenda[0][2]	
		});
	});
	
	
}

window.addEvent('domready', function() {
	if (tempgallery_agenda.length > 0) initGalleryAgenda( tempgallery_agenda, tempgallery_agenda.length, tempgallery_agenda[0][8], tempgallery_agenda[0][1], tempgallery_agenda[0][2], 0 );
});

function getstartedAgenda(width, height, loadarea, imgindex, img_id, current_imgid){
	if(current_imgid!=img_id){
		if(firstimagestart_agenda==1){
			currentwidth_agenda=firstimagewidth_agenda;
			currentheight_agenda=firstimageheight_agenda;
			firstimagestart_agenda=0;		
		}
		if(nextorprev_agenda==1){
			currentwidth_agenda=cwidth_agenda;
			currentheight_agenda=cheight_agenda;
			nextorprev_agenda=0;		
		}
		
		var resizeDivHeight = new Fx.Styles('main_image_wrapper_agenda',{duration:transspeed_agenda, onComplete: function(){modifyimage_agenda(loadarea, imgindex, img_id);currentheight_agenda=height;currentwidth_agenda=width;} });
		var fader = new Fx.Style('imgloader_agenda','opacity', {duration:fadespeed_agenda, onComplete: function(){	resizeDivHeight.start({'height': [currentheight_agenda,height],'width': [currentwidth_agenda,width]});} });
		fader.start(1,0);
		var forg_diafade = new Fx.Style('forg_dia','opacity', {duration:transspeed });
		forg_diafade.set(0);	
		var forg_monfade = new Fx.Style('forg_mon','opacity', {duration:transspeed });
		forg_monfade.set(0);
		var forg_yeafade = new Fx.Style('forg_yea','opacity', {duration:transspeed });
		forg_yeafade.set(0);
	}
}
function loadfirstimageAgenda(currentwidth_agenda,currentheight_agenda){
	var fadefirst = new Fx.Style('imgloader_agenda','opacity', {duration:fadespeed_agenda });
	fadefirst.set(0);
	var forg_diafade = new Fx.Style('forg_dia','opacity', {duration:transspeed });
	forg_diafade.set(0);
	var forg_monfade = new Fx.Style('forg_mon','opacity', {duration:transspeed });
	forg_monfade.set(0);
	var forg_yeafade = new Fx.Style('forg_yea','opacity', {duration:transspeed });
	forg_yeafade.set(0);
	function setfirstimage(){
		var newHTML = "<a href='"+tempgallery_agenda[0][7]+"' target='_self'><img src='"+tempgallery_agenda[0][0]+"' border='0' /></a>";
		$('imgloader_agenda').setHTML(newHTML);
	
		var forg_dia=document.getElementById('forg_dia');
		forg_dia.innerHTML=tempgallery_agenda[0][4];
		var forg_mon=document.getElementById('forg_mon');
		forg_mon.innerHTML=tempgallery_agenda[0][5];
		var forg_yea=document.getElementById('forg_yea');
		forg_yea.innerHTML=tempgallery_agenda[0][6];
		fadefirst.start(0,1);
		forg_diafade.start(0,1);
		forg_monfade.start(0,1);
		forg_yeafade.start(0,1);
		currentheight_agenda=imggallery_agenda[0][2];
		currentwidth_agenda=imggallery_agenda[0][1];
	}
	new Asset.image(imggallery_agenda[0][0], {onload: setfirstimage});
}
function nextimageAgenda(current_imgid){
    var next = Number(current_imgid)+1;
    if (next >= tempgallery_agenda.length) next = 0; 
	newimgid_agenda = next;
	newwidth_agenda =imggallery_agenda[newimgid_agenda][1]
	newheight_agenda =imggallery_agenda[newimgid_agenda][2]
	newimgindex_agenda =imggallery_agenda[newimgid_agenda][8]
	newimgid_agenda = imggallery_agenda[newimgid_agenda][8]
	cwidth_agenda=imggallery_agenda[current_imgid][1]
	cheight_agenda=imggallery_agenda[current_imgid][2]
	nextorprev_agenda=1;
	getstartedAgenda(Number(newwidth_agenda), Number(newheight_agenda), 'imgloader_agenda',Number(newimgindex_agenda) ,Number(newimgid_agenda) , Number(current_imgid), Number(cwidth_agenda), Number(cheight_agenda))
	
}

function previmageAgenda(current_imgid){
	var prev = Number(current_imgid)-1;
    if (prev < 0) prev = tempgallery_agenda.length-1; 
	newimgid_agenda = prev;
	newwidth_agenda =imggallery_agenda[newimgid_agenda][1]
	newheight_agenda =imggallery_agenda[newimgid_agenda][2]
	newimgindex_agenda =imggallery_agenda[newimgid_agenda][8]
	newimgid_agenda = imggallery_agenda[newimgid_agenda][8]
	cwidth_agenda=imggallery_agenda[current_imgid][1]
	cheight_agenda=imggallery_agenda[current_imgid][2]
	nextorprev_agenda=1;
	getstartedAgenda(Number(newwidth_agenda), Number(newheight_agenda), 'imgloader_agenda',Number(newimgindex_agenda) ,Number(newimgid_agenda) , Number(current_imgid), Number(cwidth_agenda), Number(cheight_agenda))
}

