//  just to change the DW collors <script>
// JavaScript Document
/*************************************************
*
* 							MODULE GALLERY
*	
* 		webmaster: luis felipe vianna da silva
*			GEN/23/2007
*************************************************/
// ----------------------------------------------
// 				Gallery Array Create New
// ----------------------------------------------
// album images and txts
var wGallery_id			 							= new Array();	//	images id
var wGallery_thumbs 							= new Array();	//	images thumbs
var wGallery_images_Before 				= new Array();	//	image before
var wGallery_images_After					= new Array();	//	image after
var wGallery_images_Title					= new Array();	//	image title
var wGallery_images_Description		= new Array();	//	image description 
// album configuration
var wconfig_thumb_width		 				= new Array();	
var wconfig_thumb_height 					= new Array();	
var wconfig_photo_width 					= new Array();	
var wconfig_photo_height					= new Array();	
var wconfig_effect 								= new Array();	
var wconfig_show_original				 	= new Array();	
var wconfig_show_original_effect 	= new Array();	
var wconfig_date									= new Array();	
// navigator arrows
var wGallery_maxRows_Gallery_Photos 		= new Array();	
var wGallery_pageNum_Gallery_Photos			= new Array();	
var wGallery_totalPages_Gallery_Photos 	= new Array();	
// album all photos in the db to config the LightBoxEffect
var wGallery_allPhotos_before						= new Array();	//	all image before
var wGallery_allPhotos_after						= new Array();	//	all image after

var wGalleryCounter 										= new Array();	// 	simple counter to know in which image we are working inside the functions

var wGalleries_Keyboard_onkeyup					= new Array();	//	all Galleies that will be moved using the keyboard

//	arrows controler for CPanel edit mode
var wGalleryArrowsOff							= false;

// ----------------------------------------------
//							Create Album
// ----------------------------------------------
function Gallery_CreateAlbum_Array (wGalleryAlbum) {
	// just create the ARRAY for the PHOTO ALBUM
	wGallery_id[wGalleryAlbum]										= new Array();	//	images thumbs
	wGallery_thumbs[wGalleryAlbum]								= new Array();	//	images thumbs
	wGallery_images_Before [wGalleryAlbum]				= new Array();	//	image before
	wGallery_images_After [wGalleryAlbum]					= new Array();	//	image after
	wGallery_images_Title [wGalleryAlbum]					= new Array();	//	image title
	wGallery_images_Description [wGalleryAlbum]		= new Array();	//	image description 

	// album configuration
	wconfig_thumb_width [wGalleryAlbum]		 				= 0;	
	wconfig_thumb_height [wGalleryAlbum] 					= 0;	
	wconfig_photo_width [wGalleryAlbum] 					= 0;	
	wconfig_photo_height [wGalleryAlbum]					= 0;	
	wconfig_effect [wGalleryAlbum] 								= false;	
	wconfig_show_original [wGalleryAlbum]				 	= false;	
	wconfig_show_original_effect [wGalleryAlbum] 	= false;	
	wconfig_date [wGalleryAlbum]									= 0;

	// album all photos in the db to config the LightBoxEffect
	wGallery_allPhotos_before [wGalleryAlbum]			= new Array();	//	all image before
	wGallery_allPhotos_after [wGalleryAlbum]			= new Array();	//	all image after

	// navigator arrows
	wGallery_maxRows_Gallery_Photos[wGalleryAlbum]			= 0;
	wGallery_pageNum_Gallery_Photos[wGalleryAlbum]			= 0;
	wGallery_totalPages_Gallery_Photos[wGalleryAlbum]		= 0;

	wGalleryCounter[wGalleryAlbum]											= 0;	// 	simple counter to know in which image we are working inside the functions
}


