// JavaScript Document
function initGalleryAnteriores ( tempgallery, count, first_id, startwidth, startheight ) {
	imggallery_anteriores = tempgallery;
	if (preloadimg_anteriores=="yes"){
		for (x=0; x<imggallery_anteriores.length; x++){
			var myimage=new Image()
			myimage.src=imggallery_anteriores[x][0]
		}
	}
	
	current_imgid_anteriores = first_id;
	currentwidth_anteriores = startwidth;
	currentheight_anteriores = startheight;
	
	window.addEvent('load', function() {
		var setloadersize = new Fx.Styles('main_image_wrapper_anteriores',{duration:transspeed_anteriores,onComplete: function(){loadfirstimageAnteriores(currentwidth_anteriores,currentheight_anteriores)}});
		
		setloadersize.start({
			'width':imggallery_anteriores[0][1],
			'height':imggallery_anteriores[0][2]	
		});
	});
	
}

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

function getstartedAnteriores(width, height, loadarea, imgindex, img_id, current_imgid){
	if(current_imgid!=img_id){
		if(firstimagestart_anteriores==1){
			currentwidth_anteriores=firstimagewidth_anteriores;
			currentheight_anteriores=firstimageheight_anteriores;
			firstimagestart_anteriores=0;		
		}
		if(nextorprev_anteriores==1){
			currentwidth_anteriores=cwidth_anteriores;
			currentheight_anteriores=cheight_anteriores;
			nextorprev_anteriores=0;		
		}
		
		var resizeDivHeight = new Fx.Styles('main_image_wrapper_anteriores',{duration:transspeed_anteriores, onComplete: function(){modifyimage_anteriores(loadarea, imgindex, img_id);currentheight_anteriores=height;currentwidth_anteriores=width;} });
		var fader = new Fx.Style('imgloader_anteriores','opacity', {duration:fadespeed_anteriores, onComplete: function(){	resizeDivHeight.start({'height': [currentheight_anteriores,height],'width': [currentwidth_anteriores,width]});} });
		fader.start(1,0);
		var titlefade = new Fx.Style('desc_anteriores','opacity', {duration:transspeed });
		titlefade.set(0);	
	}
}
function loadfirstimageAnteriores(currentwidth_anteriores,currentheight_anteriores){
	var fadefirst = new Fx.Style('imgloader_anteriores','opacity', {duration:fadespeed_anteriores });
	fadefirst.set(0);
	var firsttitlefade = new Fx.Style('desc_anteriores','opacity', {duration:transspeed });
	firsttitlefade.set(0);
	function setfirstimage(){
		var newHTML = "<a href='"+tempgallery_anteriores[0][7]+"' target='_self'><img src='"+tempgallery_anteriores[0][0]+"' border='0' /></a>";
		$('imgloader_anteriores').setHTML(newHTML);
	
		var firsttitle=document.getElementById('desc_anteriores');
		firsttitle.innerHTML="<strong  style='text-transform:uppercase'>"+ tempgallery_anteriores[0][5] +"</strong> <br />"+ tempgallery_anteriores[0][6];
		fadefirst.start(0,1);
		firsttitlefade.start(0,1);
		currentheight_anteriores=imggallery_anteriores[0][2];
		currentwidth_anteriores=imggallery_anteriores[0][1];
	}
	new Asset.image(imggallery_anteriores[0][0], {onload: setfirstimage});
}
function nextimageAnteriores(current_imgid){
    var next = Number(current_imgid)+1;
    if (next >= tempgallery_anteriores.length) next = 0; 
	newimgid_anteriores = Number(current_imgid)+1;
	newwidth_anteriores =imggallery_anteriores[newimgid_anteriores][1]
	newheight_anteriores =imggallery_anteriores[newimgid_anteriores][2]
	newimgindex_anteriores =imggallery_anteriores[newimgid_anteriores][8]
	newimgid_anteriores = imggallery_anteriores[newimgid_anteriores][8]
	cwidth_anteriores=imggallery_anteriores[current_imgid][1]
	cheight_anteriores=imggallery_anteriores[current_imgid][2]
	nextorprev_anteriores=1;
	getstartedAnteriores(Number(newwidth_anteriores), Number(newheight_anteriores), 'imgloader_anteriores',Number(newimgindex_anteriores) ,Number(newimgid_anteriores) , Number(current_imgid), Number(cwidth_anteriores), Number(cheight_anteriores))
	
}

function previmageAnteriores(current_imgid){
	var prev = Number(current_imgid)-1;
    if (prev < 0) prev = tempgallery_anteriores.length-1; 
	newimgid_anteriores = Number(current_imgid)-1;
	newwidth_anteriores =imggallery_anteriores[newimgid_anteriores][1]
	newheight_anteriores =imggallery_anteriores[newimgid_anteriores][2]
	newimgindex_anteriores =imggallery_anteriores[newimgid_anteriores][8]
	newimgid_anteriores = imggallery_anteriores[newimgid_anteriores][8]
	cwidth_anteriores=imggallery_anteriores[current_imgid][1]
	cheight_anteriores=imggallery_anteriores[current_imgid][2]
	nextorprev_anteriores=1;
	getstartedAnteriores(Number(newwidth_anteriores), Number(newheight_anteriores), 'imgloader_anteriores',Number(newimgindex_anteriores) ,Number(newimgid_anteriores) , Number(current_imgid), Number(cwidth_anteriores), Number(cheight_anteriores))
}

