// -----------------------------------------------------------------------------------
//
//	Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com
//	3/31/06
/* ----------
	*	Additional Development with Pagination 
	*	done by Palani
	*	Aug 2008 , Chennai , Tamil Nadu , India.
*/

//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects	
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	Lightbox Class Declaration
	- initialize()
	- start()
	- changeImage()
	- resizeImageContainer()
	- showImage()
	- updateDetails()
	- updateNav()
	- enableKeyboardNav()
	- disableKeyboardNav()
	- keyboardAction()
	- preloadNeighborImages()
	- end()
	
	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- pause()
	- initLightbox()
	
	Function Calls
	- addLoadEvent(initLightbox)
	
*/
// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage = "/images/loading.gif";	
var whiteSapceImage = "/images/white_spacer.gif";

/*var fileBottomNavCloseImage = "/images/gallery/images/closelabel.gif";
var fileBottomNavNextImage = "/images/gallery/images/nextlabel.gif";
var fileBottomNavPreviousImage = "/images/gallery/images/prevlabel.gif";*/
/*
var imageCloseButton = "/images/gallery/images/Closesmall.gif";
var imageForwardButton = "/images/gallery/images/forwardsmall1.gif";
var imageBackButton = "/images/gallery/images/rewinnd.gif";   
*/

// senthil image
var imageCloseButton = "/images/closenew.gif";
//var imageForwardButton = "/images/nextnew.gif";
//var imageBackButton = "/images/previousnew.gif";   

//var imageForwardButtonActive = "images/pgnav_right_active.gif"; 
//var imageBackwardButtonActive = "images/pgnav_left_active.gif";
var imageForwardButtonActive = "images/pgnav_right_active.gif"; 
var imageForwardButtonInActive = "images/pgnav_right_inactive.gif";
var imageBackwardButtonActive = "images/pgnav_left_active.gif";
var imageBackwardButtonInActive = "images/pgnav_left_inactive.gif";

var resizeSpeed = 7;	// controls the speed of the image resizing (1=slowest and 10=fastest)

var borderSize = 10;	//if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var imageArrayNew = new Array;
var fileArray = new Array;

var second = new Array;
var pageWiseImageArray = new Array;
var fileArray = new Array;
//var activeImageArray= new Array;
var paginationArray = new Array;

var nextPageImageArray = new Array;
var previousPageImageArray = new Array;
var nextPage= 0;
var previousPage= -1;
var allImageArray = new Array;
var previousPageFlag = false;


var activeImage;
var dyIncreaseWidth = 0;
var dyIncreaseHeight = 0;

if(resizeSpeed > 10){ resizeSpeed = 10;}
if(resizeSpeed < 1){ resizeSpeed = 1;}
resizeDuration = (11 - resizeSpeed) * 0.15;
// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	//alert("  95  Image preloder  with ==  "+w);

	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
	//	alert(" 101  Image preloder  Height  == "+h);

   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

function SubmitUpload(){
	
		var allowed="JPG,JPEG,TIFF,PNG,GIF,BMP";
		var file=document.getElementById("fileUpload").value;
		var ext=file.substring(file.lastIndexOf('.')+1,file.length);

		try{
		if(file!=null && Trim(file).length>0){
			if(allowed.indexOf(ext.toUpperCase())!=-1){
				var obj = document.getElementById('UploadHref'); 
				if(obj != null) 
				{
					obj.removeAttribute("href");
					obj.style.color="gray";
				}
				document.getElementById("iframeName").value=editorName;
				document.getElementById('UploadImagesForm').submit();

			}else{
				alert(uploadImages.UploadWarning);
				document.forms[2].reset();
			}
		}else{
				alert(uploadImages.UploadWarning);
				document.forms[2].reset();
		}
		}catch(e1)
		{
				alert(uploadImages.UploadWarning);
				document.forms[2].reset();
		}


}
function imageLoadingToRichText(imageName, richTextBoxName) // palani
{
		//alert(" Sikkandar4 imageLoadingProcess  Image Names  ====  "+imageName.name+"  Rich Text Name =="+richTextBoxName.id);
		LoadsImage(imageName.name, richTextBoxName);
		myLightbox.end();
	}

function nextPageLink(allImageArays, nextPageImageArrays)
{
//	alert(" This is a next page links  nextPage size ==="+nextPageImageArrays.length+"  NEXT PAGE COUNT   === "+nextPage);
	myLightbox.nextPageImageInitializePagination(allImageArays, nextPageImageArrays);  // sikk method 
	return false;
}

function previousPageLink()
{
		myLightbox.previousPageInitializePagination();
}
// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//

