
/* ---------------------------------------------------------------------------------------
swapWindowPhoto(group,id,number_of_items) - display photo in a window by photo id
IMPORTANT	: the function requires that the elements will have an ID tag in the form of: '<group_number>'
FOR EXAMPLE : <hadmaya_1>, <hadmaya_2>, <hadmaya_3>....

For the calling element will be highlighted place an ID in the form '<calling_group_number>'
And create a class with the string: '_selected'  at the end for the highlight.

FOR EXAMPLE : <calling_hadmaya_1>, <calling_hadmaya_2>, <calling_hadmaya_3>....

parameters	:
	group				-	A string representing a group of photos
	id					-	A string representing a unique identifier for a single photo
	number_of_items		-	Numeric value representing the number of photos in the collection
------------------------------------------------------------------------------------------
*/
function swapWindowPhoto(group,id,number_of_items)
{	
	if (!id || !group) return; // exit
	try 
	{
		for (var i=1;i<=number_of_items;i++)
		{	
			if (document.all(group+"_"+i))
			{
				var obj				= document.all(group+"_"+i);
				var objTitle		= document.all("title_"+group+"_"+i);
				var callingElement	= document.all("calling_"+group+"_"+i);
				if (i==id)
				{
					obj.style.display="inline";
					if (objTitle) objTitle.style.display="inline";
					// highlight the calling element
					callingElement.className = (callingElement.className)+"_selected";
				}					
				else
				{
					obj.style.display="none";
					if (objTitle) objTitle.style.display="none";
					// dim all calling element
					callingElement.className = (callingElement.className).replace("_selected","");
				}
			}
		}
	} catch(e){}
}

/* ---------------------------------------------------------------------------------------
swapWindowPhotoDir(group,direction,number_of_items) - swap photos in a window by left and right arrows
IMPORTANT	: the function requires that the elements will have an ID tag in the form of: <group_number>
FOR EXAMPLE : <hadmaya_1>, <hadmaya_2>, <hadmaya_3>....

parameters	:
	group		- A string representing a group of photos
	direction	- A string representing the sequence direction. Must be "up" or "down".
				  The function will go over the group and display the next or previous image in sequence.
	number_of_items - Numeric value represting the numebr of photos in the collection
------------------------------------------------------------------------------------------
*/
function swapWindowPhotoDir(group,direction,number_of_items)
{	
	if (!group|| !direction) return; // exit
	if (direction!="up" && direction!="down") return; // exit
	try 
	{
		for (var i=1;i<=number_of_items;i++)
		{	
			if (document.all(group+"_"+i))
			{
				var obj = document.all(group+"_"+i);
				var objTitle		= document.all("title_"+group+"_"+i);
				var callingElement = document.all("calling_"+group+"_"+i);
				// search for currently displayed image and set the ID of the image that will replace it
				if (obj.style.display=="inline")
				{
					var displayID = i;
					if (direction=="up")
					{
						if (i==number_of_items) displayID = 1;
						else	  displayID++;
					}
					if (direction=="down")	
					{
						if (i==1) displayID = number_of_items;
						else	  displayID--;
					}	
				}
				// hide all images
				obj.style.display="none";
				if (objTitle) objTitle.style.display="none";
				
				// dim all calling elements
				callingElement.className = (callingElement.className).replace("_selected","");
			}
		}
		// display the image with displayID 
		document.all(group+"_"+displayID).style.display="inline";
		if (objTitle) document.all("title_"+group+"_"+displayID).style.display="inline";
		// highlight the calling element
		document.all("calling_"+group+"_"+displayID).className = (callingElement.className)+"_selected";
	} catch(e){}
}


/* ---------------------------------------------------------------------------------------
swapDisplay(group,id) - swap the display of an element and it's corrosponding group.
						The function will hide/display the element with the specified <id>		
						The function will hide all elements in a specified <group>
parameters	:
	group		- A string representing a group of elements
	id			- A string representing an element's id. 
------------------------------------------------------------------------------------------
*/
function swapDisplay(group,id)
{	
	if (!group || !id) return;
	// flip the visibility state of the specified element
	var obj = document.all(id);
	obj.style.display=(obj.style.display=="none")?"inline":"none";
	var objState = obj.style.display;
	
	// flip all other elements in the specified group accordingly		
	var i=0;
	while (document.all(group+"_"+i) && i<10) // limit iterations to prevent infinite
	{
		if (group+"_"+i != id)
		{
			var otherGroupObj = document.all(group+"_"+i);
			
			otherGroupObj.style.display="none";
		}
		i++; // increament
	}
}