// ----------------------------------------------
// 									Fill Album
// ----------------------------------------------
function Gallery_Fill_AlbumArray (wGalleryAlbum) {
	http_request_Fill_AlbumArray = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request_Fill_AlbumArray = new XMLHttpRequest();
		if (http_request_Fill_AlbumArray.overrideMimeType) {
			//http_request_Fill_AlbumArray.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request_Fill_AlbumArray = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request_Fill_AlbumArray = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request_Fill_AlbumArray) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request_Fill_AlbumArray.open('POST', 'http://www.treemmeedilizia.com/modules/Gallery/fill_album_array.php', true);
	http_request_Fill_AlbumArray.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	postvar =		"wGalleryAlbum="+wGalleryAlbum;
	postvar +=	"&maxRows_Gallery_Photos="+wGallery_maxRows_Gallery_Photos [wGalleryAlbum];
	postvar +=	"&pageNum_Gallery_Photos="+wGallery_pageNum_Gallery_Photos [wGalleryAlbum];
	postvar +=	"&totalPages_Gallery_Photos="+wGallery_totalPages_Gallery_Photos [wGalleryAlbum];
	http_request_Fill_AlbumArray.send(postvar);

	// ----------------------------------------------
	// AFTER SEND TO THE PHP
	//	RUN THIS FUNCTION BELOW
	//		
	//									XML READER
	// ----------------------------------------------
	http_request_Fill_AlbumArray.onreadystatechange = function(){
		if (http_request_Fill_AlbumArray.readyState == 4) {
			if (http_request_Fill_AlbumArray.status == 200) {
				//--------------------------------------------
				//  The splice() method at it's most basic allows you to delete an element from the array 
				//--------------------------------------------
				for (i=0; i < wGallery_maxRows_Gallery_Photos[wGalleryAlbum]; i++) {
					wGallery_id[wGalleryAlbum][i] 									= undefined;
					wGallery_thumbs[wGalleryAlbum][i] 							= undefined;
					wGallery_images_Before [wGalleryAlbum][i] 			= undefined;
					wGallery_images_After [wGalleryAlbum][i] 				= undefined;
					wGallery_images_Title [wGalleryAlbum][i] 				= undefined;
					wGallery_images_Description [wGalleryAlbum][i] 	= undefined;
				}
				//--------------------------------------------
				//  SIMPLE COUNTER TO THE THUMBS IMAGES ARRAY
				//--------------------------------------------
				var	tempNodexCount_Album = 0;
				var	tempNodexCount_AllImages = 0;
				
				//--------------------------------------------
				//	OPEN XML
				//--------------------------------------------
				var xmldoc = http_request_Fill_AlbumArray.responseXML;
				var root = xmldoc.getElementsByTagName('root').item(0);
				//				
				for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
					 var node = root.childNodes.item(iNode);
						// 
					 for (i = 0; i < node.childNodes.length; i++) {
							// read inside the <data>
							var sibl = node.childNodes.item(i);
							if (sibl.childNodes.length > 0) {
								/*
								*
								*					IF THE childNodes HAVE CONTENT
								*					sibl
								*							<nodes>
								*							<nodes>
								*							<nodes>
								*							...
								*
								*/
								// ----------------------------------------
								// Fill the PHOTO ALBUM Array
								// ----------------------------------------
								if (sibl.getElementsByTagName("id").item(0))
									wGallery_id [wGalleryAlbum][tempNodexCount_Album] 									= sibl.getElementsByTagName('id').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("thumb").item(0))
									wGallery_thumbs [wGalleryAlbum][tempNodexCount_Album] 							= sibl.getElementsByTagName('thumb').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("photo").item(0))
									wGallery_images_Before [wGalleryAlbum][tempNodexCount_Album]				= sibl.getElementsByTagName('photo').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("photo_after").item(0))
									wGallery_images_After [wGalleryAlbum][tempNodexCount_Album]					= sibl.getElementsByTagName('photo_after').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("line").item(0))
									wGallery_images_Title [wGalleryAlbum][tempNodexCount_Album]					= changeHTMLSpecialCharacters( sibl.getElementsByTagName('line').item(0).childNodes.item(0).data );
								if (sibl.getElementsByTagName("multiline").item(0))
									wGallery_images_Description [wGalleryAlbum][tempNodexCount_Album]  	= changeHTMLSpecialCharacters( sibl.getElementsByTagName('multiline').item(0).childNodes.item(0).data );
								
								if (sibl.getElementsByTagName("thumb").item(0))
									tempNodexCount_Album++;

								// ----------------------------------------
								// Fill PHOTO ALBUM Array all photos in DataBase - usefull for LightBox
								// ----------------------------------------
								if (sibl.getElementsByTagName("allPhotos_before").item(0))
									wGallery_allPhotos_before [wGalleryAlbum][tempNodexCount_AllImages] 		= sibl.getElementsByTagName('allPhotos_before').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("allPhotos_after").item(0))
									wGallery_allPhotos_after [wGalleryAlbum][tempNodexCount_AllImages] 			= sibl.getElementsByTagName('allPhotos_after').item(0).childNodes.item(0).data;

								if (sibl.getElementsByTagName("allPhotos_before").item(0))
									tempNodexCount_AllImages++;

								// ----------------------------------------
								// Fill the ALBUM CONFIGURATION Array
								// ----------------------------------------
								if (sibl.getElementsByTagName("config_thumb_width").item(0))
									wconfig_thumb_width [wGalleryAlbum] 						 			= sibl.getElementsByTagName('config_thumb_width').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_thumb_height").item(0))
									wconfig_thumb_height [wGalleryAlbum] 				 					= sibl.getElementsByTagName('config_thumb_height').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_photo_width").item(0))
									wconfig_photo_width [wGalleryAlbum] 						 			= sibl.getElementsByTagName('config_photo_width').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_photo_height").item(0))
									wconfig_photo_height [wGalleryAlbum] 						 			= sibl.getElementsByTagName('config_photo_height').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_effect").item(0))
									wconfig_effect [wGalleryAlbum]								  			= sibl.getElementsByTagName('config_effect').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_show_original").item(0)) 
									wconfig_show_original [wGalleryAlbum]  								= sibl.getElementsByTagName('config_show_original').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_show_original_effect").item(0))
									wconfig_show_original_effect [wGalleryAlbum]  				= sibl.getElementsByTagName('config_show_original_effect').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("config_date").item(0))
									wconfig_date [wGalleryAlbum]  												= sibl.getElementsByTagName('config_date').item(0).childNodes.item(0).data;
								// ----------------------------------------
								// Fill the NAVIGATOR ARROW INFORMATIONS
								// ----------------------------------------
								if (sibl.getElementsByTagName("maxRows_Gallery_Photos").item(0))
									wGallery_maxRows_Gallery_Photos [wGalleryAlbum]  			= sibl.getElementsByTagName('maxRows_Gallery_Photos').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("pageNum_Gallery_Photos").item(0))
									wGallery_pageNum_Gallery_Photos [wGalleryAlbum]  			= sibl.getElementsByTagName('pageNum_Gallery_Photos').item(0).childNodes.item(0).data;
								if (sibl.getElementsByTagName("totalPages_Gallery_Photos").item(0))
									wGallery_totalPages_Gallery_Photos [wGalleryAlbum]  	= sibl.getElementsByTagName('totalPages_Gallery_Photos').item(0).childNodes.item(0).data;
								//------------------------------------------
								//		if there are more pages, shor right arrow
								//				this is vbery important for the insert new data
								// ----------------------------------------
								if (wGallery_pageNum_Gallery_Photos [wGalleryAlbum] < wGallery_totalPages_Gallery_Photos [wGalleryAlbum]) 
									Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','on');
								else 
									Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','off');
							}
					 }
				}
				
				Gallery_FillAlbum(wGalleryAlbum);
				// if the total of images are <= than the thumbs, hide the right arrow
				// we need to show only one page
				if (wGallery_totalPages_Gallery_Photos[wGalleryAlbum] == 0)
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','off');

			} else {
				alert('There was a problem with the request.');
			}
		}
	}
}

