// defined variables in asp function CreateJSArrayofPropertyInfo in gallery-functions.asp

function PropertySwap(intIndex){

	// set current property id for room swap function
	intProperty=intIndex
	
	// accommodate array starting at position 0
	intIndex=intIndex-1

	// set title and intro text for selected property
	document.getElementById('propertyheader').innerHTML =propertyHeaderArray[intIndex] ;
	document.getElementById('propertyintro').innerHTML =propertyIntroArray[intIndex];
		
		// Loop through tabs and set selected
	var intTabIndex=1
	var intTempIndex=intIndex+1
	while (intTabIndex<=eval(propertycount)){
	if (intTempIndex==intTabIndex) {
		// index at selected tab then change class
		document.getElementById('property'+intTabIndex).className = "tab selectedtab";
		}
		else{
		// change to turned off
		document.getElementById('property'+intTabIndex).className = "tab";
		}
	intTabIndex=intTabIndex+1;
	}
	// change main image
	var MainImageID=propertyIDArray[eval(intIndex)]
	var tempRoomIDArray=eval('ActiveRoomIDsDiv'+MainImageID+';');
	if (tempRoomIDArray.length==0){
		
	    document.getElementById('MainGalleryImage').src="images/panels/awaiting-image.gif"	
		document.getElementById('MainGalleryImage').alt=""
	    document.getElementById('MainGalleryImage').title=""
		document.getElementById('photobox').innerHTML =""
		
	}
	else{
	var RoomIDIndex=eval('ActiveRoomIDsDiv'+MainImageID+'[0];')
	var MainImageRoomID=eval('MainImageIDsDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')	
	var MainImageExtension=eval('MainImageDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')
	var MainImageAltTag=eval('MainImageAltTagsDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')
	document.getElementById('MainGalleryImage').src="images/accommodation/accommodation_"+MainImageID+"_sub_lrg_"+MainImageRoomID+"."+MainImageExtension;
	document.getElementById('MainGalleryImage').alt=MainImageAltTag;
	document.getElementById('MainGalleryImage').title=MainImageAltTag;
		// change thumbnails
			
	var RoomID=(eval('ActiveRoomIDsDiv'+MainImageID+'[0];')-1)

	ThumbnailSwap(MainImageID,RoomID);
	//ThumbnailSwap(MainImageRoomID,(SelectedRoomID-1));
	}
	// change floor plan link
	if (FloorPlansArray[intIndex] != ''){
		document.getElementById('floorplans').innerHTML='<a href="javascript:FloorPlanSwap(\''+ FloorPlansArray[intIndex] + '\');">Floor Plans</a>';}
	else{
		document.getElementById('floorplans').innerHTML='';}

		
	// change threesixty link
	if (eval(ThreeSixtyArray[intIndex]!='')){
		document.getElementById('threesixty').innerHTML="<a href='"+ThreeSixtyArray[intIndex]+"' target='_blank'><img src='images/panels/gallery/360-degree-view.png' width='66' height='55' alt='360 degree view' title='360 degree view' /></a>"}
	else{
		document.getElementById('threesixty').innerHTML=''
		}
		//write out actual tabs for this property
		document.getElementById('roomtypesouter').innerHTML=propertyTabArray[intIndex];


	
}
function RoomSwap(intIndex,intMax){
	var strLeft, strRight, i

		// set current room id for property swap function
		intRoom=intIndex

		// change value of left and right navigation
		if (intIndex==intMax){
		strLeft='javascript:RoomSwap('+(intMax-1)+','+intMax+');'
		strRight='javascript:RoomSwap(1,'+intMax+');'
		}
		else if (intIndex==1){
		strLeft='javascript:RoomSwap('+intMax+','+intMax+');'
		strRight='javascript:RoomSwap(2,'+intMax+');'
		}
		else{
		strLeft='javascript:RoomSwap('+(intIndex-1)+','+intMax+');'
		strRight='javascript:RoomSwap('+(intIndex+1)+','+intMax+');'
		}
		document.getElementById('scroll-left').href = strLeft
		document.getElementById('scroll-right').href = strRight

		// change main image
		var MainImageID=propertyIDArray[eval(intProperty-1)]
		var RoomIDIndex=eval('ActiveRoomIDsDiv'+MainImageID+'['+eval(intIndex-1)+'];')
		var MainImageRoomID=eval('MainImageIDsDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')	
		var MainImageExtension=eval('MainImageDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')
		var MainImageAltTag=eval('MainImageAltTagsDiv'+MainImageID+'['+eval(RoomIDIndex-1)+'][0];')
		//alert("images/accommodation/accommodation_"+MainImageID+"_sub_lrg_"+MainImageRoomID+"."+MainImageExtension+"");
			if ((MainImageID !='')&&(MainImageRoomID !='')&&(MainImageExtension !='')){
	document.getElementById('MainGalleryImage').src="images/accommodation/accommodation_"+MainImageID+"_sub_lrg_"+MainImageRoomID+"."+MainImageExtension+"";}
	else{
		document.getElementById('MainGalleryImage').src="images/panels/awaiting-image.gif"	
	}
		
		document.getElementById('MainGalleryImage').alt=MainImageAltTag;
		document.getElementById('MainGalleryImage').name=MainImageAltTag;
		document.getElementById('MainGalleryImage').title=MainImageAltTag;



	//document.getElementById('MainGalleryImage').src="images/accommodation/accommodation_"+propertyIDArray[eval(intProperty-1)]+"_sub_lrg_"+RoomsIDArray[eval(intIndex-1)]+"."+strExt+"";

		// get actual room index value and not just one for valid rooms on this property


		
		// sort tabs, so current one is selected
		for (var i=1;i<=intMax;i++)
		{
	
			if (i==intIndex){
				document.getElementById('room'+i).className = "room selected";
					}
				else{
				document.getElementById('room'+i).className = "room";
				}

		}
		
		// change thumbnails
		var SelectedRoomID=eval('ActiveRoomIDsDiv'+MainImageID+'['+eval(intIndex-1)+'];')
		//var ThumbnailRoomID =eval('MainImageIDsDiv'+MainImageID+'['+eval(SelectedRoomID-1)+'];')
		//alert(SelectedRoomID);
		ThumbnailSwap(MainImageID,(SelectedRoomID-1));
}

function ThumbnailClick(intArticleID,intAccommodationID,strExt){
	// swaps out current main image for thumbnail
		if ((intArticleID !='')&&(intAccommodationID !='')&&(strExt !='')){
	document.getElementById('MainGalleryImage').src="images/accommodation/accommodation_"+intArticleID+"_sub_lrg_"+intAccommodationID+"."+strExt+"";}
	else{
		document.getElementById('MainGalleryImage').src="images/panels/awaiting-image.gif"	
	}
	
	
	
	//alert("images/accommodation/accommodation_"+intArticleID+"_sub_lrg_"+intAccommodationID+"."+strExt+"");
}

function ThumbnailSwap(intAccommodationID,intAccommodationTypeID){
	// swaps out thumbnails
	document.getElementById('photobox').innerHTML = eval('ThumbnailDiv'+intAccommodationID+'['+(intAccommodationTypeID)+'];')

}

function FloorPlanSwap(strImagePath){
	// swaps out floor plan
	if (strImagePath !=''){
		document.getElementById('MainGalleryImage').src=strImagePath;}
	else{
		document.getElementById('MainGalleryImage').src="images/panels/awaiting-image.gif"	
	}
	

}