/*
	This script implements the routines aiming at:
	1-open a modal box, containing a proper page and layout to navigate the gallery
	2-other stuffs(variables and routines) usefull from inside the modal box' page
  */

/* It stores the current photo number (just to order photos when using them!) */
var _CURRENT = 0;
var _MAX_IMAGES = img_tot_num;
var MOOdalBox_dim = '958 850';
var MOOdalBox_offset = '34';
var MOOdalBox_caption = ' ';

/* Change automatically the photo number displayed in a proper html tag */
function refreshThumb() {
	var index = document.getElementById("IndexPhoto");

	//change the index span
	if (index != null){
		purge(index);
		index.innerHTML = (_CURRENT+1) + " | " + _MAX_IMAGES;
	}
}

function call_lightbox(photo_number) {
	window.addEvent('domready', function() {
		_CURRENT = photo_number;
		try {
			MOOdalBox.open( // case matters
							"/" + lang + "/collections_flash_right/" + id_coll + "/" + (_CURRENT+1), // the link URL
							MOOdalBox_caption, // the caption (link's title) - can be blank
							MOOdalBox_dim, // width and height of the box - can be left blank
							MOOdalBox_offset);
			window.setTimeout('refreshThumb()', 100);
			
			var obj = document.getElementById("cbLangFtrcomboBox");
			obj.style.visibility = 'visible';
			//obj = document.getElementById("cbSearchFilterFtr");
			//obj.style.visibility = 'visible';
		} 
		catch(e) {
			alert(e);
		}
	});
}

/* This script manages the images' flow  and some related operations within the modal window. */

/** Used by MooTools'window, that is winter_big.html **/
/* Take the coontrol of the Flash movie */
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

/* Show next picture */
function next_image() {
	
	ricarica_varianti_colore();
	
	thisMovie("GalleryBig").next_image();
	
	
	//Update _Current var's value
	_CURRENT = (_CURRENT != (_MAX_IMAGES-1) ? (_CURRENT = _CURRENT+1) : (_CURRENT = 0));
	var index = document.getElementById("IndexPhoto");
	
	//change the index span
	purge(index);
	index.innerHTML = (_CURRENT+1) + " | " + _MAX_IMAGES;
	
	show_img_title_desc(_CURRENT);
}



/* Show previous picture */
function prev_image() {
	
	ricarica_varianti_colore();
	thisMovie("GalleryBig").prev_image();
	
	//Update _Current var's value
	_CURRENT = (_CURRENT != 0 ? (_CURRENT = _CURRENT-1) : (_CURRENT = (_MAX_IMAGES-1)));
	
	//Get PhotoIndex' span
	var index = document.getElementById("IndexPhoto");
	
	//change the index span
	purge(index);
	index.innerHTML = (_CURRENT+1) + " | " + _MAX_IMAGES;
	
	show_img_title_desc(_CURRENT);	
	//window.setTimeout("ch_image()",250);
	
}


// is called when the flash is ready to receive parameters
function fullscreen_gallery_is_ready() {
	//serve per far partire il flash delle varianti colore
	if (typeof(thisMovie("GalleryBigVarianti")) != "undefined") {
		try {
			thisMovie("GalleryBigVarianti").set_image(1); // the image number you want to show into Popup
		} catch(e) {}
	}

	// Determina se viene chiamata dalla popup 
	if (typeof(thisMovie("GalleryBig")) != "undefined") {
		thisMovie("GalleryBig").set_image(_CURRENT); // the image number you want to show into Popup
	}else {
		menu_invisible();
	}
}


function ricarica_varianti_colore(){
	// cambio di visualizzazione per la variante colori
	if (divToInject != null){
		$('ColorVariantFlash').innerHTML='';
		$('ColorVariantFlash').setStyle('display','none');
		
		
	}
}