var Lightbox = Class.create();
Lightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {	
		 imageArray = new Array;
		 imageArrayNew = new Array;
		 fileArray = new Array;

		 second = new Array;
		 pageWiseImageArray = new Array;
		 fileArray = new Array;
		//var activeImageArray= new Array;
		 paginationArray = new Array;

		 nextPageImageArray = new Array;
		 previousPageImageArray = new Array;
		 nextPage= 0;
		 previousPage= -1;
		 allImageArray = new Array;
		 previousPageFlag = false;


		 activeImage;
		 dyIncreaseWidth = 0;
		 dyIncreaseHeight = 0;

	//	alert(" Initialize  CALLED  ");
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('name'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('imagegallery'))){
				anchor.onclick = function () {
					myLightbox.start(this);
					return false;
					}
			}
		}

		// The rest of this code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<img id="lightboxImage">
		//				<div style="" id="hoverNav">
		//					<a href="#" id="prevLink"></a>
		//					<a href="#" id="nextLink"></a>
		//				</div>
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="caption"></span>
		//					<span id="numberDisplay"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">
		//						<img src="images/close.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


	var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
	//	objOverlay.onclick = function() { myLightbox.end(); return false; }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);
	
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		//objImageContainer.setAttribute('width','100');
		//objImageContainer.setAttribute('height','80');

	//	objImageContainer.setAttribute('name','imageContainer');
		objImageContainer.style.marginLeft = 'auto';
		objImageContainer.style.marginRight = 'auto';
		objOuterImageContainer.appendChild(objImageContainer);
		

		imageArrayNew = document.getElementsByName('ImageGallery');  // pala
		allImageArray = document.getElementsByName('ImageGallery');  // pala
		// alert("  Total Images size   ==="+imageArrayNew.length);

		var imageCloseButtonText = document.getElementById('imgCloseButtons').value; 

		var editMode=null;
		var serveyIds =null;
		if(document.getElementById('editSurveys') != null){
				editMode = document.getElementById('editSurveys').value;
			if(document.forms[0].surveyId != null){
				serveyIds = document.forms[0].surveyId.value
			}
		}
		
		
//--------  calculate the no of pages in the pagination ------ begin ---------------------------------------------------------		
		var pagenationSize =0;
		var imagesPerPage = 20;
		
		if(imageArrayNew.length > imagesPerPage )
		{
			if((imageArrayNew.length % imagesPerPage) == 0)
			{
				pagenationSize = imageArrayNew.length / imagesPerPage ;
			} else {
				var pageSize = Math.floor(imageArrayNew.length / imagesPerPage);
				pagenationSize = pageSize + 1;
			} 
		} else {
			pagenationSize = 1;
		}
	//	alert(" Total Images size =="+imageArrayNew.length+" Pagination Size  =="+pagenationSize);		

	// --------  separate the image array pagewise 	 ----------------------------------------------------------------

	
	var count = 0;

	if(imageArrayNew.length > 0)
		{
			for(j=0;j<imageArrayNew.length; j++)
			{
				if((imagesPerPage-1) == count)
				{
					pageWiseImageArray.push(imageArrayNew[j]);
					paginationArray.push(pageWiseImageArray);
					count = 0;
					pageWiseImageArray = new Array;
				} else
				{
					pageWiseImageArray.push(imageArrayNew[j]);
					count++;
				}
			}
			if((count >0) && (count <= 20))
			{
				paginationArray.push(pageWiseImageArray);
				pageWiseImageArray = new Array;
			}
			
		}

 /*
	if(imageArrayNew.length > 0)
	{
		for(j=0;j<imageArrayNew.length; j++)
		{
			if((imagesPerPage-1) == count)
			{
				
				pageWiseImageArray.push(imageArrayNew[j]);
				paginationArray.push(pageWiseImageArray);
				count = 0;
				pageWiseImageArray = new Array;
			} else
			{
				pageWiseImageArray.push(imageArrayNew[j]);
				count++;
			}
		}
		if(count <= 20 )
		{
			paginationArray.push(pageWiseImageArray);
		}

	} */
//----------------------- All Images loading process -----------------------------------------------------------------


//alert("CURRENTLY LOADING  Image Array Length =="+imageArrayNew.length);
	for(i=0;i<imageArrayNew.length;i++) 
	{
			if(window.opera)
			{
				var imageObjLink = document.createElement('a');
	            var imageObjImages = document.createElement('img');
				
				imageObjLink.setAttribute('href','#');
				imageObjLink.setAttribute('name',imageArrayNew[i]);
			//	imageObjLink.onclick=function() { imageLoadingToRichText(this, richTextBoxName); }
				//imageObjLink.onclick=function() { imageLoadingToRichText(this, document.getElementById('frameName_RTE')); }
					
				imageObjImages.setAttribute('id','lightboxImage'+i);
				imageObjImages.setAttribute('name',imageArrayNew[i]);
			//	imageObjImages.setAttribute('name','lightboxImage'+i);
				imageObjImages.className='imagesized';

				imageObjImages.setAttribute('width','100');
				imageObjImages.setAttribute('height','80');
				imageObjImages.setAttribute('border','1');
				imageObjImages.setAttribute('align','top');
				imageObjImages.setAttribute('hspace','5');
				imageObjImages.setAttribute('vspace','5');
			} else {
				var imageObjLink = document.createElement('a');
				var imageObjImages = document.createElement('img');
		        

					imageObjLink.setAttribute('href','#');
					imageObjLink.setAttribute('id',imageArrayNew[i]);
					imageObjLink.setAttribute('name',imageArrayNew[i]);
				//	imageObjLink.setAttribute('width','90');
				//	imageObjLink.setAttribute('height','70');
					imageObjLink.setAttribute('name',imageArrayNew[i]);
			

				//	imageObjLink.onclick=function() {  imageLoadingToRichText(this, richTextBoxName); }
				//	imageObjLink.onclick=function() {  imageLoadingToRichText(this, document.getElementById('frameName_RTE')); }
				
					imageObjImages.setAttribute('id','lightboxImage'+i);
					imageObjImages.setAttribute('name',imageArrayNew[i]);
					//imageObjImages.setAttribute('name','lightboxImage'+i);
					imageObjImages.setAttribute('class','default');
					//if(window.opera){
					//	alert(" Inside widow opera  ");
					//imageObjImages.setAttribute('width','100');
					//imageObjImages.setAttribute('height','80');
					//} else {
					imageObjImages.setAttribute('width','100');
					imageObjImages.setAttribute('height','80');
					//}
					imageObjImages.setAttribute('border','1');
					imageObjImages.setAttribute('align','top');
					imageObjImages.setAttribute('hspace','5');
					imageObjImages.setAttribute('vspace','5');
				}
			imageObjLink.appendChild(imageObjImages);
			objImageContainer.appendChild(imageObjLink);		
     	}
	
		var whiteSpaceImgLink = document.createElement("div");
		whiteSpaceImgLink.setAttribute('id','whiteSpaceImage');
		var whiteSpaceImage  = document.createElement("img");
		whiteSpaceImage.setAttribute('src', whiteSapceImage);  
		whiteSpaceImage.setAttribute('width', '20');  
		whiteSpaceImage.setAttribute('height', '20');  

		whiteSpaceImgLink.appendChild(whiteSpaceImage);	
		objImageContainer.appendChild(whiteSpaceImgLink);	
		