// ----------------------------------------------
// 							SCRIPTs:
//				- GalleryInit
//				- Gallery_mainChangeImage
//				- Gallery_Change_After_Before_Image
//				- GalleryInit
// ----------------------------------------------


function GalleryInit (wGalleryAlbum) {
	// Count How much thumbs image teh webpage have
	//	usefull for the navigator arrow
	Gallery_CreateAlbum_Array(wGalleryAlbum);
	Gallery_Count_Thumbs_Fields(wGalleryAlbum);
	Gallery_Fill_AlbumArray(wGalleryAlbum);
	// Init the Keyboard keys using one array for possibles multi albuns
	wGalleries_Keyboard_onkeyup[wGalleries_Keyboard_onkeyup.length]	= wGalleryAlbum;
	document.onkeyup   			= keyHandler;
	// when intit the photo album we need hide the PreviousPage Arrow
	Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'left','off');
}

// ----------------------------------------------
// 			FILL THE ALBUM IN THE WEBPAGES
// ----------------------------------------------
function Gallery_FillAlbum(wGalleryAlbum) {
	/* ************************************************
	*			FIRST TIME:  LOAD THE ALL INFORMATIONS
	*			AND FILL
	* *************************************************/

	if (!document.getElementsByTagName){ return; }
	var FirstThumbFound = '';
	/* ************************************************
	*								Search the IMGs
	*		the important images are the thumbs and the mainImage
	* *************************************************/
	var Gallery_thumbs_tags = document.getElementsByTagName("IMG");
	// loop through all IMAGES tags
	for (var i=0; i < Gallery_thumbs_tags.length; i++){
		var Gallery_thumbs_tag = Gallery_thumbs_tags[i];
		// search for Gallery="thumbs


		/* ************************************************
		*										FILL THE THUMBS
		* *************************************************/
		if (Gallery_thumbs_tag.getAttribute("Gallery") == "thumbs" 
				&& Gallery_thumbs_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			wTempCounter 	= wGalleryCounter[wGalleryAlbum];

			if (wGallery_thumbs [wGalleryAlbum][ wTempCounter ] != undefined) {
				// catch the id to the mainimage
				if (FirstThumbFound == '') FirstThumbFound = Gallery_thumbs_tag.id;
				// Change the img founds
				//
				// ex.: <img src="public/lavori_svolti/images_thumb/01.jpg" alt="lavori svolti tre emme" width="60" height="60" border="0"  Gallery="thumbs" />
				Gallery_thumbs_tag.src 		= wGallery_thumbs [wGalleryAlbum][ wTempCounter ];
				Gallery_thumbs_tag.alt 		= changeHTMLSpecialCharacters( wGallery_images_Title [wGalleryAlbum][ wTempCounter ] );
	
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_thumbs_tag.GalleryCounter = wGalleryCounter[wGalleryAlbum];
				Gallery_thumbs_tag.GalleryAlbum 	= wGalleryAlbum;
	
				// add link and cursor
				Gallery_thumbs_tag.style.cursor = "pointer";
				Gallery_thumbs_tag.onclick 			= function () {Gallery_mainChangeImage(this);}

				// function for upload the image
				Gallery_thumbs_tag.ondblclick		= function ()		{CPanel_image_onDblClick_Gallery(this, 600,250); return false;}

				// Set CPanel Frontend Configurations
				Gallery_thumbs_tag.setAttribute( "cpanel_id" , wGallery_id [wGalleryAlbum][wTempCounter] );

				// Make the thumb's FRAME visible
				Gallery_divThumbs_Display (wGalleryAlbum, wGalleryCounter[wGalleryAlbum], BrowserVisibilityOn);
					wGalleryCounter[wGalleryAlbum]++;

			} else {
				// Make the thumb's FRAME invisible
				Gallery_divThumbs_Display (wGalleryAlbum, wGalleryCounter[wGalleryAlbum], BrowserVisibilityOff);
			}
		}

	/* ************************************************
	*
	*			RUN THE array [0]
	*
	* *************************************************/

		/* ************************************************
		*			 FILL THE mainIMAGE
		* *************************************************/
		if (Gallery_thumbs_tag.getAttribute("Gallery") == "MainImage" 
				&& Gallery_thumbs_tag.getAttribute("GalleryAlbum") == wGalleryAlbum) {
			// there is this wGalleryAlbum ?
			if (wGallery_images_Before [wGalleryAlbum][0] != undefined) {
				// Change the img founds
				//
				// ex.: <img src="public/lavori_svolti/images_thumb/01.jpg" alt="lavori svolti tre emme" width="60" height="60" border="0"  Gallery="thumbs" />
				Gallery_thumbs_tag.src = wGallery_images_Before [wGalleryAlbum][0];
				Gallery_thumbs_tag.alt = changeHTMLSpecialCharacters( wGallery_images_Title [wGalleryAlbum][0] );
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_thumbs_tag.GalleryCounter = 0;
				Gallery_thumbs_tag.GalleryAlbum = wGalleryAlbum;

				// function for upload the image
				Gallery_thumbs_tag.ondblclick			= function ()		{CPanel_image_onDblClick_Gallery(this, 600,250); return false;}

				// Set CPanel Frontend Configurations
				Gallery_thumbs_tag.setAttribute( "cpanel_id" , wGallery_id [wGalleryAlbum][0] );
				Gallery_thumbs_tag.setAttribute( "cpanel_BeforeAfter" , "before" );
				Gallery_thumbs_tag.setAttribute( "Gallery_thumbId" , FirstThumbFound );

				// Now we need to run possible album effects 
				Gallery_effect (wGallery_id [wGalleryAlbum][0], wGalleryAlbum, Gallery_thumbs_tag);
			}
		}
	}




		/* ************************************************
		*							Search the DIVs and fill it
		*		the important divs are:
		*			- the Title
		*			- the Description
		*			- the After and Before
		* *************************************************/
	var Gallery_Div_tags = document.getElementsByTagName("DIV");
	// loop through all DIVS tags
	for (var i=0; i < Gallery_Div_tags.length; i++){
		var Gallery_Div_tag = Gallery_Div_tags[i];
		/* ************************************************
		*			Gallery="line" GalleryAlbum="album1"
		* *************************************************/
		if ( Gallery_Div_tag.getAttribute("Gallery") == "line" 								&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_Title [wGalleryAlbum][0] != undefined)
				Gallery_Div_tag.innerHTML	= changeHTMLSpecialCharacters( wGallery_images_Title	[wGalleryAlbum][0] );
				Gallery_Div_tag.id				= "div_INPUT_"+wGallery_id [wGalleryAlbum][0]+"_Gallery";
		}
		/* ************************************************
		*			Gallery="multiline" GalleryAlbum="album1"
		* *************************************************/
		if ( Gallery_Div_tag.getAttribute("Gallery") == "multiline" 					&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_Description [wGalleryAlbum][0] != undefined)
				Gallery_Div_tag.innerHTML = wGallery_images_Description	[wGalleryAlbum][0];
				Gallery_Div_tag.id				= "div_TEXTAREA_"+wGallery_id [wGalleryAlbum][0]+"_Gallery";
		}
		/* ************************************************
		*			Gallery="ChangeImage_Before" GalleryAlbum="album1"
		* *************************************************/
		if (Gallery_Div_tag.getAttribute("Gallery") == "ChangeImage_Before" 	&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_Before [wGalleryAlbum][0] != undefined) {
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
				Gallery_Div_tag.GalleryImageUrl	 		= wGallery_images_Before	[wGalleryAlbum][0];
				Gallery_Div_tag.GalleryID				 		= wGallery_id	[wGalleryAlbum][0];
				// add link and cursor
				Gallery_Div_tag.style.cursor = "pointer";
				Gallery_Div_tag.onclick = function () {Gallery_Change_After_Before_Image(this);}
			}
		}
		/* ************************************************
		*			Gallery="ChangeImage_After" GalleryAlbum="album1"
		* *************************************************/
		if ( Gallery_Div_tag.getAttribute("Gallery") == "ChangeImage_After" 	&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_After [wGalleryAlbum][0] != undefined) {
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
				Gallery_Div_tag.GalleryImageUrl	 		= wGallery_images_After	[wGalleryAlbum][0];
				Gallery_Div_tag.GalleryID				 		= wGallery_id	[wGalleryAlbum][0];
				// add link and cursor
				Gallery_Div_tag.style.cursor = "pointer";
				Gallery_Div_tag.onclick = function () {Gallery_Change_After_Before_Image(this);}
			}
		}

		/* ************************************************
		*			Gallery="thumbs_LeftArrow" GalleryAlbum="album1"
		* *************************************************/
		if ( Gallery_Div_tag.getAttribute("Gallery") == "thumbs_LeftArrow" 		&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_After [wGalleryAlbum][0] != undefined) {
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
//				Gallery_Div_tag.GalleryImageUrl	 		= wGallery_images_After	[wGalleryAlbum][0];
				// add link and cursor
				Gallery_Div_tag.style.cursor = "pointer";
				Gallery_Div_tag.onclick = function () {Gallery_Arrow_PreviousPage (this.GalleryAlbum);}
			}
		}
		/* ************************************************
		*			Gallery="thumbs_LeftArrow" GalleryAlbum="album1"
		* *************************************************/
		if ( Gallery_Div_tag.getAttribute("Gallery") == "thumbs_RightArrow"		&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (wGallery_images_After [wGalleryAlbum][0] != undefined) {
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
//				Gallery_Div_tag.GalleryImageUrl	 		= wGallery_images_After	[wGalleryAlbum][0];
				// add link and cursor
				Gallery_Div_tag.style.cursor = "pointer";
				Gallery_Div_tag.onclick = function () {Gallery_Arrow_NextPage(this.GalleryAlbum);}
			}
		}
	}
}


