// JavaScript Document
function initGalleryVistos ( tempgallery, count, first_id, startwidth, startheight ) {
	imggallery_vistos = tempgallery;
	if (preloadimg_vistos=="yes"){
		for (x=0; x<imggallery_vistos.length; x++){
			var myimage=new Image()
			myimage.src=imggallery_vistos[x][0]
		}
	}
	
	current_imgid_vistos = first_id;
	currentwidth_vistos=startwidth;
	currentheight_vistos=startheight;
	
	window.addEvent('load', function() {
		var setloadersize = new Fx.Styles('main_image_wrapper_vistos',{duration:transspeed_vistos,onComplete: function(){loadfirstimageVistos(currentwidth_vistos,currentheight_vistos)}});
		
		setloadersize.start({
			'width':imggallery_vistos[0][1],
			'height':imggallery_vistos[0][2]	
		});
	});
	
}

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

function getstartedVistos(width, height, loadarea, imgindex, img_id, current_imgid){
	if(current_imgid!=img_id){
		if(firstimagestart_vistos==1){
			currentwidth_vistos=firstimagewidth_vistos;
			currentheight_vistos=firstimageheight_vistos;
			firstimagestart_vistos=0;		
		}
		if(nextorprev_vistos==1){
			currentwidth_vistos=cwidth_vistos;
			currentheight_vistos=cheight_vistos;
			nextorprev_vistos=0;		
		}
		
		var resizeDivHeight = new Fx.Styles('main_image_wrapper_vistos',{duration:transspeed_vistos, onComplete: function(){modifyimage_vistos(loadarea, imgindex, img_id);currentheight_vistos=height;currentwidth_vistos=width;} });
		var fader = new Fx.Style('imgloader_vistos','opacity', {duration:fadespeed_vistos, onComplete: function(){	resizeDivHeight.start({'height': [currentheight_vistos,height],'width': [currentwidth_vistos,width]});} });
		fader.start(1,0);
		var titlefade = new Fx.Style('desc_vistos','opacity', {duration:transspeed });
		titlefade.set(0);	
	}
}
function loadfirstimageVistos(currentwidth_vistos,currentheight_vistos){
	var fadefirst = new Fx.Style('imgloader_vistos','opacity', {duration:fadespeed_vistos });
	fadefirst.set(0);
	var firsttitlefade = new Fx.Style('desc_vistos','opacity', {duration:transspeed });
	firsttitlefade.set(0);
	function setfirstimage(){
		var newHTML = "<a href='"+tempgallery_vistos[0][7]+"' target='_self'><img src='"+tempgallery_vistos[0][0]+"' border='0' /></a>";
		$('imgloader_vistos').setHTML(newHTML);
	
		var firsttitle=document.getElementById('desc_vistos');
		firsttitle.innerHTML="<strong>"+ tempgallery_vistos[0][5] +"</strong> <br /> "+ tempgallery_vistos[0][6];
		fadefirst.start(0,1);
		firsttitlefade.start(0,1);
		currentheight_vistos=imggallery_vistos[0][2];
		currentwidth_vistos=imggallery_vistos[0][1];
	}
	new Asset.image(imggallery_vistos[0][0], {onload: setfirstimage});
}
function nextimageVistos(current_imgid){
    var next = Number(current_imgid)+1;
    if (next >= tempgallery_vistos.length) next = 0; 
	newimgid_vistos = Number(current_imgid)+1;
	newwidth_vistos =imggallery_vistos[newimgid_vistos][1]
	newheight_vistos =imggallery_vistos[newimgid_vistos][2]
	newimgindex_vistos =imggallery_vistos[newimgid_vistos][8]
	newimgid_vistos = imggallery_vistos[newimgid_vistos][8]
	cwidth_vistos=imggallery_vistos[current_imgid][1]
	cheight_vistos=imggallery_vistos[current_imgid][2]
	nextorprev_vistos=1;
	getstartedVistos(Number(newwidth_vistos), Number(newheight_vistos), 'imgloader_vistos',Number(newimgindex_vistos) ,Number(newimgid_vistos) , Number(current_imgid), Number(cwidth_vistos), Number(cheight_vistos))
	
}

function previmageVistos(current_imgid){
	var prev = Number(current_imgid)-1;
    if (prev < 0) prev = tempgallery_vistos.length-1; 
	newimgid_vistos = Number(current_imgid)-1;
	newwidth_vistos =imggallery_vistos[newimgid_vistos][1]
	newheight_vistos =imggallery_vistos[newimgid_vistos][2]
	newimgindex_vistos =imggallery_vistos[newimgid_vistos][8]
	newimgid_vistos = imggallery_vistos[newimgid_vistos][8]
	cwidth_vistos=imggallery_vistos[current_imgid][1]
	cheight_vistos=imggallery_vistos[current_imgid][2]
	nextorprev_vistos=1;
	getstartedVistos(Number(newwidth_vistos), Number(newheight_vistos), 'imgloader_vistos',Number(newimgindex_vistos) ,Number(newimgid_vistos) , Number(current_imgid), Number(cwidth_vistos), Number(cheight_vistos))
}