// ------------------- close img part begin -------------- 
		var closeImgLinkNav = document.createElement("div");
		closeImgLinkNav.setAttribute('id','closeImgLinkNav');
	

//----------------  Previous Image  Link begin  -----------------------
	//	var previousImgLinkDiv = document.createElement("div");
	//	previousImgLinkDiv.setAttribute('id','previousImgLinkDiv');
var forPrev=false;
	var previousImgLink = document.createElement("a");
		previousImgLink.setAttribute('id','previousImgLink');
		previousImgLink.className='previousImg';
		previousImgLink.setAttribute('href','#');
		var previousImg = document.createElement("img");
		previousImg.setAttribute('id', 'imageBackwardButtonInActive1');  
		previousImg.setAttribute("align","top");
        
//		if(nextPage > 0)
		if(forPrev || (nextPage>0))
		{
			        
			//alert("PREV IF"+nextPage);
			var previousImg1=document.getElementById('imageBackwardButtonInActive1');
			var previousImgLink1=document.getElementById('previousImgLink')
				previousImg1.src=imageBackwardButtonActive;
				previousImg.src = previousImg1;
				previousImg.setAttribute('title',uploadImages.Prev);
			//alert(previousImgLink1)
			previousImg.onclick=function() 
			{
				//alert("Prev Onclick : "+nextPage);
				previousPage--;
				if((nextPage < 0 ) || (nextPage == 0))
				{
					//alert(noMoreImagesToViewPreviousPage);
					        
					previousPageFlag = false;
					return false;
				} else {
					//					alert("  Previous  SELECTION  nextPage =="+nextPage+"  PAGE ARR SIZE =="+paginationArray.length+"    previousPage  =="+previousPage);
					previousPageFlag = true;
					previousPageLink(paginationArray[nextPage]); 
				//	alert("  previousPage  =="+previousPage+"  PAGE ARR LEN  === "+(paginationArray.length-1)+"  Next Page =="+nextPage);
					if(nextPage < 1)
					{
					//	alert("  previous Button InActive   Next Page =="+nextPage);

						var previousImg2=document.getElementById('imageBackwardButtonInActive1');
						//var previousImgLink1=document.getElementById('previousImgLink')
						previousImg2.setAttribute('title','');
						previousImg2.src = imageBackwardButtonInActive;
						previousImg.src = previousImg2;
					}

					var nextImgLink3=document.getElementById('imageForwardButtonActive1');
					//var previousImgLink1=document.getElementById('previousImgLink')
					nextImgLink3.src = imageForwardButtonActive;
					return false; 
				}
			}
			previousImgLink.appendChild(previousImg);		
			previousImgLink.className = 'previousImg';
			closeImgLinkNav.appendChild(previousImgLink);
		} else {
		//alert("PREV ELSE");
		//	alert(" Directly back button in actiove  nextPage  =="+	nextPage);
			previousImg.setAttribute('src', imageBackwardButtonInActive);  


			previousImg.onclick=function() 
			{								
				previousPage--;
				if((nextPage < 0 ) || (nextPage == 0))
				{
				//alert(noMoreImagesToViewPreviousPage);
					previousPageFlag = false;
					return false;
				} else {
						previousImg.setAttribute('title',uploadImages.Prev);
//					alert("  Previous  SELECTION  nextPage =="+nextPage+"  PAGE ARR SIZE =="+paginationArray.length+"    previousPage  =="+previousPage);
					previousPageFlag = true;
					previousPageLink(paginationArray[nextPage]); 
				//	alert("  previousPage  =="+previousPage+"  PAGE ARR LEN  === "+(paginationArray.length-1)+"  Next Page =="+nextPage);
					if(nextPage < 1)
					{
			    		var previousImg2=document.getElementById('imageBackwardButtonInActive1');
						//var previousImgLink1=document.getElementById('previousImgLink')
						previousImg2.src = imageBackwardButtonInActive;
						previousImg.setAttribute('title','');
						//previousImg.src = previousImg2;
					}
					if(nextPage < 1 && previousImg.getAttribute('title') == '')
					{
				                  previousImg.removeAttribute('title');
					}
					var nextImgLink3=document.getElementById('imageForwardButtonActive1');
					//var previousImgLink1=document.getElementById('previousImgLink')
					nextImgLink3.src = imageForwardButtonActive;
					nextImg.setAttribute('title',uploadImages.Next);
					return false; 
				}
			}


			}
			previousImgLink.appendChild(previousImg);		
			previousImgLink.className = 'previousImg';
			closeImgLinkNav.appendChild(previousImgLink);
	//}
	//	previousImgLinkDiv.appendChild(previousImgLink);
	//	objImageContainer.appendChild(previousImgLinkDiv);

	//----------------  Next Image Link begin  -----------------------

	//	var nextImgLinkNav = document.createElement("div");
	//	nextImgLinkNav.setAttribute('id','nextImgLinkNav');

	var nextImgLink = document.createElement("a");
		nextImgLink.setAttribute('id','nextImgLink');
		nextImgLink.className='nextImg';
		nextImgLink.setAttribute('href','#');

		var nextImg = document.createElement("img");
		nextImg.setAttribute('id', "imageForwardButtonActive1");
		nextImg.setAttribute("align","top");
		//	nextImg.setAttribute('src', fileBottomNavNextImage);  
		if((allImageArray.length > 20 ))
		{
			nextImg.setAttribute('title',uploadImages.Next);
			nextImg.setAttribute('src', imageForwardButtonActive);
			nextImg.onclick=function()
			{
				forPrev=true;
				var previousImgID=document.getElementById('imageBackwardButtonInActive1');
				if(previousImgID!=null){
					previousImg.setAttribute('title',uploadImages.Prev);
					previousImgID.src = imageBackwardButtonActive;
				}
				if(previousPage = -1) previousPage = 0;
				if((paginationArray.length - 1) == nextPage)
				{
					//	alert(noMoreImagesToViewNextPage);
					return false;
				}
				nextPage++;
				if(paginationArray.length > nextPage)
				{
					//alert("   nextPage  imageForwardButtonInActive  ========== >>"+nextPage+"  ARR size ===>> "+(paginationArray[nextPage].length)+" PAGI ARR SIZE  =="+paginationArray.length);
					if(paginationArray.length - 1 == nextPage)
					{
						
						var nextImgLink2=document.getElementById('imageForwardButtonActive1');
						nextImgLink2.src = imageForwardButtonInActive;
					    nextImg.setAttribute('title','');
					}
					previousPage++;
					nextPageLink(allImageArray, paginationArray[nextPage]); 
				} /* else {
					if(nextPage < 0){
						alert("   nextPage  2 ========== >>"+nextPage+"  ARR size ===>> "+(paginationArray[nextPage].length));
						nextPageLink(allImageArray,paginationArray[0]); 
					}
					if(nextPage > 0)
					{
						nextPage--;
						alert("   nextPage  3 ========== >>"+nextPage+"  ARR size ===>> "+(paginationArray[nextPage].length));
						nextPageLink(allImageArray,paginationArray[nextPage]); 
					} 	
				} */
				return false;
			}
		} else {
				nextImg.setAttribute('src', imageForwardButtonInActive);
			}
	
			nextImgLink.appendChild(nextImg);		
			nextImgLink.className = 'nextImg';
			closeImgLinkNav.appendChild(nextImgLink);