/* ************************************************
*
*		THIS FUNCTION COUNT THE TOTAL THUMBS IMAGES IN THE PAGE
*		UTILIZED IN THE THUMBS GALLERY AND FILL THE 
*			wGallery_maxRows_Gallery_Photos['*******']
*
* *************************************************/
function Gallery_Count_Thumbs_Fields (wGalleryAlbum) {
	if (!document.getElementsByTagName){ return; }
	/* ************************************************
	*								Search the IMGs
	*		the important images are the thumbs and the mainImage
	* *************************************************/
	var Gallery_thumbs_tags = document.getElementsByTagName("IMG");
	// loop through all IMAGES tags
	for (var i=0; i < Gallery_thumbs_tags.length; i++){
		var Gallery_thumbs_tag = Gallery_thumbs_tags[i];
		// search for Gallery="thumbs
		/* ************************************************
		*										LOAD THE THUMBS
		* *************************************************/
		if (Gallery_thumbs_tag.getAttribute("Gallery") == "thumbs"
				&& Gallery_thumbs_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			wGalleryAlbum = Gallery_thumbs_tag.getAttribute("GalleryAlbum");
			wGallery_maxRows_Gallery_Photos[wGalleryAlbum]++;
		}
	}
}


/* ************************************************
*
*			THIS FUNCTION CHANGE ALL THE MAIN INFORMATIONS
*				LIKE: mainIMAGE, title, description
*
* *************************************************/
function Gallery_mainChangeImage (thumbObject) {
  //
  //		INITIAL FUNCTION:  CONFIGURE ALL WEBPAGE
  //
  // The BIG Image have: Gallery="MainImage" GalleryAlbum="album1" 
  wGalleryAlbum				= thumbObject.GalleryAlbum;
  thumbObjectCounter	= thumbObject.GalleryCounter;

  if (!document.getElementsByTagName){ return; }
  /* ************************************************
  *
  *								Search the MainImage
  *
  * *************************************************/
  var Gallery_mainImage_tags = document.getElementsByTagName("IMG");
  // loop through all IMAGES tags
  for (var i=0; i < Gallery_mainImage_tags.length; i++) {
    var Gallery_mainImage_tag = Gallery_mainImage_tags[i];
    // search for Gallery= mainImage
    if ( (Gallery_mainImage_tag.getAttribute("Gallery") == "MainImage") && Gallery_mainImage_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      // Change the img founds
      Gallery_mainImage_tag.src = wGallery_images_Before	[wGalleryAlbum][thumbObjectCounter];
      Gallery_mainImage_tag.alt = changeHTMLSpecialCharacters( wGallery_images_Title 	[wGalleryAlbum][thumbObjectCounter] );

			// Set CPanel Frontend Configurations
			Gallery_mainImage_tag.setAttribute( "cpanel_id" , wGallery_id [wGalleryAlbum][thumbObjectCounter] );
			Gallery_mainImage_tag.setAttribute( "cpanel_BeforeAfter" , "before" );
			Gallery_mainImage_tag.setAttribute( "Gallery_thumbId" , thumbObject.id );

			// function for upload the image
			Gallery_mainImage_tag.ondblclick			= function ()		{CPanel_image_onDblClick_Gallery(this, 600,250); return false;}

			// Now we need to run possible album effects 
			Gallery_effect (wGallery_id [wGalleryAlbum][thumbObjectCounter], wGalleryAlbum, Gallery_mainImage_tag);
    }
  }
  /* ************************************************
  *
  *							Search the DIV
  *
  * *************************************************/
  var Gallery_Div_tags = document.getElementsByTagName("DIV");
  // loop through all DIVS tags
  for (var i=0; i < Gallery_Div_tags.length; i++){
    var Gallery_Div_tag = Gallery_Div_tags[i];
    /* ************************************************
    *			Gallery="line" GalleryAlbum="album1"
    * *************************************************/
    if ( (Gallery_Div_tag.getAttribute("Gallery") == "line") && Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      Gallery_Div_tag.innerHTML  = changeHTMLSpecialCharacters( wGallery_images_Title	[wGalleryAlbum][thumbObjectCounter] );
			Gallery_Div_tag.id				= "div_INPUT_"+wGallery_id [wGalleryAlbum][thumbObjectCounter]+"_Gallery";			
    }
    /* ************************************************
    *			Gallery="multiline" GalleryAlbum="album1"
    * *************************************************/
    if ( (Gallery_Div_tag.getAttribute("Gallery") == "multiline") && Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      Gallery_Div_tag.innerHTML = wGallery_images_Description	[wGalleryAlbum][thumbObjectCounter];
			Gallery_Div_tag.id				= "div_TEXTAREA_"+wGallery_id [wGalleryAlbum][thumbObjectCounter]+"_Gallery";
    }
    /* ************************************************
    *			Gallery="ChangeImage_Before" GalleryAlbum="album1"
    * *************************************************/
    if ( (Gallery_Div_tag.getAttribute("Gallery") == "ChangeImage_Before") && Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      // add a informations into this the image tag
      // will be send inside the Gallery_mainChangeImage by the 'this' arg
      Gallery_Div_tag.GalleryAlbum 		= wGalleryAlbum;
      Gallery_Div_tag.GalleryImageUrl	= wGallery_images_Before	[wGalleryAlbum][thumbObjectCounter];
			Gallery_Div_tag.GalleryID				= wGallery_id	[wGalleryAlbum][thumbObjectCounter];
      // add link and cursor
      Gallery_Div_tag.style.cursor = "pointer";
      Gallery_Div_tag.onclick = function () {Gallery_Change_After_Before_Image(this);}
    }
    /* ************************************************
    *			Gallery="ChangeImage_After" GalleryAlbum="album1"
    * *************************************************/
    if ( (Gallery_Div_tag.getAttribute("Gallery") == "ChangeImage_After") && Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      // add a informations into this the image tag
      // will be send inside the Gallery_mainChangeImage by the 'this' arg
      Gallery_Div_tag.GalleryAlbum 		= wGalleryAlbum;
      Gallery_Div_tag.GalleryImageUrl	= wGallery_images_After	[wGalleryAlbum][thumbObjectCounter];
			Gallery_Div_tag.GalleryID				= wGallery_id	[wGalleryAlbum][thumbObjectCounter];
			// add link and cursor
      Gallery_Div_tag.style.cursor = "pointer";
      Gallery_Div_tag.onclick = function () {Gallery_Change_After_Before_Image(this);}
    }
  }
  /* *************************************************/

}


