/*
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 = '960 850';
var MOOdalBox_offset = '18';
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;
	}
	// the contents you need are in the winter_big.swf and winter_big.html example
	//init the slider within the modal box
	setImg();
	try {
		var obj = document.getElementById("cbLangFtrcomboBox");
		obj.style.visibility = 'visible';
		//obj = document.getElementById("cbSearchFilterFtr");
		//obj.style.visibility = 'visible';
	}
	catch(e) {
	}
}

function call_lightbox(photo_number) {
	_CURRENT = photo_number;  
	try {
		MOOdalBox.open( // case matters
						"/" + lang + "/collections_flash_left/" + 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);
		setTimeout('refreshThumb()', 100);
		setTimeout(' var chiudi = document.getElementById("mb_bottom"); ' +
				   ' if(chiudi != null){ ' +
				   ' 	chiudi.style.top = "9px"; ' +
				   ' } ', 1500);
	} 
	catch(e) {
		alert(e);
	}
}

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

/** Used by MooTools'window, that is sportmax_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() {
	thisMovie("GalleryBig").next_image();
	
	//Update _Current var's value
	_CURRENT = (_CURRENT != (_MAX_IMAGES -1) ? (_CURRENT = _CURRENT+1) : (_CURRENT = 0));
	
	//Get PhotoIndex' span
	var index = document.getElementById("IndexPhoto");
	
	//change slider preview's image
	changeImg();
	
	//change the index span
	purge(index);
	index.innerHTML = (_CURRENT+1) + " | " + _MAX_IMAGES;
	
	show_img_title_desc(_CURRENT);
}

/* Delay effect in showing previous pictures */
function delayed_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 slider preview's image
	changeImg();
	
	//change the index span
	purge(index);
	index.innerHTML = (_CURRENT+1) + " | " + _MAX_IMAGES;
	
	show_img_title_desc(_CURRENT);
}

/* Show previous picture */
function prev_image() {
	thisMovie("GalleryBig").prev_image();
	window.setTimeout('delayed_prev_image()', 1000);
}

// is called when the flash is ready to recieve parameters
function call_flash() {
	thisMovie("GalleryBig").set_image(_CURRENT); // the image number you want to show (from 0)
}

// is called when the flash is ready to recieve parameters
function fullscreen_gallery_is_ready() {
	// 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();
	}
}