//-------- Close Image Link Begin -------------------------------
/*
		var closeImgLink = document.createElement("a");
		closeImgLink.setAttribute('id','bottomNavClose');
		closeImgLink.className='closeImages';
		closeImgLink.setAttribute('href','#');
		closeImgLink.onclick = function() { myLightbox.end(); return false; }

		var closeImg = document.createElement("img");
	//	closeImg.setAttribute('src', fileBottomNavCloseImage);  
		closeImg.setAttribute('src', imageCloseButton);  
		closeImg.onclick=function() { myLightbox.end(); return false; }
		closeImgLink.appendChild(closeImg);		
		closeImgLinkNav.className = 'closeImages';
		closeImgLinkNav.appendChild(closeImgLink);
	*/

	//------- close image link add to span --------------------------------------------------
	var closeImgSpan = document.createElement("span");
		closeImgSpan.setAttribute('id','closeImgSpan');
		closeImgSpan.setAttribute('align','middle');
		//alert("Length"+imageCloseButtonText.length);
		if(isIE)
		{
			if(imageCloseButtonText.length<=6)
			{
				closeImgSpan.className='horizontal_image_gallary_close_button_inIE'; 
			}else if((imageCloseButtonText.length>6) && (imageCloseButtonText.length<=11)){
				closeImgSpan.className='horizontal_medium_image_galary_close_button_inIE';
			}
		}
		if(isMozilla)
		{
			if(imageCloseButtonText.length<=5)
			{
				closeImgSpan.className='horizontal_small_image_gallary_close_button_InMozilla'; 
			}else if((imageCloseButtonText.length>5) && (imageCloseButtonText.length<=8)){
				closeImgSpan.className='horizontal_image_gallary_close_button_InMozilla';
			} else if((imageCloseButtonText.length>8) && (imageCloseButtonText.length<=11)){
				closeImgSpan.className='horizontal_medium_image_gallary_close_Button_InMozilla';
			}
		}
		if(isOpera)
		{
			if(imageCloseButtonText.length<=5)
			{
				closeImgSpan.className='horizontal_small_image_gallary_close_button_InOpera'; 
			}else if((imageCloseButtonText.length>5) && (imageCloseButtonText.length<=8)){
				closeImgSpan.className='horizontal_image_gallary_close_button_InOpera';
			}else if((imageCloseButtonText.length>8) && (imageCloseButtonText.length<=11)){
				closeImgSpan.className='horizontal_medium_close_image_gallary_button_InOpera';
			}
		}
		if(isSafari)
		{
			if(webkitVersion < 525 )
			{
				//alert("  Win Safari ");
				if(imageCloseButtonText.length<=5)
				{
					closeImgSpan.className='horizontal_small_image_gallary_close_button_In_win_Safari'; 
				}else if((imageCloseButtonText.length>5) && (imageCloseButtonText.length<=8)){
					closeImgSpan.className='horizontal_image_gallary_close_button_In_win_Safari';
				}else if((imageCloseButtonText.length>8) && (imageCloseButtonText.length<=11)){
					closeImgSpan.className='horizontal_medium_image_gallary_close_button_In_win_Safari';
				}
			} else {
				//	alert("  Mac Safari ");
				if(imageCloseButtonText.length<=5)
				{
					//alert("Length M1  "+imageCloseButtonText.length);
					closeImgSpan.className='horizontal_small_image_gallary_close_button_In_Mac_Safari'; 
				}else if((imageCloseButtonText.length>5) && (imageCloseButtonText.length<=8)){
					//alert("Length M2  "+imageCloseButtonText.length);
					closeImgSpan.className='horizontal_image_gallary_close_button_In_Mac_Safari';
					///alert("Length S3    "+imageCloseButtonText.length+"Classname   "+closeImgSpan.className);
				}else if((imageCloseButtonText.length>8) && (imageCloseButtonText.length<=11)){
					//alert("Length M3  "+imageCloseButtonText.length);
					closeImgSpan.className='horizontal_medium_image_gallary_close_button_In_Mac_Safari';
				}
			}
		}

		var closeImgLink = document.createElement("a");
		closeImgLink.setAttribute('id','bottomNavClose');