/* ************************************************
*
*			THIS FUNCTION ONLY CHANGE THE mainIMAGE
*					usefull for After and Before
*
* *************************************************/
function Gallery_Change_After_Before_Image (thumbObject) {
  //
  //		INITIAL FUNCTION:  CONFIGURE ALL WEBPAGE
  //
  // The BIG Image have: Gallery="MainImage" GalleryAlbum="album1" 
  wGalleryAlbum					= thumbObject.GalleryAlbum;
  thumbObject_ImageURL	= thumbObject.GalleryImageUrl;
	wID										= thumbObject.GalleryID;
  
  if (!document.getElementsByTagName){ return; }
  /* ************************************************
  *
  *								Search the MainImage
  *
  * *************************************************/
  var Gallery_mainImage_tags = document.getElementsByTagName("IMG");
  // loop through all IMAGES tags
  for (var i=0; i < Gallery_mainImage_tags.length; i++){
    var Gallery_mainImage_tag = Gallery_mainImage_tags[i];
    // search for Gallery= mainImage
    if ( (Gallery_mainImage_tag.getAttribute("Gallery") == "MainImage") && Gallery_mainImage_tag.getAttribute("GalleryAlbum") == wGalleryAlbum ){
      // Change the img founds
      Gallery_mainImage_tag.src = thumbObject_ImageURL;

			if ( Gallery_mainImage_tag.getAttribute("cpanel_BeforeAfter")=="before" )
				Gallery_mainImage_tag.setAttribute( "cpanel_BeforeAfter" , "after" );
			else
				Gallery_mainImage_tag.setAttribute( "cpanel_BeforeAfter" , "before" );

			// function for upload the image
			Gallery_mainImage_tag.ondblclick			= function ()		{CPanel_image_onDblClick_Gallery(this, 600,250); return false;}

			Gallery_effect (wID, wGalleryAlbum, Gallery_mainImage_tag)
    }
  }
}