/* ---------------------------------------------------------------------------------------
swapWorks(group,id) -	swap the display of an element and it's corrosponding group.
					-	The function will hide/display the element with the specified <id>		
					-	The function will hide all elements in a specified <group>
					-	The icon of the calling element will be replaced
					-	The text title of the containing window will be changed
parameters	:
	group		- A string representing a group of elements
	id			- A string representing an element's id. 
------------------------------------------------------------------------------------------
*/
function swapWorks(group,id)
{	
	if (!id) return;
	
	// flip the visibility state of the specified element
	var obj			= document.all(id);
	obj.style.display=(obj.style.display=="none")?"inline":"none";
	// swap Icon
	var objIcon		= document.all(id+"_icon");
	objIcon.src=((objIcon.src).indexOf("_on.gif")>-1)?(objIcon.src).replace(/_on.gif/gi,"_off.gif"):(objIcon.src).replace(/_off.gif/gi,"_on.gif");
	
	// flip all other elements in the specified group accordingly		
	var i=0;
	while (document.all(group+"_"+i) && i<10) // limit iterations to prevent infinite
	{
		if (group+"_"+i != id)
		{
			var otherGroupObj = document.all(group+"_"+i);
			otherGroupObj.style.display="none";
			// swap Icon
			var objIcon		= document.all(otherGroupObj.id+"_icon");
			objIcon.src=(objIcon.src).replace(/_on.gif/gi,"_off.gif");
		}
		i++; // increament
	}	
}



/* ---------------------------------------------------------------------------------------
swapCityWorks()		-	swap the display of the select city window (path_works template)
					-	The function will hide/display the content of the window accroding
						to the given city ID.
						The function will also display/hide the dots on the map
parameters:
			id		-   A unique String representing a city code 
			title	-	The city name
------------------------------------------------------------------------------------------
*/
function swapCityWorks(id,title)
{
	if (!id || !title || id==0) return;
	try
	{
		// the window's opening content 
		var initialWorkWin = document.all("initialCityWorks");
		// the window's title
		var worksTitle = document.all("comboCityName");
		
		
		// change the window's title and hide the initial text
		if (initialWorkWin && worksTitle)
		{
			initialWorkWin.style.display="none";	
			worksTitle.innerText = title;
		}

		// display only the spcified city's list of works
		var divs = document.all.tags("div");
		for (var i=0;i<divs.length;i++)
		{
			if ((divs[i].id).indexOf("cityworks_")>-1)
			{
				if ((divs[i].id).indexOf("cityworks_"+id)>-1) 
				{	
					divs[i].style.display = "inline";
				} else {
					divs[i].style.display = "none";
				}
			}
		}

		// display the city's icons on the map
		var imgs = document.all.tags("img");
		for (var i=0;i<imgs.length;i++)
		{
			if ((imgs[i].id).indexOf("dot_")>-1)
			{
				if ((imgs[i].id).indexOf("dot_"+id)>-1) 
				{	
					imgs[i].style.display = "inline";
				} else {
					imgs[i].style.display = "none";
				}
			}
		}
	} catch(e){}
}

/*
citiesMap(cityCode)	 - Displays a specified city's description.

parameters:
		cityCode - A string representing the city document's doc_id

The function uses the specified city code to display text already available locally
in the page. (some local array storing the cities descriptions)
In this case the descriptions are stored in <cities> array

*/
function citiesMap(cityCode)
{	
	if (!cityCode) return;

	if (document.all('title_'+cityCode))
		document.all('cities_map_title').innerHTML = document.all('title_'+cityCode).innerText;
	
	if (document.all('text_'+cityCode))
		document.all('cities_map_text').innerHTML = document.all('text_'+cityCode).innerText;
}


/*
displaySideImage(imgSrc) - Displays a specified image in a popup window

parameters:
		imgSrc - A string representing the image's src 
*/

function displaySideImage(imgSrc, imgTitle)
{
	if (!imgSrc) return;
	var name		=	"sideImagePopup";
	var parameters	=	"fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,left=100,top=100";

window.open("../includes/windowparts/popup.asp?imgSrc="+imgSrc+"&imgTitle="+imgTitle, name, parameters)
}


function swapGalleryByCity(id,title)
{	
	alert("id="+id+"\ntitle="+title);
}