//		closeImgLink.className='closeImg';
		closeImgLink.setAttribute('href','#');
		closeImgLink.innerHTML=imageCloseButtonText;
		closeImgLink.onclick = function() { myLightbox.end(); return false; }
		closeImgSpan.appendChild(closeImgLink);
		
		closeImgLinkNav.appendChild(closeImgSpan);
		closeImgLinkNav.className='closeImages';
		closeImgLinkNav.setAttribute('valign', 'middle');


// --------  File Browse process -----------------------------------------------------
		objImageContainer.appendChild(closeImgLinkNav);

// --------  File Browse process -----------------------------------------------------
		

	//	objImageContainer.appendChild(closeImgLinkNav);
	//	previousImgLinkDiv.appendChild(nextImgLink);
	//	objImageContainer.appendChild(previousImgLinkDiv);
	//	objImageContainer.appendChild(closeImgLinkNav);
	//	objImageContainer.appendChild(nextImgLinkNav);
		var whiteSpaceImgLink1 = document.createElement("div");
		whiteSpaceImgLink1.setAttribute('id','whiteSpaceImage');
		var whiteSpaceImage1  = document.createElement("img");
		whiteSpaceImage1.setAttribute('src', whiteSapceImage);  
		whiteSpaceImage1.setAttribute('width', '20');  
		whiteSpaceImage1.setAttribute('height', '5'); 
		whiteSpaceImage1.setAttribute('align', 'left');  		

		whiteSpaceImgLink1.appendChild(whiteSpaceImage1);	
		objImageContainer.appendChild(whiteSpaceImgLink1);


//---------- Newly added end   --------------------

// ------- Add Browse Buttons  ----- Begins ------------------------------------ --------------------
/*
		var browseNewImage = document.createElement("div");
		browseNewImage.setAttribute('id','browse');
		objImageContainer.appendChild(browseNewImage);
*/
//		
//		var newFileObjects = document.createElement("input");
//		newFileObjects.setAttribute ('type', 'text');
//		newFileObjects.setAttribute ('id', 'text_box');
//		newFileObjects.setAttribute('size','29');
//		newFileObjects.setAttribute('maxlength','100');
//
/*		var newFileObjects = document.createElement("input");
		newFileObjects.setAttribute ('type', 'file');
		newFileObjects.setAttribute ('id', 'text_file');
		newFileObjects.setAttribute('size','40');
		newFileObjects.setAttribute('maxlength','100');





	//	newFileObjects.className ='input_field';
		//newFileObjects.setAttribute('href','#');
		closeImgLinkNav.appendChild(newFileObjects);


		newFileObjects.className ='input_field';
		//newFileObjects.setAttribute('href','#');
		browseNewImage.appendChild(newFileObjects);
*/
// --------- Add Browse Button Close  ----------- -----------------------------------------------------