/* ************************************************
*
*			THIS FUNCTION ONLY CHANGE THE mainIMAGE
*					usefull for After and Before
*
* *************************************************/
function Gallery_Arrow_PreviousPage (wGalleryAlbum) {
	//
	//			If is in FrontEnd edit mode do not navigate using the arrows
	//
	if (wGalleryArrowsOff == false) {
		//
		//		INITIAL FUNCTION:  CONFIGURE ALL WEBPAGE
		//
		// The BIG Image have: Gallery="MainImage" GalleryAlbum="album1" 
		if ( wGallery_pageNum_Gallery_Photos[wGalleryAlbum] != 0) {
				// zero the simple thumbs gallery counter
				wGalleryCounter[wGalleryAlbum]	=	0;
				// previous page
				wGallery_pageNum_Gallery_Photos[wGalleryAlbum]--;
				
				if ( wGallery_pageNum_Gallery_Photos[wGalleryAlbum] == 0) {
					// do not ADD
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'left','off');
					if (wGallery_totalPages_Gallery_Photos[wGalleryAlbum] != 0)
						Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','on');
				} else {
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'left','on');
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','on');
				}
				// fill the album
				Gallery_Fill_AlbumArray (wGalleryAlbum);
				
		}
	}
}
function Gallery_Arrow_NextPage (wGalleryAlbum) {
	//
	//			If is in FrontEnd edit mode do not navigate using the arrows
	//
	if (wGalleryArrowsOff == false) {
		//
		//		INITIAL FUNCTION:  CONFIGURE ALL WEBPAGE
		//
		// The BIG Image have: Gallery="MainImage" GalleryAlbum="album1" 
		if ( wGallery_pageNum_Gallery_Photos[wGalleryAlbum] < wGallery_totalPages_Gallery_Photos[wGalleryAlbum]) {
				// zero the simple thumbs gallery counter
				wGalleryCounter[wGalleryAlbum]	=	0;
				// Next page
				wGallery_pageNum_Gallery_Photos[wGalleryAlbum]++;

				if ( wGallery_pageNum_Gallery_Photos[wGalleryAlbum] == wGallery_totalPages_Gallery_Photos[wGalleryAlbum]) {
					// do not ADD
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','off');
					if (wGallery_totalPages_Gallery_Photos[wGalleryAlbum] != 0)
						Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'left','on');
				} else {
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'left','on');
					Gallery_TurnOnOff_Arrows (wGalleryAlbum, 'right','on');
				}
				// fill the album
				Gallery_Fill_AlbumArray (wGalleryAlbum);
		}
	}
}