//   Click here to image upload begin ---------------------------- 
	var theNewParagraph = document.createElement('p');
	objImageContainer.appendChild(theNewParagraph);

	var browseNewImage = document.createElement("div");
		browseNewImage.setAttribute('id','browse');
/*
		var uploadImgLink  = document.createElement("a");
		uploadImgLink.name='NewUpload';  
		//uploadImgLink.href='/UploadImages.fms?isFromGallery=yes';
		//uploadImgLink.innerHTML='Click here to upload new images';  
		
		uploadImgLink.className='blue_highlighted_text_new';
		
		uploadImgLink.onclick = function()
		{
			if(editMode != null && editMode=='YES')
			{
				
				
					myLightbox.end();
				//	uploadImgLink.href='isFromGallery=yes';

					save('ImageGal');
				
					uploadImgLink.href='/UploadImages.fms?isFromGallery=yes&editsave=No&surveyId='+serveyIds;
				
			
			} else {
				
				
					myLightbox.end();
				//	uploadImgLink.href='isFromGallery=yes';

					save('ImageGal');
				
					uploadImgLink.href='/UploadImages.fms?isFromGallery=yes';
				
			}
		}
		*/
		//objImageContainer.appendChild(uploadImgLink);





       
	
/*	
	var formName = document.createElement('form');
	
	
//		formName.method = 'post';
//		formName.action = '/SRVEditSurveySubmit.fms';
//		formName.enctype= 'multipart/form-data';
//		formName.name='SurveyForm';
//		formName.id='SurveyForm';
	
		formName.action = '/UploadImagesSubmit.fms';
		formName.method='post';
		formName.enctype= 'multipart/form-data';
		formName.name='UploadImagesForm';
		formName.id='UploadImagesForm';


	if(isIE){
		formName.className = 'browseButtonIE';
	} else {
		formName.className = 'browseButtonOtherBrowser';
	}
	
	// browseNewImage.appendChild(f);
//	objBody.appendChild(f);
	var fileInput = document.createElement('input');
	fileInput.setAttribute('type', 'file');
	fileInput.setAttribute('name', 'fileUpload');
	fileInput.setAttribute('id', 'fileUpload');
	fileInput.setAttribute('size','30');
	formName.appendChild(fileInput);

			var hideTream = document.createElement("input");
		hideTream.setAttribute ('type', 'hidden');
		hideTream.setAttribute ('name', 'TreamMet');
		hideTream.setAttribute ('id', 'TreamMet');
		hideTream.setAttribute ('value', 'Bila');

		formName.appendChild(hideTream);


		var submitObjects = document.createElement("input");
		submitObjects.setAttribute ('type', 'submit');
		submitObjects.setAttribute ('name', 'SubmitImage');
		submitObjects.setAttribute ('id', 'SubmitImage');
		submitObjects.setAttribute ('value', 'Submit');

//		submitObjects.setAttribute('width','80');

		submitObjects.onclick = function()
		{ 	
				document.getElementById('textAA').value=document.getElementById('browse').innerHTML ;
				return false;
*/
		/*	var allowed="JPG,JPEG,TIFF,PNG,GIF,BMP"; 
			var fileNames=document.getElementById("fileUpload").value;
		
			var ext=fileNames.substring(fileNames.lastIndexOf('.')+1,fileNames.length);
		//	alert(allowed+" : "+ext+" : "+allowed.indexOf(ext.toUpperCase())+" WHITE SPACE =="+isWhitespace(fileNames));
			if((!isWhitespace(fileNames)) && (allowed.indexOf(ext.toUpperCase())!=-1))
			{
				//document.getElementById('UploadImagesForm').submit();
				return false;
			} else {
				alert(formFieldValidation);
				return false;
			}	*/
//		}
//		formName.appendChild(submitObjects);

	var label=uploadImages.Upload;
	var button='    <table border="0" cellpadding="0" cellspacing="0" ><tr> <td><img src="/images/ButtonTop_save_large_right.gif"></td><td  nowrap valign="middle" background="/images/ButtonTop_save_large_middle.gif"><a id="UploadHref" class="tittle_but_brd"  style="cursor:pointer;cursor:hand" tabindex="0" href="javascript:SubmitUpload()">'+label+'</a></td><td><img src="/images/ButtonTop_save_large_left.gif"></td></tr></table>';

	browseNewImage.innerHTML = '<form target="hiddenframe" class="browseButtonOtherBrowser" id="UploadImagesForm"' 
	+'name="UploadImagesForm" enctype="multipart/form-data" method="post" action="/UploadImagesSubmit.fms"><table><tr><td><input size="30"'
	+'id="fileUpload" name="fileUpload" type="file"><input type="hidden" name="UploadInLightBox" id="UploadInLightBox"' 
	+'value="UploadInLightBox"><input type="hidden" name="iframeName" id="iframeName" value=""></td><td>'
	+button+'</td></tr></table><iframe name="hiddenframe" style="display:none" >Loading...</iframe>  </form>';

		//browseNewImage.appendChild(formName);
		//closeImgLinkNav.appendChild(formName);
		objImageContainer.appendChild(browseNewImage);



//-------------------  Image Browser Buttons  end --------------------------------------------





//  ----- click here to upload images ----- end ---------

		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);
		
		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);
	
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myLightbox.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','imageDataContainer');
		//objImageDataContainer.setAttribute('name','imageDataContainer');
		objImageDataContainer.className = 'clearfix';
		objLightbox.appendChild(objImageDataContainer);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);
	
		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','numberDisplay');
		objImageDetails.appendChild(objNumberDisplay);
		
		/*var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);
	
		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);*/
	},



	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {	
		
		var imgArray = document.getElementsByTagName("img");
			for (var j=0; j<imgArray.length; j++){
			if(imgArray[j].id.substring(0, 13)=="lightboxImage"){
			imageShowed = document.getElementById(imgArray[j].id);
			imageShowed.onclick=function() { 
				imageLoadingToRichText(this,document.getElementById(editorName)); 
				}

			}
			}
	
	//	document.getElementById("iframeName").value=editorName;

		hideSelectBoxes();
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		//Element.setHeight('overlay', arrayPageSize[1]);  
		Element.setHeight('overlay', arrayPageSize[1]);  // --------------  pala  -------------------
		new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// if image is NOT part of a set..
		if(nextPage == 0)
		{
			if((imageLink.getAttribute('rel') == 'lightbox')){
				// add single image to imageArray
				imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));			
			} else {
			// if image is part of a set..

				// loop through anchors, find other images in set, and add them to imageArray
				for (var i=0; i<anchors.length; i++){
					var anchor = anchors[i];
					if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
					}
				}
				imageArray.removeDuplicates();
				while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
			}
		} else {   
			imageArray.push(new Array(imageLink.getAttribute('href'), paginationArray[nextPage][0]));	

		}

		// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		Element.setTop('lightbox', lightboxTop);
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
		changeImage: function(imageNum) {	

	//alert("  842  ===  CHANGE IMAGE FUNCTION ----------- "+imageNum+"  NEXT PAGE  ===="+nextPage);
		activeImage = imageNum;	// update global var
		// hide elements during transition
		Element.show('loading');
	//	Element.hide('lightboxImage');
	
		//imageArrayNew = paginationArray[nextPage];
	
		if(nextPage ==0)
		{
			for(i=0;i<imageArrayNew.length;i++)
			{
				//alert(" 854  Hide Elements image  ==="+i);
				Element.hide('lightboxImage'+i);
			}
		} else if(previousPageFlag)
		{
				var nextPageHide = nextPage;
				var imageArrayNews = new Array;
				imageArrayNews = paginationArray[nextPageHide];
			//	for(i=0;i<imageArrayNew.length;i++) {
				for(j= (nextPageHide* 20);j<(imageArrayNews.length+(nextPageHide * 20));j++)
				{
					//alert(" 865  Hide Elements image  ==="+j);
					Element.hide('lightboxImage'+j);
				}
			previousPageFlag = false;
			nextPage--;

		} else {

			var nextPageHide = nextPage - 1;
			var	imageArrayNew2 = new Array;
				imageArrayNew2 = paginationArray[nextPageHide];
			//	for(k=0;k<imageArrayNew.length;k++) {
				for(k= (nextPageHide* 20);k<(imageArrayNew2.length+(nextPageHide * 20));k++){
					//alert(" 878  Hide Elements image  ==="+k);
					Element.hide('lightboxImage'+k);
			}
		}
		
		Element.hide('hoverNav');
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('imageDataContainer');
		Element.hide('numberDisplay');
		//Element.hide('previousImg');
	
		
		imgPreloader = new Image();

		// once image is preloaded, resize image container
	 	if(!isIE) {
		//	alert("   !isIE  ========= "+(!isIE)+"    isIE  ========= "+isIE);
			imgPreloader.onload=function()
			{
		/*		Element.setSrc('lightboxImage', imageArrayNew[0]);
				Element.setSrc('lightboxImage1', imageArrayNew[1]);
		*/
				var imageArrayNew3= new Array;
				imageArrayNew3 = paginationArray[nextPage];
				//for(m=0;i<imageArrayNew3.length;i++){
				for(m= (nextPage* 20);m<(imageArrayNew3.length+(nextPage * 20));m++){
				Element.setSrc('lightboxImage'+m, allImageArray[m]);
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				windowWidth = self.innerWidth;
				windowHeight = self.innerHeight;
				} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
				} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			/*
				if(isIE)
				{
					myLightbox.resizeImageContainer(windowWidth-350, windowHeight-100); //pala
					}else{
					myLightbox.resizeImageContainer(windowWidth-400, windowHeight-100); //pala
				}
			*/

				myLightbox.resizeImageContainer(windowWidth-400, windowHeight-100); //pala
				//	myLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height); 
			}	//   onload end
		} else {

		//	alert("   isIE  ========= "+(!isIE)+"    isIE  ========= "+isIE);
	//	imgPreloader.onload=function(){ // IE is not working for onload function. If you use this method, your image gallary container will collapsed.
	

			/*	Element.setSrc('lightboxImage', imageArrayNew[0]);
				Element.setSrc('lightboxImage1', imageArrayNew[1]);
			*/
	
			var imageArrayNew3= new Array;
			imageArrayNew3 = paginationArray[nextPage];
			//for(m=0;i<imageArrayNew3.length;i++){
				for(m= (nextPage* 20);m<(imageArrayNew3.length+(nextPage * 20));m++)
				{
					Element.setSrc('lightboxImage'+m, allImageArray[m]);
				}

			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				windowWidth = self.innerWidth;
				windowHeight = self.innerHeight;
				} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
				} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
	
			myLightbox.resizeImageContainer(windowWidth-400, windowHeight-100); //pala
			//	myLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height); 
		} // onload end function
		//}  //  Browse  else  
		imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {
//	alert("   RESIZE IMAGE CONTAINER  ");
		// get current height and width
		this.wCur = Element.getWidth('outerImageContainer');
		this.hCur = Element.getHeight('outerImageContainer');

		// scalars based on change from old to new
		this.xScale = ((imgWidth  + (borderSize * 2)) / this.wCur) * 100;
		this.yScale = ((imgHeight  + (borderSize * 2)) / this.hCur) * 100;
	

		// calculate size difference between new and old image, and resize if necessary
		wDiff = (this.wCur - borderSize * 2) - imgWidth;
		hDiff = (this.hCur - borderSize * 2) - imgHeight;
	
		if(!( hDiff == 0)){ new Effect.Scale('outerImageContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('outerImageContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		Element.setHeight('prevLink', imgHeight);
		Element.setHeight('nextLink', imgHeight);
		Element.setWidth( 'imageDataContainer', imgWidth + (borderSize * 2));

		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
//	alert(" 788  showImage WITH LOADING ");

		Element.hide('loading');
/*		new Effect.Appear('lightboxImage', { duration: 0.5, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		new Effect.Appear('lightboxImage1', { duration: 0.5, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });*/
		imageArrayNew = new Array;
		imageArrayNew = paginationArray[nextPage];
		//for(i=0;i<imageArrayNew.length;i++){
		
		for(i= (nextPage* 20);i<(imageArrayNew.length+(nextPage * 20));i++){
		//	new Effect.Appear('lightboxImage'+i, { duration: 0.5, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		//alert("  Appear Images "+i+"  No  :  "+allImageArray[i]);
			new Effect.Appear('lightboxImage'+i, { duration: 0.0, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		}
		this.preloadNeighborImages();
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {
	// alert("  805  UPDATE DETAILS  ");
		Element.show('caption');
		Element.setInnerHTML( 'caption', imageArray[activeImage][1]);
		
		// if image is part of set display 'Image x of x' 
		if(imageArray.length > 1){
			Element.show('numberDisplay');
			Element.setInnerHTML( 'numberDisplay', "Image " + eval(activeImage + 1) + " of " + imageArray.length);
		}

	//	new Effect.Parallel(
	//		[ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration + 0.25, from: 0.0, to: 1.0 }), 


//--------- Pala hide the below part  ---------
	/*
		new Effect.Parallel([ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration + 0.0, from: 0.0, to: 0.0 }), 
			  new Effect.Appear('imageDataContainer', { sync: true, duration: 0.0 }) ], 
	  			{ duration: 0.0, afterFinish: function() { myLightbox.updateNav();} } 
	
			//  new Effect.Appear('imageDataContainer', { sync: true, duration: 1.0 }) ], 
	  		//			{ duration: 0.65, afterFinish: function() { myLightbox.updateNav();} } 
		);
	*/
	//myLightbox.updateNav();  //------------ pala  --------------
	},


	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {
//alert(" 605  Update Nav  ");
		Element.show('hoverNav');				

		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				myLightbox.changeImage(activeImage - 1); return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				myLightbox.changeImage(activeImage + 1); return false;
			}
		}
		
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c')){	// close lightbox
			myLightbox.end();
		} else if(key == 'p'){	// display previous image
			if(activeImage != 0){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage - 1);
			}
		} else if(key == 'n'){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage + 1);
			}
		}


	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