/* ************************************************
*
*			OTHERS NAVIGATIONS FUNCTIONS
*			
*
* *************************************************/
function Gallery_Reload (wGalleryAlbum) {
  //
  //		INITIAL FUNCTION:  CONFIGURE ALL WEBPAGE
  //
  // The BIG Image have: Gallery="MainImage" GalleryAlbum="album1" 
	// zero the simple thumbs gallery counter
	wGalleryCounter[wGalleryAlbum]	=	0;
	Gallery_Fill_AlbumArray (wGalleryAlbum);
}

function Gallery_divThumbs_Display (wGalleryAlbum, thumbCounter, displayValue) {
	// if ther isn't the image 
	// HIDE the Content
	var tempDIVs = document.getElementsByTagName("DIV");
	var tempDIVsCount = 0;
	// loop through all IMAGES tags
	for (var j=0; j < tempDIVs.length; j++){
		var tempDIVs_tag = tempDIVs[j];
		// search for Gallery="thumbs
		if (tempDIVs_tag.getAttribute("Gallery") == "thumbsContent"  && tempDIVs_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
			if (thumbCounter == tempDIVsCount) {
				tempDIVs_tag.style.visibility = displayValue;
				// if you call this function because you are finished the images to be showed
				// then we will need to hide all the others thumbs frames
				// to do this just increment the ThumbwGalleryCounter 
				// incrementing the wGalleryCounter we will are selecting the newt thumbImage
				if (displayValue == BrowserVisibilityOff) wGalleryCounter[wGalleryAlbum]++;
				
				tempDIVsCount++;
			} else {
				tempDIVsCount++;
			}
		}
	}
}

function Gallery_TurnOnOff_Arrows (wGalleryAlbum, Arrow, Click) {
		/* ************************************************
		*			Search the DIVs Arrows and turn ON or OFF
		*			- Arrow = 'left' or 'right'
		*			- Click = 'on' or 'off'
		* *************************************************/
	var Gallery_Div_tags = document.getElementsByTagName("DIV");
	// loop through all DIVS tags
	for (var i=0; i < Gallery_Div_tags.length; i++){
		var Gallery_Div_tag = Gallery_Div_tags[i];

		if (Arrow == "left") {
			/* ************************************************
			*			Gallery="thumbs_LeftArrow" GalleryAlbum="album1"
			* *************************************************/
			if ( Gallery_Div_tag.getAttribute("Gallery") == "thumbs_LeftArrow" 		&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum)	{
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
				// add link and cursor
				if (Click == "off") {
					Gallery_Div_tag.style.visibility  = BrowserVisibilityOff;
				} else {
					Gallery_Div_tag.style.visibility = BrowserVisibilityOn;
				}
			} 
		}

		if (Arrow == "right") {
			/* ************************************************
			*			Gallery="thumbs_LeftArrow" GalleryAlbum="album1"
			* *************************************************/
			if ( Gallery_Div_tag.getAttribute("Gallery") == "thumbs_RightArrow"		&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum){
				// add a informations into this the image tag
				// will be send inside the Gallery_mainChangeImage by the 'this' arg
				Gallery_Div_tag.GalleryAlbum 				= wGalleryAlbum;
				// add link and cursor
				if (Click == "off") {
					Gallery_Div_tag.style.visibility  = BrowserVisibilityOff;
				} else {
					Gallery_Div_tag.style.visibility = BrowserVisibilityOn;
				}
			}
		}
	}
}


/* ************************************************
*
*									Create the Keyboard events
*
*  ************************************************/
function keyHandler( e ) {
	if( !e ) {
		e = window.event;
	}
	arrowUp = 38;
	arrowDown = 40;
	arrowLeft = 37;
	arrowRight = 39;
	Escape = 27;

	switch( e.keyCode ) {
		case arrowUp:
		//Do something
		break;
		case arrowDown:
		//Do something
		break;
		case arrowLeft:
			wVerify_if_Lightbox = document.getElementById ('lightbox').style.display;
			if (wVerify_if_Lightbox == 'none')
				for (i=0; i<wGalleries_Keyboard_onkeyup.length; i++) 
					Gallery_Arrow_PreviousPage (wGalleries_Keyboard_onkeyup[i]);
		//Do something
		break;
		case arrowRight:
			wVerify_if_Lightbox = document.getElementById ('lightbox').style.display;
			if (wVerify_if_Lightbox == 'none')
				for (i=0; i<wGalleries_Keyboard_onkeyup.length; i++) 
					Gallery_Arrow_NextPage (wGalleries_Keyboard_onkeyup[i]);
		//Do something
		break;
		case Escape:
			hidefrontend_CPanel();
		break;
	}
}




/* ************************************************
*
*				Config the ALBUM EFFECTS
*
*  ************************************************/
function  Gallery_effect (wID, wGalleryAlbum, objectMainImage) {
	/*
	*						DO NOT SHOW EFFECTS WHEN THE id IS -1
	*				remember: ID = -1 is used for something particular
	*/

	/*
	*			If the user is logged do not show effects
	*/
	var Logged = '';
	if ( Logged == '') {	

		/* ************************************************
		*								Show Original ?
		*  ************************************************/
		if (wconfig_show_original [wGalleryAlbum] == true){
			/* ************************************************
			*
			*											LIGHTBOX
			*
			*				Show Original with LightBox Effect ?
			*
			*  ************************************************/
			if (wconfig_show_original_effect [wGalleryAlbum] == "LightBox"){
				/* ************************************************
				*			Search the DIVs Gallery="lightbox_albumlist" 
				* *************************************************/
				var Gallery_Div_tags = document.getElementsByTagName("DIV");
				// loop through all DIVS tags
				for (var i=0; i < Gallery_Div_tags.length; i++){
					var Gallery_Div_tag = Gallery_Div_tags[i];
			
					/* ************************************************
					*			Gallery="thumbs_LeftArrow" GalleryAlbum="album1"
					* *************************************************/
					if ( Gallery_Div_tag.getAttribute("Gallery") == "lightbox_albumlist"	&& Gallery_Div_tag.getAttribute("GalleryAlbum") == wGalleryAlbum)	{
						/*
						*	we have selected the content of the DIV of the mainImage
						*		now we need to fill with <a> and write the image in its the specific position
						*/
						
						//	<a href="http://treemme/public/lavori_svolti/images_before/02.jpg" rel="lightbox[roadtrip]"></a>
						//	<img src="public/lavori_svolti/images_before/01.jpg" alt="Lavori Svolti - Tree Emme" name="GaleryBigImage" width="278" height="220" border="0" id="GaleryBigImage"  Gallery="MainImage" GalleryAlbum="lavori_svolti" />
	
						// Create temp variable to extract the url
						var temp_src_index = objectMainImage.src.indexOf("public");
						if (temp_src_index != -1) {
							// Create variable from ? in the url to the end of the string
							object_img_src = objectMainImage.src.substring(temp_src_index, objectMainImage.src.length);
						} else {
							object_img_src = objectMainImage.src;
						}
	
						/*
						* 					REMOVE the LIGHTBOX links
						*/
						wTemp_lightbox_albumlist_Content = Gallery_Div_tag.innerHTML;
						for (j=0; j < wGallery_allPhotos_before [wGalleryAlbum].length; j++) {
							newUrl = wGallery_allPhotos_before [wGalleryAlbum][j];
							newUrl = newUrl.replace ('/images_before/','/images_before/originals/');
							searchTXT = '<a href="'+newUrl+'" rel="lightbox[roadtrip]">';
							wTemp_lightbox_albumlist_Content = wTemp_lightbox_albumlist_Content.replace (searchTXT, "");
							newUrl = wGallery_allPhotos_after [wGalleryAlbum][j];
							newUrl = newUrl.replace ('/images_after/','/images_after/originals/');
							searchTXT = '<a href="'+newUrl+'" rel="lightbox[roadtrip]">';
							wTemp_lightbox_albumlist_Content = wTemp_lightbox_albumlist_Content.replace (searchTXT, "");
						}
						for (j=0; j < wGallery_allPhotos_before [wGalleryAlbum].length; j++) {
							searchTXT = "</a>\n";
							wTemp_lightbox_albumlist_Content = wTemp_lightbox_albumlist_Content.replace (searchTXT, "");
						}
	
						/*
						* 									ADD the LIGHTBOX links
						*			
						*				with the original image in the count point
						*/
						// Recreate the LIGHTBOX links and add the selected mainImage inside the 
						// Restar the "insertTXT" variable
						insertTXT = "";
						if ( object_img_src.search("images_before") != -1) {
							for (j=0; j < wGallery_allPhotos_before [wGalleryAlbum].length; j++) {
								newUrl = wGallery_allPhotos_before [wGalleryAlbum][j];
								newUrl = newUrl.replace ('/images_before/','/images_before/originals/');
								insertTXT += '<a href="'+newUrl+'" rel="lightbox[roadtrip]">';
									if (wGallery_allPhotos_before [wGalleryAlbum][j] == object_img_src) {
										insertTXT += wTemp_lightbox_albumlist_Content;
									}
								insertTXT += '</a>\n';
							}
						
						} else {
							for (j=0; j < wGallery_allPhotos_after [wGalleryAlbum].length; j++) {
								newUrl = wGallery_allPhotos_after [wGalleryAlbum][j];
								newUrl = newUrl.replace ('/images_after/','/images_after/originals/');
								insertTXT += '<a href="'+newUrl+'" rel="lightbox[roadtrip]">';
									if (wGallery_allPhotos_after [wGalleryAlbum][j] == object_img_src) {
										insertTXT += wTemp_lightbox_albumlist_Content;
									}
								insertTXT += '</a>\n';
							}
						}
	
	
						Gallery_Div_tag.innerHTML = insertTXT;
						// initLightbox();
						myLightbox.updateImageList();
					}
				}
	
			}
		}

	/*
	*										end of logged
	*/
	}
}




/* ************************************************
*
*										BUG 
*						onmousedown="dragStart(event, 'thumbs_01')" 
*				if is not logged return a error because this function is part of the CPanel
*
*  ************************************************/
/*
*			If the user is logged do not show effects
*/
var Logged = '';
if ( Logged == '') {
	function dragStart(a, b) {}
}