// -----------palani ----------  Next page image loading pagination process ------------------------------------------------

//initializePagination: function(allImgArrays, nextPageArray){
	nextPageImageInitializePagination: function(allImgArrays, nextPageArray)
	{
		imageArrayNew = new Array;
		nextPageImageArray = new Array;
		//imageArrayNew = paginationArray[nextPage];	//nextPageImageArray = paginationArray[nextPage];
		//imageArrayNew = allImgArrays;
		nextPageImageArray = nextPageArray;
		var imageObjTemp = document.createElement('a');
		imageObjTemp.setAttribute('href',nextPageImageArray[0]);
		myLightbox.start(imageObjTemp);  
		return false;
	},
//----------- Previous Image loading process   Begin --------------------

	previousPageInitializePagination: function()
	{
		previousPageImageArray = new Array;
		previousPageImageArray =  paginationArray[0];
		myLightbox.start(previousPageImageArray[0]);
	},



	//
	//	end()
	//
	end: function() {
		this.disableKeyboardNav();
		Element.hide('lightbox');
		new Effect.Fade('overlay', { duration: 0.2});
		showSelectBoxes();
		removeElement("overlay");
		removeElement("lightbox");
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

// ---------------------------------------------------



function initLightbox() {
	myLightbox = new Lightbox(); 
	}
//Event.observe(window, 'load', initLightbox, false);

var editorName=null;
function setEditorName(name){
	editorName=name;
}


